DHCP CONFIGURATION IN LINUX UBUNTU -16.04.3-server
- Sankalpa H.T.S
- Jun 26, 2018
- 4 min read
Updated: Jun 27, 2018

In this document we are going to set up DHCP server (192.168.100.10) and assign IP address for the client machine dynamically (192.168.100.50) and assign static IP address (192.168.100.200) for the apache web server.
At the beginning of the process we will see what is the IP address of the current working server by ifconfig command. I’m

Set Static IP To The Server
Open the /etc/network/interfaces file to put the static IP address for the server as 192.168.100.10

The file should look like following:

Below the primary network interface line add the following lines as shown.

When we add lines for static IP address we want to add a line for gateway address. We can find gateway address by using nmcli device show command.

It will show us the gateway address.

Now we configured static IP address for the server. Let’s turn down the interface and reboot the machine to implement the changes.


Let’s confirm our static IP configuration is working.

Installation
Let’s install the isc-dhcp-server to the server machine. Check wheather the isc-dhcp-server package is exist by typing apt-cache search isc-dhcp-server.

After find the suitable package we can download it by typing sudo apt-get install isc-dhcp-server. But in here I’m not using sudo before the command line because I’m already in sudo mode.

It will be downloaded. But unfortunately in my server it didn’t download. So I have to fix the problem. It showed the error messages as below.

It is saying run the apt-get update or try with –fix-missing. Try the first suggestion update.

It also didn’t work. It seems my internet access is not working properly.

Use ping command to check weather I have internet access or not. Ping to 8.8.8.8

I have the internet access. But somehow download process failed to fetch and resolving security.ubuntu.com faliure. Go to the /etc/network/interfaces and add lines as shown.


Try to update the server again.

It still doesn’t work. Open the /etc/resolv.conf file and add below lines as shown.

And delete the lines that we add to the interfaces file after that lines we add for set static IP address

Now try to update the server again.

Now internet is working properly. We can download isc-dhcp-server now.

It will download as below.

Make sure specified package is installed.

Now we are going to add our interface into the /etc/default/isc-dhcp-server file.
Open that file.

File should looks like following.

Let’s add the name of the interface in the server.

Type the following command in the terminal

Run that command

Configuration
Open the dhcpd.conf file which is the main configuration file in dhcp package

Keep in mind always keep a backup of the original main configuration file when you are editing the main configuration file. In here I used backup as dhcpd.conf.backup. Go to the /etc/dhcp/

Copy the dhcpd.conf file as dhcpd.conf.backup

Check whether it is copied.

Now open the main configuration file to edit.

In the beginning of the file it will looks as below.

First edit the option domain name section. In here I’m using amaa.com as my domain name. And for my domain name servers I’m using ns1.amaa.com and ns2.amaa.com

In the middle of the configuration file there is a section as pointed. We can uncomment those lines and edit those lines for our purpose.

This will result in the DHCP server giving clients an IP address from the range 192.168.100.50- 192.168.100.100. It will lease an IP address for 600 seconds if the client doesn’t ask for a specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also “advice” the client to use 192.168.100.1 as the default gateway and ns1.amaa.com and ns2.amaa.com as it’s DNS servers.

After configured the IP pool we can assign static IP addresses for the specified hosts. For example if we have configured apache web server within the network we can assign the static IP address for that machine. Assume that 192.168.100.200 is our apache web server. We can configure it in the pointed place. Uncomment those lines and add the hostname of the apache web server and MAC address and the IP address for the suitable lines.

In my apache web server I can find the host name and MAC address by typing ifconfig command in the terminal.


After changing the config file you have to restart the DHCP service:

When restarting the service always see the /var/log/syslog for check whether that service is restarted successfully or not.

Test Clients
Turn on the client machine and when it is turning on see the DHCP server’s syslog

By seeing syslog entries we can clearly find how DHCP works.
We can confirm that DHCP server issues the IP address for the client machine by typing ifconfig in the client’s terminal.

Now let’s see our DHCP server issues the static IP address for specified hosts such as apache web server. Turn on the apache web server and see the syslog in DHCP server.

We can see static IP address issued for the specified apache web server.
Troubleshoot an error occured
In everytime when we see our DHCP server’s syslog and our DHCP server offers the IP addresses to the clients there are two entries saying temporary name server faliure as pointed above screenshots.
We can solve this problem easily by editing the /etc/dhcp/dhcpd.conf file. In the dynamically allocating IP addresses section we entered domain name servers as ns1.amaa.com and ns2.amaa.com. Delete those ns1 and ns2 domain name server and add corresponding IP addresses for the ns1.amaa.com and ns2.amaa.com.

Now restart the service: and see the syslog:

dhclient -r
In my client machine it already has the IP address assigned. I want to remove it and request IP address from the DHCP server which we configured.

See the server’s syslog.

When we are using dhclient -r command it actually does the removing of /var/lib/dhcp/dhclient.leases file.

dhclient
Request IP address for the client again

Check server’s syslog. Here we can verify we don’t get that temporary name server faliure error message.
It is true that with these dynamic addressing capabilities, Network Managers save money, time and make their networks more robust and adaptable. DHCP has grown from a tool to simply apply IP addresses to a link-local interface to a multifaceted networking tool, invaluable for maintaining large scale networks. Addresses can be allocated and de-allocated across the whole world, due to Relay Agents and DHCP servers. As network architecture and capabilities change, DHCP has continued to change alongside them, offering Network Administrators more automation in the allocation of addresses, and much more speed in renewing leases to the nodes.
References
http://www.isc.org/software/dhcp http://manpages.ubuntu.com/manpages/xenial/en/man5/dhcpd.conf.5.html
Commentaires