DHCP 101
DHCP Server
DHCP Pools
On a router, you have to create one or more pools of DHCP addresses available for lease. When a DHCP server receives a DHCP request, it will know what pool to use based on the IP address of interface that received it. If the request came from a host that is not on that subnet, the router will try to match the GIADDR field which contains the IP address of the interface that received the DHCP request on the relay server. To define a pool, use:
Now you can define the pool attributes:
You can exclude some IP’s from being used in the DHCP pool using:
Manual Bindings
To make manual bindings you have to create additional pools, one for each static binding. In these pools you must specify the host IP-Address and an identifier for the host – Client ID or Hardware Address. Clients are matched by the hardware address only if they don’t send a client ID. Cisco routers always send a Client ID!
Defining one POOL for each client can become an administrative nightmare. Another option is to use static mappings from a file similar to the one that the router saves when using the database agent. To enable the use of a static file, use this command in a Network Pool:
ODAP – On Demand Address Pool
A pool can be configure to use one or more subnets from another DHCP or AAA server. This is usually used by providers to assign addresses from the same pool to different customers. To define an ODAP pool, use:
The ODAP server must also be configured to reply with the requested subnets. To do this, configure the server pool with:
DHCP Relay Agent
By default, the list of DHCP bindings is kept in memory by the router and they are lost once the router reloads. You can enable the router to use a database agent, that is a location where the router can save the list of the bindings. This file can also be used to recover the list in case of reloads. To enable this feature, use:
DHCP Classes for Option 82
When a host requests an address via DHCP, the server uses the incoming interface IP or the GIADDR field in the DHCP request (filled by a relay agent with it’s incoming interface IP) that would match the network address defined for a pool. Additionally, it can use the client-id or hardware-address for specific manual bindings. Option 82 is a special field in a DHCP packet that can contain additional information that may identify a host. Switches can be configured to insert information in this field (and in the Relay Information Option field). See DHCP Snooping. To process this information, the DHCP server on a router needs to use DHCP classes. By default, DHCP classes are on, but if disabled, they can be enabled again with:
When you configure a class, you actually define the option fields that the router will compare when it receives a DHCP request. The match is done bitwise.
Then apply the class to an existing DHCP pool. When you do this, the pool will be used for allocation only if at least one class is matched by a DHCP request.
The value of the Option82 field is also added back to the DHCP reply messages that the server sends to its clients.
If the relay agent inserts Option 82 but doesn’t add GIADDR field, the router will drop the DHCP message unless you configure it to trust such messages:
Another option is to disable the insertion of Option82 on the switch:
DHCP Relay Agent
You can forward DHCP requests to another server using the feature of forwarding UDP protocols. For DHCP, the following command should be enough:
The requests will be sent as unicast and the relay agent will add the GIADDR information (IP address of the interface that received the DHCP request) Another option is to make the router forward DHCP requests from within a pool:
When using classes, you can define a relay target for each class:
Option 82
The DHCP relay can be configured to add Option82 information to the DHCP requests that it forwards. You can enable this globally or per interface:
Also by default, the router will also check the reply messages from the server before forwarding them to the host. If they don’t have the Option82 information echoed back in the reply packet, it will be dropped. You can disable this check globally, or per interface:
A Cisco switch can insert Option82 information into a DHCP request. When it receives DHCP requests that already have this information attached, the router will replace it with its own. You can configure how it should treat these packets with any of the following commands:
Again, if the relay agent inserts Option 82 but doesn’t add GIADDR field, the router will drop the DHCP message unless you configure it to trust such messages:
3DHCP Client
Settings for DHCP clients can be configured globally, or on each interface:
Another option is to specify the information when you enable the DHCP client:
A DHCP router will always include a client-id in it’s request. This means that a Cisco DHCP server will not use it’s mac-address when searching for a host pool used for address assignment. You can see what is the value of the client-id sent by the router in it’s DHCP requests with:
If you want to match this value on the DHCP server, you will have to use the hex-value but in a dotted format. So a better option would be to change the client id before sending the request. To see debug information for the client, use:
You can use 2 exec commands to release or renew the DHCP address:
Last updated