Install and Configure DHCP Server On Linux


Normally if you've got a cable electronic equipment or phone line, you get your home PC's science address dynamically allotted from your service supplier. If you put in a home cable/DSL router between your electronic equipment and residential network, your computer can presumably get its science address at boot time from the house router instead. you'll like better to disable the DHCP server feature on your home router and created a Linux box because the DHCP server.

This chapter covers solely the configuration of a DHCP server that has science addresses. The configuration of a Linux DHCP shopper that gets its science address from a DHCP server is roofed in "Linux Networking", on Linux Networking.

Download and Install the DHCP Package
Most RedHat and lid Linux wares packages ar offered within the revolutions per minute format, whereas Debian and Ubuntu Linux use woman format installation files. once sorting out these packages, keep in mind that the name typically starts with the software system package name and is followed by a version variety, as in dhcp-3.23.58-4.i386.rpm. (For assistance on downloading and putting in the package.)

Managing the DHCP Server
Managing the DHCP daemon is simple to try and do, however the procedure differs between Linux distributions. Here ar some things to stay in mind.

    Firstly, totally {different|completely different} Linux distributions use different daemon management systems. every system has its own set of commands to try and do similar operations. the foremost unremarkably used daemon management systems ar SysV and Systemd.
    Secondly, the daemon name has to be renowned. during this case the name of the daemon is dhcpd.

Armed with this data you'll acumen to:

 begin your daemons mechanically on booting Stop, begin and restart them afterward throughout troubleshooting or once a configuration file modification has to be applied.

For additional details on this, please take a glance at the "Managing Daemons" section of "Installing Linux Software"

Note: If you modify your daemon configuration file keep in mind that the changes will not get until you restart the daemon.

Note: keep in mind to tack together your daemon to start out mechanically upon your next resuscitate.

dhcpd.conf File
You can outline your server configuration parameters within the dhcpd.conf file which can be situated within the /etc the /etc/dhcpd or /etc/dhcp3 directories counting on your version of Linux.

Note: The skeleton dhcp.conf file that's created after you install the package could vary in its completeness. In Ubuntu / Debian, the skeleton dhcpd.conf file is intensive with most of the commands deactivated with a # sign at the start. In lid / RedHat / CentOS an intensive sample is additionally created with activated commands. it's found within the following location that you'll continuously use as a guide.


Note: The dhcpd.conf configuration file formats in Debian / Ubuntu and Redhat / lid ar identical.

Here may be a fast clarification of the dhcpd.conf file: most significantly, there should be a subnet section for every interface on your Linux box.

ddns-update-style interim
ignore client-updates

subnet netmask vary of science addresses the server
   # can issue to DHCP enabled computer shoppers
   # booting abreast of the network


   # Set the quantity of your time in seconds that
   # a shopper could keep the science address

  default-lease-time 86400;
  max-lease-time 86400;

   # Set the default entrance to be employed by
   # the computer shoppers

 choice routers;
   # do not forward DHCP requests from this
   # NIC interface to the other NIC
   # interfaces

 choice ip-forwarding off;

   # Set the published address and subnet mask
   # to be employed by the DHCP shoppers

 choice broadcast-address;
 choice subnet-mask;
   # Set the NTP server to be employed by the
   # DHCP shoppers

 choice ntp-servers;

   # Set the DNS server to be employed by the
   # DHCP shoppers

 choice domain-name-servers;

   # If you specify a WINS server for your Windows shoppers,
   # you wish to incorporate the subsequent choice within the dhcpd.conf file:

 choice netbios-name-servers;

   # you'll conjointly assign specific science addresses supported the clients'
   # LAN waterproof address as follows (Host's name is "laser-printer":

  host laser-printer {
      hardware LAN 08:00:2b:4c:59:23;
# List associate unused interface here
subnet netmask }

There ar more choices statements you'll use to tack together DHCP. These embody telling the DHCP shoppers wherever to travel for services like finger and IRC. Check the dhcp-options man page when you are doing your install:

