DHCP Server HowTo

Introduction

Imagine a network topology with a number of devices connected to a router on two different VLANs. To avoid configuring static addresses for all devices on the network, we configure the router to also act as a DHCP server. We also want to inform the devices that the router is the default gateway and DNS server.

In some cases, predetermined roles on the network of certain hosts are preferred. For example, a given port on a switch, or a client which sends a certain hostname should always get a static IP address. For such cases the DHCP server can be configured with Static Host Entires that are individually configured. These entries are configured to be provided to host that meets the matching requirement of the entry, this can be either a Client Id, MAC address or DHCP Option 82 (switch port).

                                 |
                             .--.-.
                            ( (    )__
                            (_,  \ ) ,_)  Internet/Intranet
                             '-'--`--'
                              |
                          .---+----.
                    vlan1 |  DHCP  | vlan2
                    +-----+ Server +-----+
                    |   .1|        |.1   |
                    |     '--------'     |
192.168.1.0/24      |                    |      192.168.2.0/24
----+----------+----+---              ---+----+----------+----
    |          |                              |          |
  .-+--.     .-+--.                         .-+--.     .-+--.
  | H1 |     | H2 |                         | H3 |     | H4 |
  '----'     '----'                         '----'     '----'

Figure 1: Example network with two LANs

Configuration

DHCP Server

The DHCP Server is with two different subnet definitions, each with their own address pool, in order to distribute addresses to both VLANs.

Interface Configuration

VLAN1
Address: 192.168.1.1
VLAN2
Address: 192.168.2.1

DHCP Server Configuration

Subnet 1
  • Pool: 192.168.1.100/24 - 192.168.1.150/24
  • lease time: 1 hour
  • Gateway: 192.168.1.1
  • Name-server: 192.168.1.1
Subnet 2
  • Pool: 192.168.2.100/24 - 192.168.2.150/24
  • lease time: 1 hour
  • Gateway: 192.168.2.1
  • Name-server: 192.168.2.1

Address Pools

Enter the DHCP Server configuration Context:

example:/#> configure
example:/config/#> dhcp-server
example:/config/dhcp-server/#>

Configure the dynamic pool for subnet 192.168.1.0:

example:/config/dhcp-server/#> subnet 192.168.1.0/24
example:/config/dhcp-server/subnet-192.168.1.0/#> pool 192.168.1.100 192.168.1.149
example:/config/dhcp-server/subnet-192.168.1.0/#> lease-time 3600
example:/config/dhcp-server/subnet-192.168.1.0/#> gateway 192.168.1.1
example:/config/dhcp-server/subnet-192.168.1.0/#> name-server 192.168.1.1
example:/config/dhcp-server/subnet-192.168.1.0/#> end
example:/config/dhcp-server/#>

Configure the dynamic pool for subnet 192.168.2.0:

example:/config/dhcp-server/#> subnet 192.168.2.0/24
example:/config/dhcp-server/subnet-192.168.2.0/#> pool 192.168.2.100 192.168.2.149
example:/config/dhcp-server/subnet-192.168.2.0/#> lease-time 3600
example:/config/dhcp-server/subnet-192.168.2.0/#> gateway 192.168.2.1
example:/config/dhcp-server/subnet-192.168.2.0/#> name-server 192.168.2.1
example:/config/dhcp-server/subnet-192.168.2.0/#> end
example:/config/dhcp-server/#> leave
example:/#>

When we enter the configuration for the specific a few different variables are configured:

  • First the pool of available addresses are configured to serve up to 50 hosts on that subnet (.100 - .149).

  • The lease-time is configured so that each address are supplied with a validity of one hour (3600 seconds). When that time has elapsed any host that wants to retain its given address will need to consult the server again to renew it.

  • Both a gateway and name-server are defined to be accessible on the DHCP server it self, since in this case it also serves as the router for the two local networks.

The server is now configured to serve two different subnets, all these addresses will be handled dynamically so no additional actions should be needed.

Static Leases

In this example we want to provide a specific configuration for H3 based on its MAC address. We also want to provide a Specific address on the subnet 192.168.1.0/24 for any host with a specific Client Id.

Enter the DHCP Server configuration Context:

example:/#> configure
example:/config/#> dhcp-server
example:/config/dhcp-server/#>

Configure host 1:

example:/config/dhcp-server/#> host 1
example:/config/dhcp-server/host-1/#> match client string some_clientid_string
example:/config/dhcp-server/host-1/#> address 192.168.1.10
example:/config/dhcp-server/host-1/#> lease-time 10000
example:/config/dhcp-server/host-1/#> gateway 192.168.1.1
example:/config/dhcp-server/host-1/#> end

The host 1 static lease is configured to match on a clientid string. If a host provides the matching Client Id it will be provided with the specific address 192.168.1.10, instead of an address from the dynamic address pool.

Configure host 2:

example:/config/dhcp-server/#> host 2
example:/config/dhcp-server/host-2/#> match mac 0c:50:e5:4f:d6:00
example:/config/dhcp-server/host-2/#> address 192.168.2.20
example:/config/dhcp-server/host-2/#> lease-time 10000
example:/config/dhcp-server/host-2/#> gateway 192.168.2.1
example:/config/dhcp-server/host-2/#> end
example:/config/dhcp-server/#> leave
example:/#>

The host 2 static lease is configured to match on a specifc mac address. Any host associated with the matching MAC will be provided the specific address 192.168.2.20, and not another address from the dynamic pool of addresses.

Status

In order to verify if any DHCP leases are handed out to hosts on the subnet:

example:/#> show dhcp-server
LEASE TIME  MAC ADDRESS       CLIENT ID            IP ADDRESS       HOSTNAME
3600        0c:50:e5:8c:52:00 01:0c:50:e5:8c:52:00 192.168.1.136    H1
10000       0c:50:e5:7c:45:00 01:0c:50:e5:7c:45:00 192.168.1.10     H2
10000       0c:50:e5:4f:d6:00 01:0c:50:e5:4f:d6:00 192.168.2.20     H3
3600        0c:50:e5:33:a6:00 01:0c:50:e5:33:a6:00 192.168.2.121    H4

This shows the specific IP Addresses that have been handed out, and to which host (MAC Address) they have been provided for. This list should show all addresses that the server have provided, therefore this command is useful when debugging address distribution for your network.