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.

Installation

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 

INTERFACES=""

to,

INTERFACES="eth0"

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.

Address: 10.0.0.1

Netmask: 255.255.255.0

Gateway: 0.0.0.0

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.

14 Comments

Ben (not verified)
March 14th, 2010 03:37 pm
Im struggling to get two ubuntu computers to connect. I have a Ubuntu 9.10 laptop which is connected to internet by wifi then I have a ubuntu 9.04 laptop which has no internet connection at all.
March 15th, 2010 03:23 pm

I have used a similar scenario in the howto. It should have worked for you. Where are you stuck.. btw?

Ben (not verified)
March 15th, 2010 03:46 pm
I'm going to try this tutorial again, I've had to reinstall Ubuntu 9.10 because after all these tutorials I've been doing I must have stuffed something up along the way. Should I be doing something different with the eth0 and eth1? Because the laptop with Internet is connected via wifi. Before on the computer without Internet it says it's connected to eth0 but you can't use the Internet on it.
March 15th, 2010 06:27 pm

This tutorial should work, because this is how I used to connect my laptop, which had internet access through wifi, to my desktop using a LAN cable. In case you are confused with the interfaces, eth0 is generally the wired interface. You can always use "ifconfig -a" to see which interface is your wifi, the one with the IP address because its connected and working, and which is wired.

And if things don't work for you, you can easily switch back to the old configuration by uninstalling each of the softwares you have installed. If you face any trouble following the tutorial, let me know.

Ben (not verified)
March 16th, 2010 12:28 pm
Right, so I'm doing the tutorial again, and just making sure. When I get to "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" Are we doing this one the computer with or without internet? I think its the computer without that I do this on, ill see.
Ben (not verified)
March 16th, 2010 12:41 pm
Right, firestarter is installed and running, both computers are connected Both have "shared etho" as a wired connection. Still doesn't work, Is there something I've done wrong? (Probably having two 'shared eth0' connections . . .)
March 16th, 2010 01:04 pm

First of all, the shared connection is to be made on the machine which has internet connectivity through wireless. The wireless interface (eth1 or eth2 or wlan0 etc.) already has an IP address. The point of making a "shared connection" is to make sure that we assign an IP address to the eth0(wired) interface manually which will be its local address for the LAN that will be created when you connect it to the other computer.

So, have you done all this correctly? And one more thing, the other machine(no internet) should be set to "auto eth0" while connecting. This is will ensure that the no-internet computer automatically gets an IP address and internet too.

Ben (not verified)
March 16th, 2010 01:47 pm
Right heres the setup. Computer with internet: Shared Internet-eth0 connection Firestarter-(For some reason keeps saying 'Cannot start firewall" but other than that has the settings in this tutorial and says its active) Computer without internet: auto eth0 is not connecting.
March 16th, 2010 02:31 pm

Firestarter should start. Take a look at the image showed in step 5. Set the internet connected device to your wireless interface(eth1, wlan0 etc.) and the local network connected device to eth0. Use the same configuration of firestarter as mentioned in the image. I should have mentioned these steps more clearly. See, if  it works now.

Ben (not verified)
March 16th, 2010 03:01 pm
Firestarters configuration matches that in the screenshot. Still doesn't connect. Could this have something to do with 9.10? I wouldn't have thought it was that much of a difference.
Ben (not verified)
March 16th, 2010 03:09 pm
Whoa! Don't know what's going on but it suddenly started working. Eh not sure. Thanks a bunch for the help getting it to work. I'd say I owe you one, but last time I said that it got me into strife . . . Thanks. Ben
March 16th, 2010 03:17 pm

That's really strange. Something should have been wrong with the configuration because I am using 9.10 and it works well here. Is dhcp3 server running fine. Make sure that when you connect both the computers, you should select "shared internet" network(this is to give an IP to the eth0/wired interface) on the Internet-working computer and "auto eth0" on the no-internet computer. So, now it means that your first computer is connected to internet using wirless interface and to LAN using eth0/wired.

In order to trouble shoot, you can check the IP addresses that get alloted to the respective interfaces on the first computer, once it is connected to both the networks (wireless and shared). Run "ifconfig -a"  and post the output on pastebin.com and share the link here.

March 16th, 2010 03:37 pm
Thanks again, I've now been able to give the other laptop a much needed update, Plus I have Synergy working on it now so thats pretty cool. Starting to love this website. Yours Truly. Ben
ardigma (not verified)
October 10th, 2010 06:34 pm
great!!!! thanks a lot for you guide worked perfectly with me! Do you mind if I quote you in my page? Thanks again. Ardigma

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.