There is several ways to share internet connection using Ubuntu Server. But this in this tutorial, I'll be using one method that is quite simple and proven to be working on Ubuntu Hardy. But as far as i know, this kind of setting will work on any distribution which support iptables.
Here is the steps to share your internet connection:
sudo -s
- Then change the setting in sysctl to allow ip forwarding by running this command:
sysctl -w net.ipv4.ip_forward=1
- By the way, sysctl actually will run on Ubuntu startup automatically, but to be sure just edit the /etc/sysctl.conf:
#nano /etc/sysctl.conf
net.ipv4.ip_forward = 1
iptables
Then we need to masquerade the service. This could be a little bit tricky, but still it's easy to use. Let say if your server connected to internet using wireless device, so the device interface should be wlan0. And a network card connected to your local area network is eth0. So here is some example in the interface setting:
wlan0:
IP = 10.41.57.103
netmask = 255.255.0.0
gateway = 10.41.57.254
eth0:
IP = 192.168.1.10
netmask = 255.255.255.0
gateway = 10.41.57.254(IP for the gateway of wlan0)
- If you can see, the setting for eth0's gateway is using the same gateway as wlan0, so we need to masquerade it using iptables to allow packets to be forward through 2 interfaces. To masquerade, here is the command:
#iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
#service iptables save
It's all done with the server setting, now we have to do the setting for client pc, in this example, the client is using winxp, so all we have to do is to set the ip manually. The ip should be like this:
IP = 192.168.1.100 (Well the ip can be anything but have to be on the same class)
netmask = 255.255.255.0
gateway = 192.168.1.10
DNS = 192.168.1.10
So this one should help all user to share internet connection using Ubuntu Server. I'm not expert on the network subject but this one is simple and easy to understand. I hope this will help you out.