Sharing Internet Connection in Ubuntu
Posted by admin on June 24th, 2007
Email This Post
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.
If you want to be notified the next time we write something please subscribe to our RSS feed.Thanks for Visiting!


June 24th, 2007 at 9:09 pm
And why do not simply apt-get install ‘firestarter’ which is already doing all this staff for you just in few clicks?…
Rgds,
-dim
June 25th, 2007 at 2:42 pm
Hi,
I just tried those steps and now I can’t even browse from Ubuntu.
any idea? I’m new to Ubuntu. please help.
July 29th, 2007 at 12:39 am
‘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.
August 7th, 2007 at 9:00 pm
it doesn’t work apt-get install it says “E: Coudn;t find package dnsmasq” any idea please
August 9th, 2007 at 7:43 am
dnsmasq is in universe-package.
(
sudo nano /etc/apt/sources.lst
Remove # from line which contains universe.
sudo apt-get update
)
January 28th, 2008 at 11:47 am
can anyone tell me step-by-step to configure internet sharing on ubuntu..
i cant understand.. i’m new use ubuntu.. plezzz
April 5th, 2008 at 1:42 pm
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.
May 10th, 2008 at 5:21 am
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.
May 18th, 2008 at 1:24 am
#7: See #5. You can also do this point-and-click by enabling universe in ’software sources.’
July 5th, 2008 at 12:26 pm
I am new to ubuntu. Please help me with more details about connecting only two computers one having Ubuntu and another xp
July 19th, 2008 at 9:42 pm
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…
August 14th, 2008 at 8:44 pm
Motin’s comment should be added to this post as a simpler alternative.
Good job Motin
August 17th, 2008 at 12:50 am
WOW! this tutorial is the best!!!
after a couple of tries, i have picture-perfect internet sharing,
thanx a ton!
August 22nd, 2008 at 4:08 am
It works… Just needed to change DNS
August 29th, 2008 at 10:13 pm
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!
September 2nd, 2008 at 4:40 am
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.