Sharing Internet Connection in Ubuntu

Sponsored Link
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.

 

You may also like...

41 Responses

  1. Shrikant says:

    i have a 8 port switch……
    Wat i hav to do share internet if i have ubuntu and my friend has windows XP professional….

  2. cutiyar says:

    its working with usb modem internet? not wired .

  3. Neel says:

    I have already set up my internet on my Ubuntu 10.10. I have two internet connections, one at the office and one at home. Now when I try opening youtube-dl, Evolution mail, gpg sever key download from home it doesnt get downloaded and says ‘Connection Timed out’. However at my office premises all the above programs work like a charm.
    P.S. I have two different speed connections at home and office. Also two different kinds of Modems. All other sites opening and downloads work like a charm on both the connections.
    Kindly suggest what could be the possible solution.

  4. rjdreyes says:

    @Neel,

    it might be different smtp settings. On evolution mail, if youre isp is different from office unto your house probably it uses different smtp. check your isp provider or contact them for the smtp address, and if the allowed smtp port connection.

  5. ayub says:

    I am using cable net and I have wireless router of netgear how can I share my network connection to my other computers I can use internet at only one computer at same time I can not connect to other computers there is a user name and password required
    and I can not use my internet on iphone please help me I shall be ver thankful to you.

  6. Trevor Jones says:

    When attempting to follow your method I receive the following:
    root@trevorj-Linux:/home/trevorj# apt-get install dnsmasq ipmasq
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package ipmasq is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘ipmasq’ has no installation candidate

    can you help?

  7. birkopf says:

    I have a question. I have an ADSL connection going to router, and from router via cable to my laptop. No WiFi enabled. Can I connect my Blackberry to the internet via my laptop? I mean could I create some wifi network on/from my laptop that my BB could connect to ?

  8. uydunet says:

    I dont like wireless, cable systems everytime stable, thank you from uydunet.

  9. Nico says:

    Great info, is there anything that needs to be done to the computer receiving the shared internet?

    My small home network is configured on windows and is broadcasting on a second router. The internet connection works on other computers (windows / mac) but I can’t connect from Ubuntu 11.04. I can see the name of the network in the network manager, can connect in “Local-only” mode, but cannot get any data from the internet…

    maybe i should upgrade??

  10. Hi,

    I have faced a problem in a company. Problem is : “We have use single broadband connection as wired and wireless into the company. But recently, we are using another broadband connection into the company. Our Company server is connected with earlier connection through Ethernet point. So in that LAN people have access the server accept those using another broadband connection.”

    i couldn’t found the solution where i can link between 2 network.

    Can you pls help me out of this problem.

    Best Regards,
    Shubham

  11. kuzgtr says:

    I need help, to share usb internet wirelessly on ubuntu?

Leave a Reply

Your email address will not be published. Required fields are marked *