Set Up Internet Connection Sharing on Ubuntu

- - No comments
SET UP INTERNET CONNECTION SHARING ON UBUNTU: If you want to share your internet connection on Ubuntu, just follow these steps. But first, some prerequisites:

-2 network cards on the computer the internet is coming from
-1 network cable (not crossover) to connect the two computers
-1 network card on the second computer

For the computer the internet connection is coming from or we shall call it computer 1, follow the steps for setting it up:

Step-1. Open a terminal and use this command:

ifconfig ethX ip

*Where 'ethX' is the network card that is going to be connected to the second computer and 'ip' is your desired server IP address (Usually is used)

Step-2. Configure NAT by:

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

*Where 'ethX' is the network card that the Internet connection is coming from. Then type:

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

Step-3. Now, we will have to install the packages dnsmasq and ipmasq:

sudo apt-get install dnsmasq ipmasq

Step-4. Restart dnsmasq using this command:

/etc/init.d/dnsmasq restart

Step-5. You should reconfigure ipmasq to run after networking has been started:

dpkg-reconfigure ipmasq

Step-6. Repeat steps 1 and 2.

Step-7. Add the line "net.ipv4.ip_forward = 1" to /etc/sysctl.conf by using a text editor:

gedit /etc/sysctl.conf

Configuring the second computer (computer 2):

Set the network card ip to:
Netmask: (like the first computer)

You can also enter the internet DNS's from the computer connected to the internet.

Note: The DNS's can be found in the following file: /etc/resolv.conf and have this syntax: nameserver ip

PS: If using Ubuntu Jaunty and later, you must add a line to /etc/rc.local so that this is persistent after restarting your computer.

gksu gedit /etc/rc.local

Paste this line:

sudo iptables -A POSTROUTING -t nat -j MASQUERADE

That's about. Now enjoy sharing your internet connection in Ubuntu.

No comments

Post a Comment