top of page

DHCP CONFIGURATION IN LINUX UBUNTU -16.04.3-server

  • Writer: Sankalpa H.T.S
    Sankalpa H.T.S
  • Jun 26, 2018
  • 4 min read

Updated: Jun 27, 2018


ree

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


ree

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

ree

The file should look like following:

ree

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


ree

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.

ree

It will show us the gateway address.

ree

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


ree

ree

Let’s confirm our static IP configuration is working.

ree

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.

ree

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.

ree

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.

ree

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

ree

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

ree

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

ree

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.

ree

ree

Try to update the server again.

ree

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

ree

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

ree

Now try to update the server again.

ree

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

ree

It will download as below.

ree

Make sure specified package is installed.

ree

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

Open that file.

ree

File should looks like following.

ree

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

ree

Type the following command in the terminal

ree

Run that command

ree

Configuration


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

ree

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/

ree

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

ree

Check whether it is copied.

ree

Now open the main configuration file to edit.

ree

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

ree

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

ree

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.

ree

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.

ree

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.

ree

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

ree

ree

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

ree

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

ree

Test Clients


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

ree

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.

ree

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.

ree

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.

ree

Now restart the service: and see the syslog:

ree

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.

ree

See the server’s syslog.

ree

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

ree

dhclient


Request IP address for the client again

ree

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

 
 
 

Comments


bottom of page