Thursday, November 1, 2012

Raspberry Router



I wanted to set up my Raspberry Pi as a 3G router for my small home network,  and as a file server too. It worked out nicely, so here are some notes and links that helped me.  My internet connection is provided by a USB GSM modem (Huawei E173), so the first task is to get this device running on the Pi. This was surprisingly easy, thanks to the sakis3g script.

I learned that once you start messing with the network, downloading new stuff gets tricky - so it's best to get everything at once.
sudo apt-get install ppp isc-dhcp-server usb-modeswitch 
and download sakis3g
wget "http://www.sakis3g.org/versions/latest/armv4t/sakis3g.gz"

EDIT: The Sakis3G web page is down at the moment, but a local copy of the script is here: sakis3g.gz (version 0.2.0.e).

The Pi can probably not supply enough current for the 3G modem through the USB ports (thanks for the tip), so I connected the modem through a powered hub. Without the hub, the modem did not work.



The sakis script was easy to use, it asked me to select my modem and then the network name (APN). When the connection works, one can write the selections in a configuration file to avoid having to enter them again. In sakis: "More options..." -> "Generate success report" shows a lot of info. Last in the list, there are the options needed to connect. Copy these (except  --console and --interactive) to the file /etc/sakis3g.conf with one option per line. Sakis does not like any extra whitespace on these lines. Now it should be possible to connect with  a simple sudo sakis3g connect.

I found a nice guide to setting up the pi as a router. This worked well for me, I just had to change which network interface is connected to the local network (eth0 for me) and which is connected to the outside (ppp0).






A small complication has turned up with the GSM modem. The modem is a multimode USB device, and must be switched into the correct mode before actually working as a modem. Sakis handles this automatically (using the usbmodeswitch program I installed above). The trouble is, that when the modem is switched, it changes its USB device ID. So the device option to pass to sakis is different the first time and any later time sakis is run without unplugging or powering down the modem in between.
The broadband company seems to drop the connection after 24 h. I think I will put a cron script for reconnecting at 5 in the morning or so. I came up with the following command for finding the current USB ID of  the modem and passing it to sakis.
sudo sakis3g connect USBMODEM=\
`lsusb | grep Huawei | sed 's/.*ID \([a-f0-9:]*\) Huawei.*/\1/'`
sed is a strange creature! grep finds the relevant line, and the sed command extracts the ID number between 'ID ' and ' Huawei'. This is of course assuming that exactly one huawei device is present.

I post some of the configuration files here. In this later post, I added a WLAN stick and got the Pi set up as a WLAN access point, these files are for a WLAN device as well. If you don't have one, just ignore those sections.
my /etc/networks/interfaces:

auto lo
iface lo inet loopback

auto eth0 #static address on eth0
iface eth0 inet static
address 192.168.50.1
netmask 255.255.255.0
network 192.168.50.0
broadcast 192.168.50.255
gateway 192.168.50.1

auto wlan0 #static address on wlan0
iface wlan0 inet static
address 10.10.0.1
netmask 255.255.255.0

And then /etc/dhcp/dhcpd.conf

ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;

#for the eth0 subnet
subnet 192.168.50.0 netmask 255.255.255.0 {
range 192.168.50.10 192.168.50.250;
option broadcast-address 192.168.50.255;
option routers 192.168.50.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4; #Google DNS
interface eth0;
}

#for the wireless network on wlan0
subnet 10.10.0.0 netmask 255.255.255.0 {
        range 10.10.0.25 10.10.0.50;
        option domain-name-servers 8.8.8.8, 8.8.4.4;
        option routers 10.10.0.1;
        interface wlan0;
}

Newer Older Home
Related Posts Plugin for WordPress, Blogger...