Internet Connection Sharing using Ubuntu 10.04 LTS as NAT Gateway

posted in: Networking, Technical | 0

The following how to contains procedures to configure an Ubuntu 10.04 LTS machine to be used as a NAT (Network Address Translation) gateway for sharing internet connection.

Part A. Configuring IP v4 forwarding option

A.1. Edit the sysctl.conf file by issuing command: nano /etc/sysctl.conf  and un-commented (remove hash mark) from the following line # net.ipv4.ip_forward=1
A.2. Open the rc.local file by issuing command: nano /etc/rc.local, next, add the following lines before exit 0 line

/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE
#(before exit 0 line)

sudo apt-get install dhcp3-server

edit the file /etc/dhcp3/dhcpd.conf and insert the following section:

ddns-update-style none;
option domain-name "";
option domain-name-servers;
option routers;

default-lease-time 42300;
max-lease-time 84600;

log-facility local7;

subnet netmask {

edit the file /etc/default/dhcp3-server and replace the x of ethx to match number / index of the eth interface used.


start DHCP server: sudo /etc/init.d/dhcp3-server start

edit /etc/network/interfaces and add the following section at the end of the file.

# static route(s)
up route add -net netmask gw