How to share your Internet connection on Ubuntu

For many moons ever since i started using Linux i have always wanted an easy way to share my internet connections between two computers. anyway i finally found a way to get it to work. Now i can share internet connection between my work laptop and my personally laptop.

Please while it might be possible on some other laptops. my laptop came with the PRO/Wireless 3945ABG and its impossible to share my internet over wireless because the current driver for my device doesnt support master mode which is what is needed for this to be possible. But with this guide it would be possible to share intenet via Lan. so if you get your intenet connection over wlan or a 3g modem or anything modem. it would be possible to share that same internet over Lan. Note if you got your wifi to work through ndiswrapper then we are also in the same shoes and sharing via wifi wont work. Infact this post is not about sharing your internet via wifi period.

Ok enough talk. To get started we would need tool packages. Firestarter and dhcp both can be installed with this command

sudo apt-get install firestarter dhcp3-server

Next we need to configure the internal Network Card that other computers get their internet from. In my case since the shaing computer gets internet from Wifi my internal network card (i.e the card other computers would be getting their internet from) would be eth0. we need to configure the card and assign a static IP address in a range that you will use for your internal network card. so rightclick on the Network manager applet and select edit

click the wired tab and select Auto eth0 (or the card of the particular card you want to coonfigure as the sharing interface) and click edit.

null

now select IPv4 Settings and choose Manual. now Add

and set it up to your preference. for example i set like this IP address to 192.168.0.1, and the subnet mask to 255.255.255.0. Leave the gateway empty.

Now we need to fix a problem where firestarter cannot locate the DHCP daemon script

so we open a terminal and run this command

sudo ln -sf /etc/init.d/dhcp3-server /etc/init.d/dhcpd

Next we configure the interface that DCHP will be listening to.

To do this we need to edit this file /etc/default/dhcp3-server

gksu gedit /etc/default/dhcp3-server

only variable in there by default is “INTERFACES”, which will have a null value. Set it to your internal network interface. For example:

# Defaults for dhcp initscript
# sourced by /etc/init.d/dhcp
# installed at /etc/default/dhcp3-server by the maintainer scripts

#
# This is a POSIX shell fragment
#

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. “eth0 eth1″.
INTERFACES=”eth0″

save and exit

Now we run Firestarter Applications/Internet/Firestarter

A wizard should appear Select your Detected Device (Internet-connected) if your sharing computer gets its Internet via wifi then your external device would mostly be wlan0. if you are connected via a modem then it would be ppp0 device when it asks, and make sure to specify whether or not the address is obtained via DHCP. Click the “Forward” button, check the “Enable Internet connection sharing” box, select your internal network card,”Start firewall now” box, Then click on Preference and and Network settings.

“Enable DHCP for local network”. Drop down the “DHCP server details” and enter the range of IPs you would like for it to dynamically assign. Make sure they are in the same range as the static IP you set for your internal network card. You can leave the DNS field as “” Click “Forward”, check the “Start firewall now” box, and click “Save”.

“Enable DHCP for local network”. Drop down the “DHCP server details” and enter the range of IPs you would like for it to dynamically assign. Make sure they are in the same range as the static IP you set for your internal network card. You can leave the DNS field as “” Click “Forward”, check the “Start firewall now” box, and click “Save”.

At this stage am able to ping the from the other computer but am unable to access the internet. to fix this we need to add “net.ipv4.ip_forward = 1″ to /etc/sysctl.conf

to /etc/sysctl.conf

so
gksu gedit /etc/sysctl.conf

and add this at the bottom

net.ipv4.ip_forward = 1
save and close.

now if all goes well you will be able to share your Internet to another laptop or computer. hope this helps some body

To share your internet using your wireless connection use this guide

This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.

