Wednesday, July 28, 2010

DHCP Server Configuration

Dynamic Host Configuration Protocol (DHCP) automatically assigns IP addresses and other network configuration information (subnetmask, broadcast address, etc) to computers on a network. A client configured forDHCP will send out a broadcast request to the DHCP server requesting an address. The DHCP server will then issue a "lease" and assign it to that client. The time period of a valid lease can be specified on the server.DHCP reduces the ammount of time required to configure clients and allows one to move a computer to various networks and be configured with the appropriate IP address, gateway and subnet mask. For ISP's it conserves the limited number of IP addresses it may use. DHCP servers may assign a "static" IP address to specified hardware. Microsoft NetBios information is often included in the network information sent by the DHCPserver.
DHCP assignment:
  1. Lease Request: Client broadcasts request to DHCP server with a source address of and a destination address of The request includes the MAC address which is used to direct the reply.
  2. IP lease offer: DHCP server replies with an IP address, subnet mask, network gateway, name of the domain, name servers, duration of the lease and the IP address of the DHCP server.
  3. Lease Selection: Client recieves offer and broadcasts to al DHCPservers that will accept given offer so that other DHCP server need not make an offer.
  4. The DHCP server then sends an ack to the client. The client is configured to use TCP/IP.
  5. Lease Renewal: When half of the lease time has expired, the client will issue a new request to the DHCP server.
Starting DHCP server: service dhcpd start
(or /etc/rc.d/init.d/dhcpd start for Red Hat, Fedora and CentOS Linux distributions)
Sample DHCP server config file: (DHCP v3.0.1) /etc/dhcpd.conf
(See /usr/share/doc/dhcp-3.X/dhcp.conf.sample)
ddns-update-style interim;                                   # Required for dhcp 3.0+ / Red Hat 8.0+
   ignore client-updates;
   subnet netmask {
   range;                   # Range of IP addresses to be issued to DHCP clients
   option subnet-mask    ;    # Default subnet mask to be used by DHCP clients
   option broadcast-address;    # Default broadcastaddress to be used by DHCP clients
   option routers        ;      # Default gateway to be used by DHCP clients
   option domain-name              "";
   option domain-name-servers,;           # Default DNS to be used by DHCP clients
   option netbios-name-servers;    # Specify a WINS server for MS/Windows clients. 
   # (Optional. Specify if used on your network)
   #         DHCP requests are not forwarded. Applies when there is more than one ethernet device and forwarding is configured.
   #       option ipforwarding off;
   default-lease-time 21600;                            # Amount of time in seconds that a client may keep the IP address
   max-lease-time 43200;
   option time-offset              -18000;              # Eastern Standard Time
   #       option ntp-servers    ;         # Default NTP server to be used by DHCP clients
   #       option netbios-name-servers;
   # --- Selects point-to-point node (default is hybrid). Don't change this unless you understand Netbios very well
   #       option netbios-node-type 2;
   # We want the nameserver "ns2" to appear at a fixed address.
   # Name server with this specified MAC address will recieve this IP.
   host ns2 {
   hardware ethernet 00:02:c3:d0:e5:83;
   # Laser printer obtains IP address via DHCP. This assures that the
   # printer with this MAC address will get this IP address every time.
   host laser-printer-lex1 {
   hardware ethernet 08:00:2b:4c:a3:82;
Test configuration file for errors with the following command: /etc/rc.d/init.d/dhcpd configtest (Other distributions may use: /usr/sbin/dhcpd -f)
Note: The MAC addresses for the static address name server (,
can be obtained with the command /sbin/ifconfig:
eth0      Link encap:Ethernet  HWaddr 00:02:C3:D0:E5:83
   inet addr:  Bcast:  Mask:
   inet6 addr: fe80::202:b3ff:fef0:e484/64 Scope:Link
   RX packets:4070 errors:0 dropped:0 overruns:0 frame:0
   TX packets:3878 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:1000
   RX bytes:3406445 (3.2 MiB)  TX bytes:439612 (429.3 KiB)
When dhcpd is running it will generate entries in the file: /var/lib/dhcp/dhcpd.leases
lease {
   starts 2 2004/12/01 20:07:05;
   ends 3 2004/12/02 08:07:05;
   hardware ethernet 00:00:e8:4a:2c:5c;
   uid 01:00:00:e8:4c:5d:31;
   client-hostname "Node1";
LANs separated by routers: In order to have your DHCP broadcast pass through a router on the the next network, one must configure the router to allow DHCP relay. (Cisco: ip-helper address, Juniper: dhcp-relay) The local lan subnet{ } configuration must come before the configuration directives of the remote LANs.