[root@bigboy tmp]# man dhcp-options

Note: The host statement seen within the sample dhcpd.conf file may be terribly helpful. Some devices like network printers default to obtaining their science addresses victimization DHCP, however users have to be compelled to access them by a set science address to print their documents. This statement may be accustomed continuously give specific science address to DHCP queries from a predefined a NIC waterproof address. this will facilitate to cut back systems administration overhead.

DHCP Servers with Multiple NICs
DHCP servers with multiple interfaces create 2 configuration challenges. the primary is putting in place the proper routing and also the second is ensuring solely the specified interfaces ar paying attention to serve DHCP. Don’t worry, each are going to be mentioned next.

When a DHCP designed computer boots, it requests its science address from the DHCP server. It will this by causation a uniform DHCP broadcast request packet to the DHCP server with a supply science address of

If your DHCP server has over one interface, you've got to feature a route for this address so it is aware of the interface on that to send the reply; if not, it sends it to the default entrance. (In each of consecutive 2 examples, we have a tendency to assume that DHCP requests are going to be returning in on interface eth0).

Note: additional data on adding Linux routes and routing could also be found in "Linux Networking".

Note: you cannot run your DHCP sever on multiple interfaces as a result of you'll solely have one route to network If you are trying to try and do it, you will discover that DHCP serving functioning on only 1 interface.

Temporary resolution
You can briefly add a route to victimization the route add command as seen below.

[root@bigboy tmp]# route add -host dev eth0

If you would like this routing state to be maintained when a resuscitate, then use the permanent resolution that is mentioned next.

Permanent resolution
Create a permanent route to this may vary in keeping with your version of Linux

Fedora / RedHat / CentOS: Add the route to your /etc/sysconfig/network-scripts/route-eth0 file if the route has to be added  to your eth0 interface.

# File /etc/sysconfig/network-scripts/route-eth0
# dev eth0

Ubuntu / Debian: Add the route to your /etc/network/interfaces file. during this case the route is added  to the eth0 interface.

# File: /etc/network/interfaces
iface eth0 inet static

      up route add -host eth0

Simple Linux routing is roofed in "Linux Networking" and can add additional clarity to adding permanent static routes.

Once you've got outlined the interface for your DHCP routing you ought to conjointly make sure that your DHCP server solely listens thereon interface and no others. this technique to try and do this varies counting on your versiĆ³n of Linux.

Fedora / RedHat / CentOS: The /etc/sysconfig/dhcpd file should be emended and also the DHCPDARGS variable emended to incorporate the well-liked interface. during this example interface eth0 is most popular.

# File: /etc/sysconfig/dhcpd

Debian / Ubuntu: The /etc/default/dhcp3-server file should be emended and also the INTERFACES variable emended to incorporate the well-liked interface. during this example interface eth0 is most popular.

# File: /etc/default/dhcp3-server

You will be ready to verify success in one in every of 2 ways in which. initial the netstat command victimization the –au choices can offer the list of interfaces listening on the bootp (DHCP) UDP port.

[root@bigboy-f ~]# netstat -au  | grep bootp
udp zero zero    *:*
[root@bigboy-f ~]#

Secondly, your /var/log/messages file also will reveal the outlined interfaces used once the DHCPd daemon was restarted.

Jan eight 17:22:44 bigboy dhcpd: Listening on LPF/eth0/00:e0:18:5c:d8:41/
Jan eight 17:22:44 bigboy dhcpd: causation on   LPF/eth0/00:e0:18:5c:d8:41/

Success! you'll return to lunch!
Configuring Linux shoppers to Use DHCP

A Linux NIC interface may be designed to get its science address victimization DHCP with the examples printed in , " Linux Networking". Please visit this chapter if you wish a fast refresher on the way to tack together a Linux DHCP shopper.
Configuring Windows shoppers to Use DHCP

