Step by Step for NAT Gateway and DHCP Server configuration on Ubuntu Server 12.04


Ubuntu 12.04 IPv4 NAT Gateway and DHCP Server

Step :1
  1. Install ubuntu server
  2. configure ipaddress manually
  3. install openssh server
Note:don't insert secondary lan card

Step:2
  1. shutdown the system
  2. insert secondary lan card
  3. configure ipaddress for secondary lancard
  4. //etc/network/interfaces
Step:1 /etc/network/interfaces
sudo vim /etc/network/interfaces

             	auto lo
             	iface lo inet loopback
auto eth0
			iface eth0 inet static
    				address 10.20.30.77
    				netmask 255.255.255.0
    				gateway 10.20.30.1
    				network 10.20.30.0
    				broadcast 10.20.30.255
   				dns-nameservers 10.20.30.15 10.20.30.16
   				dns-search codeghar.com

			auto eth1
			iface eth1 inet static
    				address 172.22.22.1
                       	netmask 255.255.255.0
    				network 172.22.22.0
    				broadcast 172.22.22.255
step:2 /etc/sysctl.conf
sudo vim /etc/sysctl.conf
And uncomment the line
# net.ipv4.ip_forward=1
so that it now appears as
net.ipv4.ip_forward=1
Step:3
sudo sysctl -w net.ipv4.ip_forward=1

Step:4 : /etc/rc.local
sudo vim /etc/rc.local
Make sure the following two lines appear before the exit 0 line in the file.
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables --table nat -A POSTROUTING -o eth0 -j MASQUERADE
Step:5
sudo iptables -P FORWARD ACCEPT
sudo iptables –-table nat -A POSTROUTING -o eth0 -j MASQUERADE

Step:6 Restart Networkin Services
sudo /etc/init.d/networking stop
sudo /etc/init.d/networking start

Step:7 chckout eth0 and eth1 are up or not
sudo ifconfig eth0 up
sudo ifconfig eth1 up

Step :3 Install DHCP server

Step:1 Install DHCP server
sudo aptitude install isc-dhcp-server

Step:2 /etc/dhcp/dhcpd.conf
sudo vim /etc/dhcp/dhcpd.conf
The file is very well commented and you can learn a lot reading it. Just make sure it has at least the following configuration.
ddns-update-style none;

# option definitions common to all supported networks...
option domain-name "codeghar.com";
option domain-name-servers 10.20.30.15, 10.20.30.16;

default-lease-time 3600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# This is a very basic subnet declaration.
subnet 172.22.22.0 netmask 255.255.255.0 {
range 172.22.22.21 172.22.22.250;
option routers 172.22.22.1;
}

Step :3 /etc/default/isc-dhcp-server
sudo vim /etc/default/isc-dhcp-server
The line will look like this before you change it
	INTERFACES=""
And after you change it, it will look like this:
	INTERFACES="eth1"
Step:4 stop and start the DHCP server
sudo service isc-dhcp-server stop
sudo service isc-dhcp-server start




0 comments:

Post a Comment