How to configure DHCP Server on Ubuntu

To configure DHCP Server on Ubuntu

DHCP stands for Dynamic Host Configuration Protocol which can used to allocate dynamic IP address for Client Systems. Dynamic IP’ s are automatically request from dhcp server, where static IP’ s are manually configured by user or system administrator. In order to simplify the work for administrator DHCP can be used to allocate IP address automatically for N number of systems.

To configure DHCP Server

In order to configure DHCP, you should update your repositories. Use the following command for the same process.

root@linuxhelp:~# apt-get update
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:2 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease 
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial InRelease              
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading package lists... Done

Use the following command to install the package for DHCP Server

root@linuxhelp:~# apt-get install isc-dhcp-server -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-42 linux-headers-4.4.0-42-generic linux-headers-4.4.0-53 linux-headers-4.4.0-53-generic linux-image-4.4.0-42-generic linux-image-4.4.0-53-generic
  linux-image-extra-4.4.0-42-generic linux-image-extra-4.4.0-53-generic
Use ' sudo apt autoremove'  to remove them.
The following additional packages will be installed:
  libirs-export141 libisccfg-export140
Suggested packages:
  isc-dhcp-server-ldap policycoreutils
.
.
.
Setting up libisccfg-export140 (1:9.10.3.dfsg.P4-8ubuntu1.4) ...
Setting up libirs-export141 (1:9.10.3.dfsg.P4-8ubuntu1.4) ...
Setting up isc-dhcp-server (4.3.3-5ubuntu12.6) ...
Generating /etc/default/isc-dhcp-server...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for systemd (229-4ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...

Now, assign the network interface with the help of following command.

root@linuxhelp:~# vim /etc/default/isc-dhcp-server
INTERFACES=” ens33” 
To configure DHCP service we need to edit dhcpd.conf file and mention the following required values in your configuration
Network IP : 192.168.7.0/24
IP Range : 192.168.7.141 - 192.168.7.145
Gateway : 192.168.7.1
Primary DNS : 192.168.7.130
Sec DNS : 8.8.8.8

root@linuxhelp:~# vim /etc/dhcp/dhcpd.conf
subnet 192.168.7.0 netmask 255.255.255.0
{
    range 192.168.7.141 192.168.7.145 
    option domain-name-servers 192.168.7.130, 8.8.8.8 
    option domain-name " linuxhelp.example.com"   
    option routers 192.168.7.1 
    option broadcast-address 192.168.7.255  #Broadcast
    default-lease-time 600 
    max-lease-time 7200 
}

Once the DHCP configuration is done, start and enable the service to take effect.

root@linuxhelp:~# systemctl start isc-dhcp-server6
root@linuxhelp:~# systemctl enable isc-dhcp-server6

Now DHCP server is setup and ready.

Tag : DHCP
FAQ
Q
Does DHCP support statically defined addresses?
A
Yes. At least there is nothing in the protocol to preclude this and one expects it to be a feature of any DHCP server. This is really a server matter and the client should work either way. The RFC refers to this as manual allocation.
Q
Can a BOOTP client boot from a DHCP server?
A
Only if the DHCP server is specifically written to also handle BOOTP queries.
Q
Can a DHCP client update its DNS entry through DHCP?
A
No. There has been some discussion about adding this ability to DHCP.
Q
How can DHCP server back up another DHCP server?
A
You can have two or more servers handing out leases for different addresses. If each has a dynamic pool accessible to the same clients, then even if one server is down, one of those clients can lease an address from the other server.
Q
What is DHCP's purpose?
A
DHCP's purpose is to enable individual computers on an IP network to extract their configurations from a server (the 'DHCP server') or servers, in particular, servers that have no exact information about the individual computers until they request the information. The overall purpose of this is to reduce the work necessary to administer a large IP network.