In case CDMA technology is still offered in your area, this post might be useful to you in setting up a simple Home WiFi using a CDMA modem, WiFi router and a Linux machine. This could be a good excercise to revive your old Linux box and that old WiFi router which had been laying useless :-).
What you need
- Linux machine - An old Debian / Ubuntu Linux pc will do too.
- WiFi router - An old 2.4GHz router from DLink would work.
- CDMA-1x USB modem - Typically available as CDMA USB-Dongle.
- Ethernet cable to connect the Router to the Linux machine.
Hardware setup
- Configure the WiFi router to act as an access point using the Router’s web interface.
- Connect the Ethernet cable to one of the 4 ports of the Router and the other end to the Linux machine’s Ethernet port.
- Connect the CDMA USB modem to one of the USB port of the Linux machine.
Software setup
Install the following packages using the package manager.
1apt-get install -y pppd wvdial iptables dnsmasqEnsure that the Linux device driver modules
usbserialandcdc_acmare loaded. You may use the commandinsmodin case they are not already loaded.
Setting up the WiFi
This process involves the following main steps.
- Configuring kernel modules for auto-loading at bootup
- Configuring and running “wvdial” for dialup (ppp) connection
- Setting up “iptables” for NAT forwarding
- Setting up “dnsmasq” for resolving DNS and as DHCP server
Configure Kernel modules
Open a terminal and the command
sudo bashin order to enter BASH as super-user.Edit the file
/etc/modulesand append the following lines if they do not already exist. Check and use the appropriate values forvendorandproductids for the USB modem, by referring to the file/proc/bus/usb/devices.1usbserial vendor=0x19d2 product=0xfffd 2cdc_acmSave the file and exit the terminal.
Reboot the machine for automatic driver loading to happen.
Configure Dial-Up connection
Open a terminal and the command
sudo bashin order to enter BASH as super-user.Take a backup of the file
/etc/wvdial.confand then replace it’s content with the following configuration.1[Dialer Defaults] 2Init1 = ATZ 3Init2 = AT+CRM=1 4Modem Type = Analog Modem 5SetVolume = 0 6Baud = 115200 7New PPPD = yes 8Modem = /dev/ttyUSB0 9Carrier Check = no 10Stupid Mode = 1 11ISDN = 0 12Phone = <dial-number> 13Password = <dial-password> 14Username = <dial-username>Use appropriate values for
dial-number,dial-passwordanddial-username. For Reliance CDMA modem, dial-number will be #777 and, dial-password and dial-username will be the phone number itself.Save and close the file.
Take a backup of
/etc/resolv.confthen, clear all the content of/etc/resolv.confand save it.Run
wvdialto initiate the PPP connection.
NAT forwarding with iptables
In this step, we will be configuring the NAT table to masquerade ppp0 network interface and configure forwarding rule for the ethernet interface.
Open a terminal and the command
sudo bashin order to enter BASH as super-user.Create or open the file
/usr/local/sbin/ppp_eth_routeand enter the following content. If the file altready exists, first take a backup and then replace its content with the following.1#!/bin/bash 2 3## Flush the nat table 4iptables --flush 5iptables --table nat --flush 6 7iptables --delete-chain 8iptables --table nat --delete-chain 9 10## Set up IP forwarding and masquerading 11iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE 12iptables --append FORWARD --in-interface eth0 -j ACCEPT 13 14echo 1 > /proc/sys/net/ipv4/ip_forwardSave the file and change its permission to 0755 using the command;
1chown 755 /usr/local/sbin/ppp_eth_routeRun the
ppp_eth_routescript created above.
Setting up local DNS and DHCP server
We will be using the dnsmasq tool to setup a DHCP server and configure the DNS host resolution.
Open a terminal and the command
sudo bashin order to enter BASH as super-user.Edit the file
/etc/network/interfacesand replace it’s content with the following. It is recommended to take a backup of the file before changing it’s content.1auth eth0 2iface eth0 inet static 3address 10.10.1.1 4netmask 255.255.255.0Save and close the file.
Edit the file
/etc/dnsmasq.confas follows. Then, save and close the file.- Uncomment the line containing
interface=eth0 - Uncomment the line that starts with
dhcp-rangeto enable integrated DHCP server. The line must be edited asdhcp-range=10.10.1.10,10.10.1.200,12h
Here, the
dnsmasqtool is allowed to provide IPs in the range 10.10.1.10 to 10.10.1.200 with a lease time of 12 hours.- Uncomment the line containing
Restart the system services -
network-manageranddnsmasq.
- Restart the system
networking / network-managerservice. - Run
wvdial &. Wait till it fetches IP address and DNS entries. Otherwise, there is no use in proceeding further since, there is likely a PPP connection issue. - Run
/usr/local/sbin/ppp_eth_route. - Restart the system
dnsmasqservice.
Of course, you can put the above commands in a shell script and run them as super-user. That’s it!
Comments