Home Download Ubuntu

Configure internet connection sharing in Ubuntu

Before we continue the following tutorial, you have to make sure that you have configured network interfaces and that you are having a working internet connection. In our example we are going to use eth0 as local area network (ip 192.168.0.1) and eth1 as wide are network.

sudo iptables -A FORWARD -i eth1 -o eth0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT

sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT


Finally we made NAT:

sudo iptables -A POSTROUTING -t nat -j MASQUERADE


Configure the gateway for routing between two interfaces by enabling IP forwarding:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"


Edit /etc/sysctl.conf and add these lines or uncomment by removing # or ; in front of them if they are commented:

net.ipv4.conf.default.forwarding=1
net.ipv4.conf.all.forwarding=1


To be able to have this configuration at every start-up, you should do something like this example. Please note that this is just an example. There are many ways to configure ics to run at boot. I found this easier.

Resources: Ubuntu.com

0 comments:

Post a Comment