How to Use a RaspberryPi with a 3G Modem as a WIFI Router and Internet Access Point

In this tutorial I am going to explain how I set up my RaspberryPi as a WIFI router, using a Huawei E367 3G modem to connect to the internet, and a Tenda W311U+ wireless USB Adapter for setting up a wireless access point over which other devices can connect to the internet using the established 3G connection.

 

Connect to the Pi

To work on the Pi, I have connected it via a LAN cable to my desktop, from where I am going to do the work via SSH, as my Pi runs headless and without monitor.

First, we need to find the PI's IP address

On the desktop, with 

hostname -I

we can detect the desktop's network IP address, and consequently check the network's other addresses; just replace the last part of the address with a 0 and add /24, like for example:

nmap -sP 192.168.43.0/24

which shows me that my PI has the address 192.168.43.164. SO I connect from my desktop via

ssh pi@192.168.43.164

 

Create Internet Access using a Huawei E367 USB modem


Download and install required software: 
  • We will need usb-modeswitch to put the modem in the internet mode
  • We need sakis3g to establish a 3G connection with the network service provider
  • We need umtskeeper to keep the connection alive

sudo apt-get install ppp libpcap0.8 usb-modeswitch libjim0debian2 usb-modeswitch-data -y

as well as sakis3g + UMTSkeeper

mkdir umtskeeper && cd umtskeeper

Download umtskeeper

wget "http://mintakaconciencia.net/squares/umtskeeper/src/umtskeeper.tar.gz"

Check file integrity

md5sum umtskeeper.tar.gztar

and extract the archive

-xzvf umtskeeper.tar.gz

Make the software executable:

chmod +x sakis3g umtskeeper

 

Set Modem from Memory Mode to Internet Mode
 

Then edit the usb_modeswitch configuration to switch the Huawei E367 modem from memory to internet modem, in:

sudo nano /etc/usb_modeswitch.conf

and add:

# Huawei E367
DefaultVendor=0x12d1
DefaultProduct=0x1446
 
TargetVendor=0x12d1
TargetProductList="1001,1406,140b,140c,1412,141b,14ac,1506"
 
CheckSuccess=20
 
MessageEndpoint=0x01
MessageContent="55534243123456780000000000000011062000000100000000000000000000"

Check

sudo lsusb


and now the modem should appear as 

Bus 002 Device 003: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard

 

Create Internet connection and keep it alive

To set up sakis3g, first run manually:

sudo ./sakis3g --interactive

to check if settings work. When the settings work, test to use the modem in umtskeeper mode. Unplug and plug in again the modem, then run

sudo ./umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1506' SIM_PIN='0' APN='internet' CUSTOM_APN='0' APN_USER='0' APN_PASS='0'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --nat 'no'

[Note, this may take a few minutes]

Next, let's set umtskeeper to start automatically during the boot and define it to generate a log file. Edit

sudo nano /etc/rc.local

and add the line [yes, in one line]:

/home/pi/umtskeeper/umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1506' SIM_PIN='0' APN='internet' CUSTOM_APN='0' APN_USER='0' APN_PASS='0'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 1 --nat 'no' --httpserver &>> /home/pi/umtskeeper/error.log &

before 

exit 0

Create desktop button for reconnecting umtskeeper

For starting umtskeeper right away, or for restarting it if necessary, create a script in

sudo nano /home/pi/umtskeeper/connect.sh
 

and add the line

sudo /home/pi/umtskeeper/umtskeeper --sakisoperators "USBINTERFACE='0' OTHER='USBMODEM' USBMODEM='12d1:1506' SIM_PIN='0' APN='internet' CUSTOM_APN='0' APN_USER='0' APN_PASS='0'" --sakisswitches "--sudo --console" --devicename 'Huawei' --log --silent --monthstart 1 --nat 'no' --httpserver &>> /home/pi/umtskeeper/error.log &

 

Save & exit, and create shortcut: 

sudo nano /usr/share/applications/umtskeeper.desktop

with the content:

