This tutorial should help you configure your ubuntu machine as a GATEWAY. So that means your ubuntu machine would share its internet connection to other machines connected on the network. For this you need a specific type of network setup . Your Ubuntu gateway machine needs Two network cards, 1 Card to connect your ubuntu machine to your DSL modem/router . The other card to connect your ubuntu machine to a hub/switch which inturn is connected to other machines(clients) in your network . Now your ubuntu machine should be able to take the internet connection from your DSL modem/router and share it with its clients which is connected to the other network card via a hub/switch . For this you need to configure internet connection sharing in your ubuntu machine . So here's how you do it :
This whole procedure is done via the command line , in certain steps i have mentioned ethX here x is usually 0 or 1 , it depends on your network setup sometimes eth0 is connected to the router and eth1 is connected to your clients , sometimes it could be the other way round.So lets go :
Step 1 : Open the Terminal(Applications->Accessories->Terminal)
Step 2 : Now type sudo -i and enter your root password
Step 3 : Now type in the following commands one after the other and remember to replace X with the correct interface number.
1) ifconfig ethX 192.168.0.1
here ethX is the network card which is connected to your machines(clients) via a hub/switch . 192.168.0.1 is your server ip address , you could change it to whatever you wish , although 192.168.0.1 is usually preferred
2) iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE
here ethX is the network card connected to your DSL modem/router i.e. from where the internet is coming from.
3) echo 1 > /proc/sys/net/ipv4/ip_forward
4) apt-get install dnsmasq ipmasq
5) /etc/init.d/dnsmasq restart
6) dpkg-reconfigure ipmasq
The following screenshots would help you configure ipmasq , select Yes, then click on OK then click on OK for "After network interfaces are brought up"
Now a few steps are repeated as shown below you need to type these again!!
7) ifconfig ethX 192.168.0.1
here ethX is the network card which is connected to your machines(clients) via a hub/switch . 192.168.0.1 is your server ip address , you could change it to whatever you wish , although 192.168.0.1 is usually preferred
8) iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE
here ethX is the network card connected to your DSL modem/router i.e. from where the internet is coming from.
9) echo 1 > /proc/sys/net/ipv4/ip_forward
10) sudo gedit /etc/sysctl.conf
Now add the line net.ipv4.ip_forward = 1 to the /etc/sysctl.conf file
Do a Reboot!!Thats it your done!!
|
5
comments
]
5 comments
Great! Simple and direct.
Thank you so much! This works like a charm!
hi there,
i connect my ubuntu machine to a router and get the net connection from there, i was planning to create a local network btw my macbook and ubuntu using a usb wireless adaptor, in the search of a solution i found your article.. unfortunately after following your instruction i completely lost my net connection (totally) on my ubuntu machine, its not even talking to my router.. could you please let me know how to undo the steps !! i have already unistalled those two packages on ubuntu (dnsmasq ipmasq).. pls let me know.. cheers. mail:eswararaj.s@ntlworld.com
i do appreciate your efforts.. my knowledge in networking is very very limited
Hurray
solved the problem
i had to completely delete the /etc/network/interface file and rewrite it to
auto lo
iface lo inet loopback
any how.. thanx
cheers
Nice.. Thanks for posting the solution ;)
Post a Comment