Instructables

Raspberry Pi as a 3g (Huawei E303) wireless (Edimax EW-7811Un) router

Picture of Raspberry Pi as a 3g (Huawei E303) wireless (Edimax EW-7811Un) router
Aim:

Set up the Raspberry Pi as a wireless router using the Raspbian OS. The internet connection will be provided by a Huawei E303 USB 3g dongle on the safaricom network in Kenya, though the setup should be similar on most Huawei dongles and 3g networks. The wireless access point will be provided by an Edimax Nano USB Wifi adapter.

Power Source -------->RPI ----> Powered USB HUB -----> 3g Dongle
                                           |
                                           |         
                                     Edimax
                                        Wifi


The USB ports of the Pi seem to struggle to provide the power for a 3g dongle, so a powered USB hub is necessary.

After a lot of reading and messing around, I've come up with a step by step guide for setting up my Pi as a wireless internet router. I use this every time I make a fresh setup of Raspbian, which is a fairly regular event. Stumbling round my latest install like a drunken elephant, it never takes me long to screw something up so badly that it's easier just to start from scratch.

As such, this guide assumes that the Raspbian operating system is 'fresh'. It has been tested with the 2012-12-16 release - as soon as I have the time free, I'll update the guide for the newest release. So, the steps I use to set up the 'Pifi' Router are as follows:

This guide and more like it can be found on my blog.
 
Remove these adsRemove these ads by Signing Up
kunfannen6 months ago

Thanks for the helpful instructable. Now I can connect my devices wirelessly to the internet here in Guinea. I had a bit of trouble getting things to work. Finally, I realized that I had a static address on the RPi that wasn't in the range you gave here. I was connecting headless via WiFi and needed the set IP address to do that. What I did was change the range of IP addresses in step 5. I edited /etc/network/interfaces so it now has:

#wireless adapter
allow-hotplug wlan0
iface wlan0 inet static
address 169.254.0.1
network 169.254.0.0
netmask 255.255.255.0

And then I changed the end of /etc/dnsmasq.conf to say:

interface=wlan0
dhcp-range=169.254.0.3,169.254.0.13 ,255.255.255.0,12h

So, now everything is working. A huge thank you for this instructable. The only problem I'm still having is that it seems that usb_modeswitch isn't working as it doesn't always boot up in the right mode and so doesn't always connect on boot. I'm still working on that though.

Still, I am quite happy with the results and want to say thank you.

And... did you search what type of addresses were these 169.254.x you were getting? It's possibly working for 1 client, but you still have the same problem, except that the failure ends up assigning an address (to be seen as a failure to get the DHCP address) as a static address right in the DHCP range... Don't do that a second time unless you're ready to deal with random IP address conflicts :-S

SifisoS1 month ago

1. With this setup, can one ssh to the raspberry pi?

2. I'm trying to use a 3g modem to host a basic website, could you please help. ive looked so much and most people are using routers and then can access their websites on the internet. please help i also wanna Access my raspberry pi (website) via internet just using the 3g on the raspberry pi.

Do you have any idea why this wouldn't work on a raspberry pi b+? i've got it all working on a model a, flashed the image to a micro sd and it works for the a but not the b+, any thoughts?

Hey- I'm having the same problem. Are you losing power to your USB ports when you attach the Huawei?

raceface2nd9 months ago
thanks for the nice tutorial!

I have a Problem with to get Clients connected to the eth0 to the Internet.

My iptables-restore file is like following

# Generated by iptables-save v1.4.14 on Sun Feb 2 01:41:20 2014
*filter
:INPUT ACCEPT [105:18135]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [99:22038]
-A FORWARD -i ppp0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o ppp0 -j ACCEPT
COMMIT
# Completed on Sun Feb 2 01:41:20 2014
# Generated by iptables-save v1.4.14 on Sun Feb 2 01:41:20 2014
*nat
:PREROUTING ACCEPT [39:3046]
:INPUT ACCEPT [23:1674]
:OUTPUT ACCEPT [28:2989]
:POSTROUTING ACCEPT [7:1539]
-A POSTROUTING -o ppp0 -j MASQUERADE
COMMIT
# Completed on Sun Feb 2 01:41:20 2014

What ist wrong? DNS seems to work, clients are getting the IP from DNS but no ping, nothing is possible.

Any tipps?

Best regards!

Andy
Happz0r10 months ago
Thanks for the tutorial, but it didnt seem to work for me. I got the AP up and running but my clients were not able to use the Internet connection.

It almost drove me crazy, since I'm a linux noob and I wasn't able to solve this...

Until I realized that there's an error in the Nat script.

You wrote:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEP

Problem is, that at least for me, using a 3G connection, you don't have to forward "eth0"(there is no cable plugged in anyway), but rather forward "ppp0".

So all you got to do is to change
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEP

In

sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
sudo iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEP


At least that's what helped me :)
svazquez61 year ago
Hi i have another version to install 3G Modem with Raspberry Pi, it is in Spanish but could help to some who wants to use Google Translate, also if you don't want to use Google Translate it could be easy 'cause it has images to guide... http://www.webonactivo.blogspot.mx/2013/09/raspberry-pi-con-banda-ancha.html
I made this script so you can execute (need internet connection first time to download stuff) and then will configure umtskeeper and 3gsakis, it will make the connection, is working with my carrier Tuenti and huawei k3772 dongle, so you have to modify the line 51 to connect with your setting hope it will be helpfull =)
https://mega.co.nz/#!J9UFiBIZ!VsW4GWTcnqABHAAqG7UayUxz_aVHYlwSbvmowQXD2so
dexxster1 year ago
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Can you please tell why are you using the eth0 interface and not the wlan0 ? Thanks.


goofygutt1 year ago
Nice tutorial! Had some real problems getting it to work on a Huawei E220 modem, but after updating the modem firmware, no problems =)
Now I want to connect to the pc with the 3g Modem using remote desktop, but this was not so easy as it works a little different from usual DSL internet connections, I guess my operator has some restrictions. Have you tried this?
hadrianus1 year ago
There is also a typo regarding the script
sudo tar -xzvf sakis36.tar.gz
instead of
sudo tar -xzvf sakis3g.tar.gz
kyuzumaki1 year ago
Small typo the command for unzip of utms keeper should be sudo tar -xzvf umtskeeper.tar.gz