FRONT PAGE | CV | ARTICLES | PROJECTS

Using EEE PC as 3G router

Some time ago I found myself struggling without any decent permanent Internet connection. I then bought cheap 3G / HSDPA USB-dongle without any speed gap and was very surprised when it actually worked pretty well (average transfer rate is about 2 Mbps / 0.35 Mbps). However I could not share network connection for multiple computers anymore as my old router did not have 3G support (nor any USB ports). Routers having 3G support was expensive so I tried to figure out something and when I saw my old EEE PC 701 I relaized it may be the answer. It does have three USB 2.0 ports, 10/100 Mbit Ethernet and 802.11b/802.11g WLAN, relatively powerfull CPU and lots of memory. As bonus it does have builtin UPS ;) So one could actually make very good router out of it WLAN card could be configured to Access Point mode. Can it be done? YES! Well, at least if your EEE PC does have Atheros AR242x WLAN card (perhaps other Atheros and Realtek will work also).

Installing OS

Altough everything probably could be done using Xandros Linux which is installed out-of-the-box, I decided to ditch it and install something else. My choice was Debian Lenny (EEE PC Blend) - Ubuntu and others probably are great choices also. I installed Debian Lenny as instructed without any problems. Did zap original partitioning and used only one big partition, no swap and no EFI partition. You may prefer otherwise, it really should not matter. I did not select any unneccessary tasks when installing - I like to manually install only packaes I need, but once again it should not matter, just do as you like.

I spent some time trying to optimize SSD life - mounted root partition with "noatime,data=writeback,commit=120" parameters, tweaked rsyslogd settings etc. You will find everything from Debian EeePC wiki, benefits of tweaking may be nil but at least it's great hobby ;) Installed some neccessary software, configured few things etc. You probably can get avay with pure default installation so do as you wish.

I also optimized power consuption by enabling CPUfreq. Added following lines to /etc/modules :

p4-clockmod
cpufreq_ondemand
And following line sto the /etc/rc.local :
# Setting scaling governor
echo Setting scaling governor to ondemand...
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

CPU now runs 113 MHz when idle (read: all time). Power consumption of whole systems seems to be around 13W while my old router ate about 7W - seems pretty modest.

Configuring 3G

I was surprised how easy it was to configure my 3G USB-dongle: I just plugged it in and hey, It Just Worked! My Huawei E230 appeared as generic USB-serial-converted and was fully accessible from using device /dev/ttyS0 . I also tried to plug in my Nokia E51 GSM in PC Suite mode using USB cable and hey, It Just Worked too, was fully accessible using device /dev/ttyACM0 .

I installed wvdial and used following configuration (/etc/wvdial.conf):

[Dialer Defaults]
Modem = /dev/ttyUSB0
Baud = 460800
Init1 = ATZ
Init2 = AT+CGDCONT=1,"IP","internet"
Phone = *99#
Username = guest
Password = guest
Stupid Mode = 1

Of course you should substitute my values with your own operators values. Init2 does contain APN, mine is internet, Phone is probably good for you too and if you have to provide username and password, do it so and disable stupid mode. Typing "vwdial" connected me to the Internet without any troubles!

Time to share

So now I just had to figure out how to share my dial-up connection (interface ppp0) through Ethernet (interface eth0) and WLAN (interface ath0). Luckily there are tons of documents describing how to implemnent NAT using iptables and madwifi documents were more than enough for changing WLAN mode from station to access point.

First I installed dnsmasq which does offer lightweight DHCP server and DNS proxy in one daemon. I configured dnsmasq not to start in boot and used following configuration (/etc/dnsmasq.conf):

domain-needed
bogus-priv
dhcp-range=172.16.10.100,172.16.10.200,12h
dhcp-range=172.16.11.100,172.16.11.200,12h

Then I rewrote /etc/netwrok/interfaces after which network interfaces were up after boot but without any IP-addesses etc. (because I wanted to write scripts for changing between 3G router and normal laptop depending on situation - if you use your EEE PC only as router, you could write everything to the file):

# The loopback network interface
auto lo
iface lo inet loopback

# The wired network interface
auto eth0
iface eth0 inet manual

# The wireless network interfaces
auto ath0
iface ath0 inet manual

Almost done, only needed script which does configure Ethernet, WLAN, starts dnsmasq and creates neccessary iptables rules:

