Ubuntu Geek

Ubuntu Linux Tips,Howtos&Tutorials|Edgy,Feisty,Gutsy,Hardy,Intrepid

  • RSS Feed

    subscribe to the ubuntu Geek RSS feed


  • Sponsor



  • Categories

  • Meta

  • Sponsor

  • Archives

  • Support Ubuntugeek

    Amount $:
    Website(Optional):


  • Favourite Sites

Sharing Internet Connection in Ubuntu

Posted by admin on June 24th, 2007 Email This Post Email This Post

Setting up a computer to share its internet connection should be easy.After all, you’ve successfully networked your computers together and even shared files with all your home computers, so why not the Internet? Well if you have a small home network of computers all connected and have tried to open up a browser, you’ve probably found out that things aren’t quite as straight forward as connecting one machine with an Ethernet cable to the computer that has the DSL/cable modem.

The secret is that everything comes down to having a gateway.

A gateway is a computer or device than can route data between different networks. Put it this way, if your computers are on one network and every other computer connected to the Internet is on a different one, to pass information across network boundaries you need a device which is connected to both networks and equipped to decide whether information from one network should go out to the other network, and vice versa.

So, without a gateway there is no way for the other computers in your network to receive or pass information to the other networks, and consequently, they have no Internet access.

The computer in your small network which is directly connected to the cable or DSL modem is provided with a default gateway by the Internet service provider. That allows the computer to connect to the interenet, but unfortunately for us that gateway is not part of your home network - rather it is a separate network formed between the computer connected to the cable/DSL modem and the ISP itself.

In order to enable Internet access on the rest of your small home network, the computer or device that connects with your ISP must become a gateway for the computers in your local home network. Once this has been configured, it will enable all of the other home network computers to access the Internet by sending and receiving information through that gateway.

The easiest way of acquiring a gateway for your home network is to buy a cable/DSL router. Given how cheap they currently are (about a quarter of the price they commanded when they first appeared in the marketplace), there really isn’t much of an excuse not to buy one.

The major advantages of having a hardware router doing your internet sharing include minimal configuration, since they are set up to act as a gateway by default (it’s pretty much all they do), increased reliability (they are not a PC… PCs crash.), and security, since most of these devices incorporate a firewall. Highly recommended!

You’ll also need

a working dial-up Internet account with an Internet Service Provider (ISP) or

a working broadband (cable, DSL, satellite, etc.) Internet connection.

Share your Internet connection using the following Procedure

Note: Type all the following commands in a root terminal

Start by configuring the network card that interfaces to the other computers on you network

# ifconfig ethX ip

where ethX is the network card and ip is your desired server ip address (Usually 192.168.0.1 is used)

Then configure the NAT as follows

# iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE

where ethX is the network card that the Internet is coming from

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

Install dnsmasq and ipmasq using the following command

# apt-get install dnsmasq ipmasq

Restart dnsmasq using the following command

# /etc/init.d/dnsmasq restart

Reconfigure ipmasq to start after networking has been started

# dpkg-reconfigure ipmasq

Start by configuring the network card that interfaces to the other computers on you network

# ifconfig ethX ip

where ethX is the network card and ip is your desired server ip address (Usually 192.168.0.1 is used)

Then configure the NAT as follows

# iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE

where ethX is the network card that the Internet is coming from

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

Add the line “net.ipv4.ip_forward = 1″ to /etc/sysctl.conf

# gedit /etc/sysctl.conf

Reboot your system is optional.

Share/Save/Bookmark

If you want to be notified the next time we write something please subscribe to our RSS feed.Thanks for Visiting!

Related Articles

16 Responses to “Sharing Internet Connection in Ubuntu”

  1. Dim Says:

    And why do not simply apt-get install ‘firestarter’ which is already doing all this staff for you just in few clicks?…

    Rgds,
    -dim

  2. sinoj Says:

    Hi,
    I just tried those steps and now I can’t even browse from Ubuntu.
    any idea? I’m new to Ubuntu. please help.

  3. Allison Says:

    ‘llo.

    I tried those steps above, but my second computer still doesn’t connect to the Internet.
    Ubuntu 7.04 is installed in both pcs.

    Another thing: firestarter can’t help here too.

  4. Esmeal Says:

    it doesn’t work apt-get install it says “E: Coudn;t find package dnsmasq” any idea please

  5. a Says:

    dnsmasq is in universe-package.

    (
    sudo nano /etc/apt/sources.lst
    Remove # from line which contains universe.
    sudo apt-get update
    )

  6. ptra8 Says:

    can anyone tell me step-by-step to configure internet sharing on ubuntu..
    i cant understand.. i’m new use ubuntu.. plezzz

  7. Fabiano Duarte Says:

    It doesnt work. I dont know if the problem is the version of Ubuntu i have or ???? …. Cause i didnt find the packages dnsmasq and ipmasq at Synaptic.

  8. karunadheera Says:

    I have tried this. I also found i could not even browse internet after that!. Then rolled back several changes and got rid of that.

  9. Bob Says:

    #7: See #5. You can also do this point-and-click by enabling universe in ’software sources.’

  10. kaus Says:

    I am new to ubuntu. Please help me with more details about connecting only two computers one having Ubuntu and another xp

  11. Motin Says:

    As previously mentioned this method is far to complicated. Easier way:

    Install “Firestarter” using Applications -> Add/remove.
    Then run Applications -> Internet -> Firestarter and follow the configuration guide (about 3-4 questions about how you connect to the internet and LAN)

    If you do not enable the DHCP-option* (automatic network configuration) you will have to manually set the ips of the other machines so that they begin with the same three groups of numbers (eg 192.168.0.x) as the internet-connected machine has on the LAN. Then, set the gateway ip of the other machines to the ip of the internet-connected machine.

    * Do not do this if your network already has a DHCP server (ie via an existing router) - two DHCP servers on the same network that gives out different settings is a bad idea…

  12. bob Says:

    Motin’s comment should be added to this post as a simpler alternative.

    Good job Motin

  13. feistytom Says:

    WOW! this tutorial is the best!!!

    after a couple of tries, i have picture-perfect internet sharing,

    thanx a ton!

  14. gocho Says:

    It works… Just needed to change DNS :)

  15. Tuoni Says:

    You can’t use the firestarter stuff unless you’re working in a graphic environment, the tutorial only requires command line access.

    Very usefull stuff, but the comment about the universe packages should be added to the tutorial, to many people would miss that else (I did to at first)
    But when adding those packages, it worked like a charm, thanks a lot!

  16. simon Says:

    So I have a linksys router right now but it is kind of a piece of garbage and I was wondering if I got a wireless card and put it in my computer and did this would it then work as a wireless router?
    Like the internet would come directly into my computer and then it would serve up to different laptops in my house wirelessly. Am I right? And would this be better than my linksys router?
    Thanks.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>