Fortunately Windows defaults to victimization DHCP for all its NIC cards therefore you do not ought to worry regarding doing any reconfiguration.
Using a Single DHCP Server to Serve Multiple Networks

As explicit  before, DHCP shoppers send their requests for science addresses to a broadcast address that is proscribed to the native LAN. this may imply that a DHCP server is needed on every subnet. Not so. it's attainable to tack together routers to forward DHCP requests to a DHCP server several hops away. this is often done by inserting the science address of the router's interface on the DHCP client's network into the forwarded packet. To the DHCP server, the non-blank router science address field takes precedence over the published address and it uses this price to produce a DHCP address that's purposeful to the shopper. The DHCP server replies with a broadcast packet, and also the router, that has unbroken track of the initial forwarded request, forwards it back towards the shopper. you'll tack together this feature on Cisco devices by victimization the science helper-address command on all the interfaces on that DHCP shoppers reside. Here may be a configuration sample that points to a DHCP server with the science address

interface FastEthernet 2/1
 science address
 science helper-address

Simple DHCP Troubleshooting

The most common issues with DHCP typically are not associated with the server; when the server is designed properly there's no have to be compelled to modification any settings and it thus runs faithfully. the issues typically occur at the DHCP client's finish for a spread of reasons. the subsequent sections gift straightforward troubleshooting steps that you simply will undergo to make sure that DHCP is functioning properly on your network.

DHCP shoppers getting Addresses

Whenever Microsoft DHCP shoppers ar unable to contact their DHCP server they default to choosing their own science address from the network till the DHCP server becomes offered once more. this is often ofttimes brought up as Automatic personal science Addressing (APIPA). Here ar some steps you'll undergo to resolve the problem:

 certain that} your DHCP server is designed properly and use the pgrep command mentioned earlier to form sure the DHCP method is running. Pay special attention to your route, particularly if your DHCP server has multiple interfaces.
 offer your DHCP shopper a static science address from an equivalent vary that the DHCP server is meant to produce. See whether or not you'll ping the DHCP server. If you can't, ensure your cabling and your NIC cards.
    DHCP uses the BOOTP protocol for its communication between the shopper and server. certify there aren't any firewalls interference this traffic. DHCP servers expect requests on UDP port sixty seven and also the DHCP shoppers expect responses on UDP port sixty eight. Use tcpdump on the server's NIC to verify the proper traffic flows.

Other DHCP Failures

If the DHCP server fails to start out then use your regular troubleshooting techniques printed in "Simple Network Troubleshooting", to assist rectify your issues. Most issues with associate initial setup ar typically due to:

    Incorrect settings within the /etc/dhcpd.conf file like not process the networks that the DHCP server is responsible;
    Firewall rules that block the DHCP bootp protocol on UDP ports sixty seven and 68;
    Routers failing to forward the bootp packets to the DHCP server once the shoppers reside on a separate network.

Always check your /var/logs/messages file for dhcpd errors and keep in mind that necessary keywords in your configuration file could modification after you upgrade your software package. continuously scan the discharge notes to take care.

In most home-based networks, a DHCP server is not necessary as a result of the phone line router / firewall typically has DHCP capabilities, however it's a stimulating project to do. simply keep in mind to form positive that the vary of science addresses issued by all DHCP servers on a network does not overlap as a result of it may probably cause surprising errors. you would possibly wish to disable the router/firewall's DHCP server capabilities to experiment along with your new Linux server.

A DHCP server could also be priceless in associate workplace surroundings wherever the time and price of obtaining a network engineer to urge the work done could create it less complicated for Linux systems directors to try and do it by themselves.

Creating a Linux DHCP server is simple and touches all the foremost themes within the previous chapters. currently it is time to do one thing more durable, however before we have a tendency to do, we'll do a fast refresher on the way to produce the Linux users who'll be victimization several of the applications printed within the remainder of the book.