#
echo Setting up the wireless interface...
ifdown ath0
wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode ap
iwconfig ath0 mode master
iwconfig ath0 channel 11
iwconfig ath0 essid 3G-GW
ifconfig ath0 172.16.10.1 netmask 255.255.255.0 up

#
echo Setting up the wired interface...
ifdown eth0
ifconfig eth0 172.16.11.1 netmask 255.255.255.0 up

#
echo Enabling IP forwarding...
echo 1 > /proc/sys/net/ipv4/ip_forward

#
echo Flushing packet filtering rules...
iptables --table filter --flush INPUT
iptables --table filter --flush OUTPUT
iptables --table filter --flush FORWARD
iptables --table nat --flush PREROUTING
iptables --table nat --flush OUTPUT
iptables --table nat --flush POSTROUTING

#
echo Setting up default policies...
iptables --table filter --policy INPUT ACCEPT
iptables --table filter --policy OUTPUT ACCEPT
iptables --table filter --policy FORWARD DROP
iptables --table nat --policy PREROUTING ACCEPT
iptables --table nat --policy OUTPUT ACCEPT
iptables --table nat --policy POSTROUTING ACCEPT

#
echo Setting up NAT...
iptables --table nat --append POSTROUTING --out-interface ppp0 --jump MASQUERADE
iptables --table filter --append FORWARD --in-interface ath0 --out-interface ppp0 --jump ACCEPT
iptables --table filter --append FORWARD --in-interface eth0 --out-interface ppp0 --jump ACCEPT
iptables --table filter --append FORWARD --in-interface ppp0 --out-interface ath0 --match state --state RELATED,ESTABLISHED --jump ACCEPT
iptables --table filter --append FORWARD --in-interface ppp0 --out-interface eth0 --match state --state RELATED,ESTABLISHED --jump ACCEPT
iptables --table filter --append FORWARD --in-interface ath0 --out-interface eth0 --jump ACCEPT
iptables --table filter --append FORWARD --in-interface eth0 --out-interface ath0 --jump ACCEPT

#
echo Starting DHCP-server and DNS-proxy...
/etc/init.d/dnsmasq restart

Voilą! Works like a charm, WLAN clients can connect to the EEE PC and access Internet through it, computers can be connected to the Ethernet port of the EEE PC and it works too (depending on situation you may wish to use small Ethernet switch). I never tought this could be this easy. Depending on your needs you can of course alter the script, this is very basic one.

Wireless encryption

Adding encryption (WPA) to WLAN was pretty easy too. I just installed hostapd and used following configuration (/etc/hostapd/hostapd.conf, copied only relevant lines here):
interface=ath0
driver=madwifi
ssid=3G-GW
hw_mode=g
channel=11
wpa=1
wpa_passphrase=XXX
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP

Added following lines to my initialization-script:

#
echo Setting up wireless encryption...
/etc/init.d/hostapd restart

Automation

I was too lazy to try to automate everything, I currently have to login to the EEE PC after boot and run wvdial and my script. Probably adding these to /etc/rc.local would do the trik, though perhaps some kind of deamon moitoring that 3G connection stays up would be good addition.

Using other wireless drivers than madwifi

My EEE PC did have Atheros AR242x WLAN card which is supported out-of-the box using madwifi driver. Never kernels does have another dirver, ath5k, which should be better (or at least free - madwifi does contain some binary-only code). Ath5k should also support AP mode. However, I have not yet tried it. Also some EEE PCs does have WLAN card using Realtek's chip and other drivers is needed. Have no experience about them too.

If you have any experience of these drivers, please share them with me!

Problems

Sometimes changing ath0 to AP mode does not work - wireless clients will be disconnected after few seconds every time after they connect. Running initialization script few times seems to fix this. Don't know what the cause.

Final thoughts

EEE PC is expensive if you plane to use it noly as router - you can get dedicated 3G router for 100 euros while EEE PC does cost twice as much. However if you have old EEE PC which you do not use anymore you can just as well to convert it to 3G router (could also be used as router for ADSL/Cable/etc. but since EEE PC does have only one Ethernet you would need Ethernet switch also and throughput would reduce to only 50 Mbps). But one again this cheap piece of hardware saved my day (previously I used EEE PC as GPS navigator in my boat).

© JARI ESKELINEN