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 "unpatti.ac.id";
option domain-name-servers 202.134.0.155;
option routers 192.168.76.1;

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

log-facility local7;

subnet 192.168.76.0 netmask 255.255.255.0 {
range 192.168.76.10 192.168.76.200;
}
#

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

INTERFACES="ethx"

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 192.168.76.0 netmask 255.255.255.0 gw 192.168.76.1

Ref: http://www.somewhereville.com/?p=1196