Sharing an Internet Connection between two Ubuntu Computers

, , , May 19th, 2008

If you follow my blog regularly, you would have known that my father has brought a new computer running Ubuntu, and that I have completed my BE degree course and have brought my computer home from college.

At home, we have a broadband Internet connection that we share between the two computers. Here’s how I setup my father’s computer as a gateway for my computer.

Both computers had an inbuilt ethernet port and we bought an extra ethernet card for my father’s computer and use it as an internet gateway. Sharing internet on two windows computers is a very straight forward procedure. You just have to connect the broadband modem to one of the ethernet ports and use additional ethernet ports to connect other computers to the gateway.

In Linux however, this doesn’t work automatically. Port forwarding is disabled by default in Ubuntu. This has to be enabled if the computer should forward packets it recieves to other computers. Here’s how this is done.

On the computer you want to use a gateway

  1. You need to connect the internet cable to eth1 and the client computer to eth0. Since the computer has two network cards, you have to figure out which one is connected to the internet and which one to the other computer. Here’s an easy way to do this
    1. Pull out the cable connecting the two computers
    2. Goto Applications -> Accessories -> Terminal and enter the following command
    3. $ sudo ifconfig

    4. You will be shown 2 or more sections with eth0 and eth1 being the first two. In the two sections, one of them will have a line similar to this:
    5. inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0

    6. The section that has this line is the one connected to the internet. If this is in eth0, remove the internet cable and plug it in the other ethernet port and the cable from the client to eth0. If it is in eth1, you can connect the client cable back to its original port
  2. Next you have to give a static ip address to eth0. In terminal, type
  3. $ sudo gedit /etc/network/interfaces

  4. And add the following lines to the file and save it
  5. auto eth0
    iface eth0 inet static
    address 10.8.16.1
    netmask 255.255.255.0
    broadcast 10.8.16.0
    network 10.8.16.0

  6. This will assign the static ip address 10.8.16.1 to eth0, but these changes take effect only after a reboot. To use these settings temporarily for the current session, use the command
  7. $ sudo ifconfig eth0 10.8.16.1

  8. Once your network card serving the client has a static ip address, the next thing to do would be to enable port forwarding:
    1. Goto terminal and open the local startup script as root. To do this, type
    2. $ sudo gedit /etc/rc.local

    3. Add the following lines before the exit 0 line in the file.
    4. sysctl -w net.ipv4.ip_forward=1
      /sbin/iptables -P FORWARD ACCEPT
      /sbin/iptables --table nat -A POSTROUTING -o eth1 -j MASQUERADE

    5. Before closing the script, make sure it is enabled. See the first line of the script. If it isn’t present already, just add a '-e' to the first line so that it would look like '#!/bin/sh -e'
  9. That’s all you have to do on the server. Just do a restart for the settings to take effect. If that’s not possible, you have to execute all the commands you have added to the rc.local script one by one for all of them to take effect

On the client

  1. Go to System -> Administration -> Network There should be a wired connection. Select it and click ‘properties’. Choose ‘Static IP Address’ in the Configuration list box.
  2. Use 10.8.16.2 as the ip address and set the gateway address to 10.8.16.1
  3. Network manager should give you a subnet mask automatically. You won’t have to change that.

This should be enough. This is what I did. If this doesn’t seem to work, just let me know and I’ll help you out.

P.S. You can use a Windows computer to connect to Internet through the linux gateway too. Nothing needs to be changed on the server. Just make 10.8.16.2 the IP address of the client in LAN Settings which can be found in Network Connections. Also, set 10.8.16.1 as the default network gateway address.

del.icio.us Digg DZone IndianPad Newsgator reddit Simpy SlashDot StumbleUpon Technorati

Ubuntu - The OS for all Parents

, May 12th, 2008

My father bought his first computer a few weeks back. They had given a free Ubuntu 7.10 CD, but had not installed any operating system. My guess is that they hadn’t installed Linux on the computers is that they expected the users to install pirated Windows on purchase. When companies give computers with Windows preinstalled, why can’t they install Ubuntu, which is faster and easier to install?

Anyways, upon my recommendation, my father decided to install Linux. And right now, he’s browsing and listen to Carnatic music on Rhythmbox. And he’s safe online. Nothing can really hurt his computer, he won’t have crashes and so, won’t have to wait for the engineer to come and fix his computer. He thinks Firefox, OpenOffice.org, spell check and stuff are really easy to use, but needs to get used to the cut-copy-paste thingy.

So if your parents are buying a new computer or are having trouble with their Windows installation, I’d suggest that you install an easy to use Linux distro like Ubuntu on their computer. Please don’t try to teach them all things you do to keep viruses away from your windows computer, they’d find learning a new operating system much easier.

del.icio.us Digg DZone IndianPad Newsgator reddit Simpy SlashDot StumbleUpon Technorati