• user warning: Table './newdigit/captcha_sessions' is marked as crashed and should be repaired query: SELECT solution FROM captcha_sessions WHERE csid = 1344 in /home/digit/public_html/sites/all/modules/captcha/image_captcha/image_captcha.user.inc on line 21.
  • user warning: Table './newdigit/captcha_sessions' is marked as crashed and should be repaired query: SELECT solution FROM captcha_sessions WHERE csid = 1353 in /home/digit/public_html/sites/all/modules/captcha/image_captcha/image_captcha.user.inc on line 21.
Buddhika Siddhisena is the Co-Founder&CTO of THINKCube Systems which specializes in Collaboration Technologies for the Enterprise by integrating widely used and proven FOSS Technologies. Buddhika Siddhisena obtained his B.Sc (Physical Science) from University of Colombo and is also a Member of the British Computer Society (MBCS). Buddhika has also been involved through theinception of several leading FOSS projects, such as Sahana Disaster Management System and Tarprobane GNU/Linux Distribution. He is an active member of the Lanka Linux User Group, Sri Lankan FOSS Community and does a weekly podcast about FOSS in Sinhala over at sinhalenfoss.org.
 

Internet Connection Sharing under Linux

03/30/2010 2:49 am By Buddhika Siddhisena | Articles: 8

Imagine you and a couple of buddies went on a hiking trip and after a tiring day, your all back at the hotel trying to chill and catch up with whats been happening at facebook. The problem is, the hotel doesn't have broadband and your the only one who has bought along a broadband modem. Now for the sake of this article, I'll assume your buddies have brought along their notebooks, although in reality you'll probably be “Internet Connection Sharing” by passing your notebook around! Also to simplify this article, and knowing the geek you are, I'll assume you've brought along a small hub along with a couple of network cables to hook your pals up. In reality, you might instead setup an Ad-Hoc wireless network, but that'll have to wait for another article.

Now if you've read this far, and have some experience with Internet connection sharing under Windows or Mac OSX, you're probably thinking BIG DEAL! You just right click here and select this option and thats it, right? Well sure, but where is the fun in that? Besides did you even learn how it “magically” worked?



If your the type of person who doesn't care how it works as long as it works, well your in luck as the article is about to end very soon for you. If your running a modern GNU/Linux distribution such as Ubuntu 9.10 or Fedora 12 then you can easily enable Internet connection sharing using the Network Manager applet found in the system panel area.



Just right click on the network icon and select “Edit Connections...”. From the next dialog which pops up, goto the “Wired” tab and click on “Auto eth0” and then edit. From the next pop-up dialog box select the “IPV4 Settings” tab. From the connection “method:” drop down, select “Shared to other computers” and click “Apply”. Now your broadband modem or wireless connection should be shared with other computer plugged into your ethernet port (via hub). Thats it and thank you for reading.

Now for those of you, who are more inquisitive as to how the magic trick is performed, open up a terminal and become root (via su or sudo -s).

The first thing you'd want to do is to assign a static IP address for your ethernet port (eth0). You can do this either via network manager or straight in the command line for this session.

#ifconfig eth0 192.168.10.1

The only thing to be concerned when assigning the IP address is to make sure it is not in the same range as that of your Internet connection interface. Next you should enable routing between your network interfaces. Again, you have the option of permanently changing this setting by editing /etc/sysctl.conf and enabling net.ipv4.ip_forward=1 by uncommenting the line or temporally for this session using the command line. Note that if you edit sysctl.conf, you'll need to reboot for it to take effect.

#echo 1 > /proc/sys/net/ipv4/ip_forward

The final configuration step is to enable Network Address Translation or NAT, which is actually where the real magic of Internet connection sharing takes place. Lets go ahead and type that in before we explain whats going on.

#iptables -t nat -A POSTROUTING -j MASQUERADE

Nothing much to say except the above line configure the Linux firewall system (iptables), to modify all packets that come in from the network and are going out to the Internet after routing (post-routing), to appear as if it was originated from your machine (masquerade trick). Think of it this way – your pal is in love with your cousin and wants to send a love letter, except you both know your cousin will not get the letter unless it appears to come from a trusted source (parents are protective!). So you take your pal's letter and masquerade it by putting it in an envelope with your name on the front before mailing it off.

At this point Internet Connection Sharing works, but you would still have to configure each and every client computer of your buddy by assigning it a static IP in the same range as that of eth0 (192.168.10.xxx) and adding your IP (192.168.10.1) as the default gateway along with proper DNS server settings (OpenDNS perhaps). If you prefer a more fully automated setup for your buddies, then read on.

Network configuration settings for clients can be given by setting up a DHCP server. Additionally you could improve performance by running your own DNS caching server so that frequently visited domain name's IP address is cached locally. Fortunately rather than setting up a full DHCP (dhcpd) and DNS server (bind9), there is a swiss-army-knife like dhcp/dns/tftp combo server called dnsmasq which we will use. If dnsmasq is not already installed, go ahead and install it via apt, yum or any fancy front-end installer your distro may provide.

To have it up and running in a jiffy, you can just run it in command line without having to modify any configuration file.

#dnsmasq -k -o -i eth0 --dhcp-range 192.168.10.50,192.168.10.100

The above command runs dnsmasq in the foreground (-k) so that you can easily stop it using Ctrl+C and listens only to eth0 interface. It issues the IP automatically to client in the range 192.168.10.50 – 192.168.10.100. Now all you pals need to do is to set their network on DHCP mode and refresh their network interfaces. Everything else should “just work”!

 

Share/Save
Your rating: None Average: 5 (2 votes)

Post new comment