How to share Internet with other computers in Linux
This is a common issue among all the computer users. I read a lot of how tos and tutorials available on Internet and finally came up with the following tutorial. This was performed on a system running Ubuntu 9.04 but similar steps (with some modification) can be taken to do the same on different distros.
In my case, I wanted to share connection between my Laptop and Desktop. The Laptop accessed Internet through wireless on eth1 interface and I shared it with the Desktop by creating a small wired network.
Perform the following steps on the computer which has access to Internet.
1. Open a terminal (Applications -> Accessories -> Terminal) and type the following commands to install a dhcp3-server and firestarter.
[shredder12]$ sudo apt-get install dhcp3-server firestarter
dhcp3-server is the package to create a dhcp server on the machine
Firestarter is a program with graphical frontend to manage your firewall.
[shredder12]$ sudo gedit /etc/default/dhcp3-server
2. Change the line
I used eth0 because I wanted to provide connection to every machine connected to the main computer through this interface.
3. Now, we need to create a connection on eth0 interface. Go to System -> Preferences -> Network Connections (in other distros this can be done using network manager or wicd). Then click on the "add" button. Assign a name of your choice to this connection.
4. Check the option of "connect automatically" then click the IPv4 settings tab and select the manual method. Use these network settings.
and check the option "available to all users" ( in case you have more than one user).
So, our dhcp server is configure and now we need to configure our firewall using Firestarter.
5. Go to Applications->Internet->Firestarter
You will be prompted for password (enter it). Click on the preferences and select the network settings.
Look at the image and do a similar configuration in your firestarter.
Choose the interface which provides you internet access (for me its eth1) and the one through which you want to share Internet (for me its eth0) and fill them accordingly.
Use a similar configuration as shown in the image, in your firestarter.
Now, to check if your dhcp server is working properly enable the firewall. If the status of Firestarter changes to active this means things are working properly.
Points to be considered
1. So, Now whenever you want to start your jst do
[shredder12]$ sudo /etc/init.d/dhcp3-server restart
even though it will be restarted automatically at boot up.
2. All the other machines for whom our computer is acting as a gateway will be on a completely different subnet from ours. If you don't want this then you should be look for bridging.
3. In order to activate the connection we need to connect to the eth0 network ( in our case it is "shared internet connection"), one can do this by left clicking on the network manager icon on the right top corner of the display and choosing the option.
4. "shared internet connection" is not the default connection. If you haven't changed that setting already then the default connection should be auto eth0.
P.S.: This how to was written considering the system to be ubuntu 9.04 but similar steps can be taken (with slight modifications) to do the same on any linux based system.