Install ISC DHCP Server on Ubuntu 16.04.
The Internet Systems Consortium (ISC) Dynamic Host Configuration Protocol (DHCP) server is free, open-source, and easy to install. Both enterprises and small networks have used ISC DHCP in production for many years.
Jason Coltrin
Jason Coltrin has been working in IT for more than 17 years. He holds an MCSE 2003 Security+ plus various Palo Alto and SonicWall firewall certifications. He also is an avid Linux Administrator and currently works in higher education.
Latest posts by Jason Coltrin (see all)
ISC DHCP can issue both IPv4 and IPv6 addresses and support address reservation, boot-p, DDNS, VOIP configurations, and failover. ISC DHCP has been around since 1999 and is available free for download but runs only on BSD, Solaris, and Linux.
I won't go into all of the benefits of different DHCP platforms such as Windows Server, Cisco routers, or firewalls, as choosing a platform usually comes down to personal preference. Most implementations of DHCP provide the same functions, but I've become fond of the way ISC DHCP provides rock-solid service as well as flexibility.
If you have a Cisco router issuing IP addresses to 12 different VLANs, you might want to consider a dedicated DHCP server to free up resources. Another benefit of ISC DHCP is that you won't have to manually set static IP addresses on your servers; you only need to pre-populate the dhcpd.config file with a client's MAC address once. Being proficient with editors such as vim or Nano helps in this regard. Tasks like commenting out old hardware addresses, providing a server a new static address, or managing your IP scopes are a breeze with only an SSH session.
In this guide, I'll demonstrate how to locate your current DHCP server and then install and set up an ISC DHCP server. We'll then move on to gaining control of your new DHCP server, best practices, monitoring the logs, and setting up static address reservations.
Find existing DHCP servers ^
Networks can get large, and sometimes it's not readily apparent which DHCP server is running on your network. Before you install a new DHCP server, you have to make sure that no other DHCP server is running to avoid conflicts.
If you suspect rogue DHCP servers, I recommend reading Michael's instructions, or you can download and run the Microsoft Rogue DHCP Server Detection tool. Either of these tools will also identify the authoritative DHCP server on your network.
On Windows 10, to find your DHCP server, right-click on the Start Button and click Network Connections. Next, right-click on the primary Ethernet adapter and click Status, then the Details button. Here you will find the IPv4 DHCP Server address.
If you want to find the IP address of a DHCP server used for configuring a particular interface on Ubuntu/Linux, there are two ways of doing this:
The easy way is to simply view the DHCP lease information from the following file, where 'ens34' is the adapter's identity:
1 | sudo less /var/lib/dhcp/dhclient.ens34.leases |
You'll have something similar to the following returned:
I like this method because I can see my lease-time, renew, rebind, and expire dates. We can tell that our dhcp-server-identifier is 10.0.10.151.
Another way is to examine the log files in /var/log/ by typing the following:
1 | sudo grep -R "DHCPOFFER" /var/log/* |
Here's what this returns:
Here you may notice that two NICs have received IP addresses (.54 and .55) from 10.0.10.151.
Install and configure ISC DHCP ^
The installation of an ISC DHCP server is pretty straightforward on Ubuntu and can be accomplished with this command:
1 | sudo apt-get install isc-dhcp-server |
Once the service has been installed, we'll first want to tell the server which interface to use for serving requests. Do this by entering the interface's names between quotes at the bottom of the file /etc/default/isc-dhcp-server. For example:
sudo vi /etc/default/isc-dhcp-server INTERFACES="ens33" |
You could also include the wlan0 interface. For example:
Now we need to edit our dhcpd.conf file, but for practice, let's first make a copy of the default file in the same directory with the command cp:
1 | sudo cp dhcp.conf dhcpd.conf.orig |
Now open the config file with your file editor of choice and take a look at the different default settings.
The default dhcpd.config provides comments and examples for all possible functions. However, I've provided a simplified dhcpd.conf file here to add a little clarity about lease times.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | ##### ## /etc/dhcpd/dhcpd.conf ## ISC DHCPD Configuration file # QUICK REFERENCE TIME CHART # # DAYS SECONDS # 1 86400 # 2 172800 # 3 259200 # 4 345600 # 5 432000 # 6 518400 # # {{{ Global Definitions (Common to all networks) # send logs to default /var/log/dhcp/dhcpd.log log-facility local7; #set options option domain-name "jasoncoltrin.com"; option domain-search "jasoncoltrin.com"; option domain-name-servers 10.0.10.107,8.8.8.8; option subnet-mask 255.255.255.0; default-lease-time 345600; max-lease-time 518400; allow bootp; allow booting; # dynamic dns ddns-update-style none; update-static-leases on; ## Primary Subnet and pool subnet 10.0.10.0 netmask 255.255.255.0 { authoritative; option domain-name "jasoncoltrin.com"; option broadcast-address 10.0.10.255; option routers 10.0.10.254; # {{{ Client Pools # Known clients get this pool. pool { # WINS server address and info for microsoft win 3x,9x & NT option netbios-name-servers 10.0.10.107; option netbios-dd-server 10.0.10.107; option netbios-node-type 8; range 10.0.10.50 10.0.10.250; default-lease-time 345600; max-lease-time 518400; allow unknown clients; } } |
In the example dhcpd.conf file, the option log-facility local7; sets the default log file location according to how you define logging in /etc/rsyslog.d/. In my case, I created the file /etc/rsyslog.d/10-dhcpd.conf and added the following line:
1 | local7.* /var/log/dhcp/dhcpd.log |
Now records of all DHCP requests and leases are added to the dhcpd.log. We'll go further into logging later.
The rest of the options should look familiar: we set our global options and then move on to our primary subnet and pool. We can include any number of VLANs or networks in this file, as defined by subnet, each with their own address pools. You can tell that the primary AD domain controller is 10.0.10.107, my pfSense is 10.0.10.254, and the address pool is 10.0.10.50 through 10.0.10.250. We'll go over how to pre-define and set static addresses according to MAC addresses shortly.
Set up reservations with MAC addresses ^
In order to set up a host with a static address, under the subnet section in which you want the device to be defined, just add the following few lines to dhcpd.conf:
host exec-hplj4525 { hardware ethernet 00:KK:HD:66:55:9B; fixed-address 10.0.10.58; } |
Now when the device with the MAC address 00:KK:HD:66:55:9B powers on, because it's set to DHCP, the printer will only be issued the IP address 10.0.10.58. This is a very useful tool when provisioning new equipment, switches, and printers.
In a similar fashion, you can add if statements to the configuration file for hooking VOIP phones or hardware addresses with a particular pattern to your controllers, set additional options, and define VLANs for those devices.
Get status/start/stop/restart ISC DHCP ^
There are four commands I use regularly to control the ISC DHCP server:
sudo service isc-dhcp-server status sudo service isc-dhcp-server restart sudo service isc-dhcp-server start sudo service isc-dhcp-server stop |
The status command provides troubleshooting information in the event you have misconfigured the dhcpd.conf file; otherwise you should see your service is running with output similar to the following:
Monitor server and logs with ccze ^
When adding devices to your network, especially IoT devices, network cameras, or other headless devices, it's nice to see what hits your DHCP server and when. Also, looking at log files in the standard green font can be monotonous. To make things a little easier and more colorful, I like to use my favorite utility, ccze. Ccze is great for colorizing logs, ruby, and Apache as well as of course DHCP logs. Install ccze on Ubuntu with this command:
1 | sudo apt-get install ccze |
Now use the tail -f command to watch the logs as they run with something like the following command:
1 | tail -f /var/log/dhcp/dhcpd.log | ccze |
You can also add the –A flag and pipe the output to other commands such as grep. In the following example, I will get only results where the last four digits of the MAC address, 02:1c:29:3a:85:ca (85:ca), are output to the screen.
Conclusion ^
ISC DHCP server has been around for a long time, and many different enterprises use it because of its flexibility. If you haven't tried DHCP on Linux, you should know that the set up is not that difficult, and you may become inspired to take ISC DHCP server even further than what I have demonstrated here.
Source: www.bing.com
Images credit ed to www.bing.com and img55.it168.com