Sharing mobile net through router
Last weekend some horrible thing happened : Our internet service was deactivated for some silly reason. As some basic “internet feature” like mail, news are basic requirements for daily life, I had to solve this situation. Fortunately I have a pretty mobile internet connection so the idea has just came up to share the mobile net over the router so everybody can use the net without any changes made.
Setting up mobile connection through bluetooth:
Setting up the mobile connection on Debian is pretty easy. Under GNOME there is a pretty bluetooth applet called blueman which you can use to set your phone as a bluetooth modem. I have used bluetooth connection for the modem, because I can not charge and use the data cable at the same time. And then I did not have the data cable at home. Installing blueman:
apt-get install blueman
With this applet, I could easily set up modem service through bluetooth. Just search your device, right-click on it, and select Dial-up networking from topmost Connect to menu.
Now you can add your mobile broadband connection. Click on Network Monitor applet and select configure. Select Mobile broadband. Add your connection, which generally means setting the APN ( the same way as you set in your mobile phone). When done, you can use your new mobile broadband connection.
Sharing it:
So, after my mobile net connection was set up, the only thing was missing to share it. Unfortunately, I could not find any easy tool to set up ip forwarding rules correctly, so I searched for related articles. I have found a great description on Debian Administration. I have slightly changed eth1 to ppp0 according to my needs. Here is my version:
#!/bin/sh PATH=/usr/sbin:/sbin:/bin:/usr/bin # # delete all existing rules. # iptables -F iptables -t nat -F iptables -t mangle -F iptables -X # Always accept loopback traffic iptables -A INPUT -i lo -j ACCEPT # Allow established connections, and those not coming from the outside iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -m state --state NEW ! -i ppp0 -j ACCEPT iptables -A FORWARD -i ppp0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow outgoing connections from the LAN side. iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT # Masquerade. iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE # Don't forward from the outside to the inside. iptables -A FORWARD -i ppp0 -o ppp0 -j REJECT # Enable routing. echo 1 > /proc/sys/net/ipv4/ip_forward
Before executing the script, I had to configure eth0. Because it was set to dhcp I changed it to static address in /etc/network/interfaces :
iface eth1 inet static address 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
Then I just executed the script and it just worked.
Configuring the router:
The only thing was left is to configure the router. This was easy too. I have modified the WAN settings from pppoe (yes, an ADSL connection) to static ip. The ip can be anything in the subnet of eth0, the netmask is the same, and the gateway is ip of eth0. And first I have set DNS to Google’s dns (8.8.8.8).
So, every 4 machines could use the net without any configuring and without an active ADSL service
admin on April 20th 2010 in Uncategorized