Let's start. First you have to install dhcp server.
sudo apt-get install isc-dhcp-server
There are two main files /etc/default/isc-dhcp-server
and /etc/dhcp/dhcpd.conf
which we will need to configure so lets take the first.
Configuration of DHCP server
First you need to configure /etc/default/isc-dhcp-server
file so you need to edit the file using the following command
sudo nano /etc/default/isc-dhcp-server
You should see similar to the following
#Defaults for dhcp initscript
#sourced by /etc/init.d/dhcp
#installed at /etc/default/isc-dhcp-server by the maintainer scripts
#
#This is a POSIX shell fragment
#
#On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#Separate multiple interfaces with spaces, e.g. “eth0 eth1?.
INTERFACES=”eth0?
Replace eth0
above with the name of your network interface that you want the server to lease addresses on.
Save and exit the file
Now you need to configure /etc/dhcp/dhcpd.conf
file for this edit this file using the following command
sudo nano /etc/dhcp/dhcpd.conf
Minimal conf is:
# minimal sample /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
subnet 172.20.0.0 netmask 255.255.0.0 {
range 172.20.0.1 172.20.255.252;
option routers 172.20.255.254;
option domain-name-servers 192.168.x.x, 192.168.x.x;
option domain-name "mydomain.example";
}
Finally you have to restart the dhcp service by using the following command
sudo service isc-dhcp-server restart
You can check if your dhcp server is working properly bt running the following command
sudo netstat -uap
After this action you must forward traffic from one nic to other
Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
Configure iptables
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
Change eth0 and eth1 with your interfaces.