[Desktop Entry]
Encoding=UTF-8
Name= Umtskeeper
Comment= Start umtskeeper
Exec=sh /home/pi/umtskeeper/connect.sh
Icon=/usr/share/pixmaps/wireless-connection-icon_32.xpm
MimeType=text/plain
Terminal=false
Type=Application
Categories=Internet 

and create link on desktop:

ln -s /usr/share/applications/umtskeeper.desktop /home/pi/Desktop/umtskeeper.desktop

 

Set up WIFI network with a Tenda W311U+ Wireless USB Adapter

Download and install dhcp server & hostapd

sudo apt-get install hostapd hostap-utils isc-dhcp-server rfkill iw dnsmasq -y
 

Note, the "Tenda W311U+ Wireless USB Adapter (Ralink RT3070, 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter) - Works out-of-the-box with Raspbian using rt2800usb kernel module, does not need powered USB hub to work.” (Source: http://elinux.org/RPi_USB_Wi-Fi_Adapters)

Check with

sudo iw list

if device is able to create an “AP”. It should be, so we can move on to configure the wireless interface in 

sudo nano /etc/network/interfaces

and add – including giving static IP which is necessary for creating an access point:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet static
address 3.14.15.9
netmask 255.255.255.0

Thus, our RasperryPi will have the address: 3.14.15.9 in our network.
 

Restart wireless network with: 

sudo ifdown wlan0 && sudo ifup wlan0

and: 

Configure the WIFI access point (AP)

Edit in

sudo nano /etc/hostapd/hostap.conf

and add:
 

interface=wlan0 
driver=nl80211 
ssid=3,14159 
hw_mode=g 
channel=10 
macaddr_acl=0 
auth_algs=1 
ignore_broadcast_ssid=0 
wpa=2 
wpa_passphrase=<YOUR-PASSWORD>
wpa_key_mgmt=WPA-PSK 
wpa_pairwise=CCMP
rsn_pairwise=CCMP 
ieee80211n=1 
ieee80211ac=1 
wmm_enabled=1 
ht_capab=[HT40-][SHORT-GI-20][SHORT-GI-40]

[For more details, see MagPi magazine issue 11 (from pistore) and http://sirlagz.net/2012/08/09/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-1/]

NOTE: hostap.conf is very sensitive: leave no unneccessary space or whatever!


Restart hostapd:

sudo service hostapd restart

and

Configure DHCP server

in:

sudo nano /etc/dnsmasq.conf

by adding

domain-needed
interface=wlan0
dhcp-range=3.14.15.10,3.14.15.30,255.255.255.0,12h


and restart

sudo service dnsmasq restart

 

Forward internet to the Access Point

Now the WIFI AP should be online and accessible, and we need to configure network routing/internet forwarding so that devices connected to the AP can access the internet, set up by the Huawei modem.

Edit

sudo nano /etc/init.d/pipoint

and add:

#!/bin/sh
# Configure Wifi Access Point.
#
### BEGIN INIT INFO
# Provides: WifiAP
# Required-Start: $remote_fs $syslog $time
# Required-Stop: $remote_fs $syslog $time
# Should-Start: $network $named slapd autofs ypbind nscd nslcd
# Should-Stop: $network $named slapd autofs ypbind nscd nslcd
# Default-Start: 2
# Default-Stop:
# Short-Description: Wifi Access Point configuration
# Description: Sets forwarding, starts hostap, enables NAT in iptables
### END INIT INFO

# turn on forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# enable NAT
iptables -t nat -A POSTROUTING -j MASQUERADE

#If you want to block a certain IP address in your network, uncomment and adjust
#iptables -A FORWARD -s 3.14.15.XX -j DROP

# start the access point
hostapd -B /etc/hostapd/hostapd.conf


To apply changes, restarts hostapd, and to make automatize

sudo chmod +x /etc/init.d/pipoint

sudo update-rc.d pipoint start 99 2

 

Now, you should have a WIFI running with the Pi being accessible via the address 3.14.15.9, and the Pi sharing its internet connection that is established through a 3G USB modem.

Add new comment

The content of this field is kept private and will not be shown publicly.