DHCP Server in a few steps (CentOS)

Hi there,

This is short post how to create a DHCP server in a few steps for any lab. This is just for Centos 7.

Install your DHCP server

Install dhcpd

yum install -y dhcp

Now, modify dhcpd.conf as follow:

#file: /etc/dhcp/dhcpd.conf
subnet 10.10.10.0 netmask 255.255.255.0 {
  range 10.10.10.200 10.10.10.250;
  option domain-name-servers ns01.nuage.lab;
  option domain-name "nuage40r4.lab";
  option routers 10.10.10.1;
  option broadcast-address 10.10.10.255;
  default-lease-time 600;
  max-lease-time 7200;
}

I strongly suggest you to extend default-lease-time and max-lease-time to more reasonable values. Start your dhcpd

service dhcpd start

Check if everything is ok. You will get an output like this.

Nov  8 09:10:08 ns01 yum[13797]: Installed: 12:dhcp-4.1.1-51.P1.el6.centos.x86_64
Nov  8 09:30:39 ns01 dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
Nov  8 09:30:39 ns01 dhcpd: Copyright 2004-2010 Internet Systems Consortium.
Nov  8 09:30:39 ns01 dhcpd: All rights reserved.
Nov  8 09:30:39 ns01 dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Nov  8 09:30:39 ns01 dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Nov  8 09:30:39 ns01 dhcpd: Wrote 0 leases to leases file.
Nov  8 09:30:39 ns01 dhcpd: Listening on LPF/eth0/52:54:00:45:42:09/10.10.10.0/24
Nov  8 09:30:39 ns01 dhcpd: Sending on   LPF/eth0/52:54:00:45:42:09/10.10.10.0/24
Nov  8 09:30:39 ns01 dhcpd: Sending on   Socket/fallback/fallback-net

That’s all

Test your DHCP server

I tested it using a libvirt domain and connecting its interface to the same bridge of my dhcp server. This is a sample of the XML file:

    <interface type='bridge'>
      <mac address='52:54:00:ae:6c:72'/>
      <source bridge='bridge0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

I started the domain and I got this from the dhcp server’s /var/log/messages file:

Nov  8 10:07:00 ns01 dhcpd: DHCPDISCOVER from 52:54:00:ae:6c:72 via eth0
Nov  8 10:07:01 ns01 dhcpd: DHCPOFFER on 10.10.10.200 to 52:54:00:ae:6c:72 via eth0
Nov  8 10:07:01 ns01 dhcpd: DHCPREQUEST for 10.10.10.200 (10.10.10.2) from 52:54:00:ae:6c:72 via eth0
Nov  8 10:07:01 ns01 dhcpd: DHCPACK on 10.10.10.200 to 52:54:00:ae:6c:72 via eth0
Nov  8 10:07:37 ns01 dhcpd: DHCPREQUEST for 10.10.10.200 from 52:54:00:ae:6c:72 via eth0
Nov  8 10:07:37 ns01 dhcpd: DHCPACK on 10.10.10.200 to 52:54:00:ae:6c:72 via eth0

Also you can check the leases into dhcpd.leases~

[root@ns01 ~]# cat /var/lib/dhcpd/dhcpd.leases~
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1

server-duid "\000\001\000\001\037\264\254\037RT\000EB\011";

lease 10.10.10.200 {
  starts 2 2016/11/08 16:07:01;
  ends 2 2016/11/08 16:17:01;
  cltt 2 2016/11/08 16:07:01;
  binding state active;
  next binding state free;
  hardware ethernet 52:54:00:ae:6c:72;
}
lease 10.10.10.200 {
  starts 2 2016/11/08 16:07:37;
  ends 2 2016/11/08 16:17:37;
  cltt 2 2016/11/08 16:07:37;
  binding state active;
  next binding state free;
  hardware ethernet 52:54:00:ae:6c:72;
}

See ya!

One thought on “DHCP Server in a few steps (CentOS)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s