This entry was posted in Connectivity, Uncategorized. Bookmark the permalink.
  • John

    Awesome! Xbox 360 via wifi, for free! Thank you so much.
    To others: This took me a while because I didn’t read all of the directions first. It would have gone a lot faster if I did.

    Thanks again!

    John

  • Peter

    Shouldn’t the IP address in Network manager, wired tab, IPv4 Settings be 192.168.1.100 , just for consistency ?

    This would be because the Firestarter comment stated “Make sure they are in the same range as the static IP you set for your internal network card.”

    Peter

  • Pingback: Share You Internet wirelessly on Ubuntu « bigbrovar

  • Ugo

    This totally works. Well done brov!

  • http://www.bronius.com bronius

    It works, it really works! And really simple, too. Thanks very much for posting :D

    One thing is unclear to me: where you set 192.168.0.1, what is this IP referring to? Are we making it up at this point? Is it the new dhcp?..

    Also a little word to the wayward journeyman: I hit some errors starting apt-get installing dhcp server and again starting it (and “eth0 is not ready yet” is what firewall reported) until I rebooted. This is likely due to other, unrelated updates I had done..

  • http://www.bronius.com bronius

    Oh one more thing: I’ve successfully set up DirecTV On Demand using your instructions above :D

  • http://1xN.org Dan

    Ahhh I cant get it to work… it always says “device eth0 not ready” when starting firestarter.. cannot find the source of the problem… also I cannot set the range for the dhcp in firestarter.. it always reverts to keep existing DHCP…

  • http://www.bronius.com bronius

    For me, at least, that’s when a restart of the machine landed me back in the right again..

  • priyesh

    Dan,
    you need to make sure that the eth0 interface is up before starting the firewall. You can either do ifconfig eth0 192.168.0.1 255.255.255.0 or edit your /etc/network/interfaces to add the static setup before starting the firewall.

  • http://this-is-saurabh.blogspot.com Saurabh Gupta

    thanks a ton man.. i was fighting on this thing from long back..
    thanks for posting.. :)

  • http://bigbrovar.wordpress.com/ Bigbrovar

    @Saurabh Gupta glad it worked for you :)

  • J

    Works Great! Quick and easy. I tried another guide and this is way simpler.

  • http://www.homelesschattanooga.org/ grundygreen

    I’ve look at both howto’s .
    Could you not use dnsmasq to feed eth0?
    If so how?
    They set up pfsense at the charity I work for.
    I can get on but it screws up my net installs. So feeding an ad hoc install subnet from a laptop is a boon.

  • zandoval

    BRAVO – The steps are revealed – I find it interesting that you need to set up a net sharing a SAMBA file with assigned IP addresses before even thinking about getting going with internet connection sharing – Installing firestarter and DHCP3-server on the same command line at least insured repository compatibility – The Gedit commands worked – I AM HAPPY – It works…

    • http://bigbrovar.wordpress.com/ Bigbrovar

      thanks mate .. i appreciate the feed back

  • chris s

    THANK YOU SO MUCH!!!!! NOW I HAVE A HOME NETWORK SET UP FROM UBUNTU!!!! Finally a replacement to windows server. ewwww!!! windows.. win-blows. lol

  • chris s

    THANK YOU SO MUCH!!!!! NOW I HAVE A HOME NETWORK SET UP FROM UBUNTU!!!! Finally a replacement to windows server. ewwww!!! windows.. win-blows.

  • Rohel

    Firestarter doesn’t work for me.

  • Rohel

    Nevermind I got Firestarter to work but it won’t locate my wireless connection

  • Mike

    After doing all of this when I load Firestarter I get a message saying that the firewall could not be started because eth0 is not ready, I tried rebooting and I followed everything very precisely. Any ideas why this is happening?

    • Michael

      Worked like a charm, doumo arigatou.

      “After doing all of this when I load Firestarter I get a message saying that the firewall could not be started because eth0 is not ready, I tried rebooting and I followed everything very precisely. Any ideas why this is happening?”

      I got the same but that was because there was nothing connected to eth0, check to see if the other machine is connected.

  • streetbiker

    This was a huge help to me, thanks!!!  Very well written and explicit with regard to exact steps to follow.