Posts Tagged ‘DHCP’

IOS DHCP Server – Part 2 (Advanced Configuration)

Informational | Posted by admin
Apr 14 2010

In Part 1 we covered the basic configuration of the DHCP. Now we’ll delve into some of the more advanced configuration aspects.

Inherited Settings

When a DHCPDISCOVER message is received by the router, Cisco IOS matches it against the list of DHCP pools and returns the DHCP options based on which pools matched the subnet the request came from.
Did you catch that? I said pools… plural… if the pools overlap, it is possible for more than one DHCP pool to match a DHCPDISCOVER message. In this case the options are cascaded down through the matching pools with the more specific pool taking priority. Here’s an example:
ip dhcp pool GLOBAL
 network 192.168.0.0 /22
 dns-server 192.168.1.10 192.168.1.11
ip dhcp pool DATA
 network 192.168.1.0 /24
 default-router 192.168.1.1
ip dhcp pool VOICE
 network 192.168.2.0 /24
 default-router 192.168.2.1
dns-server 192.168.2.10

Assuming we get a DHCPDISCOVER request on the DATA VLAN, the request will be matched against the pools above. As you can see, the 192.168.1.0 network will match both the GLOBAL and the DATA pools. Since none of the options overlap, the DHCPOFFER will contain an IP address on the 192.168.1.0/24 network with 192.168.1.1 as the gateway router and dns servers of 192.168.1.10 and 192.168.1.11.
However if the DHCPDISCOVER request was received on the VOICE VLAN, the result would be different. The DHCPOFFER would still contain an address on the 192.168.2.0/24 network with it’s proper gateway. However, the more specific matched pool (VOICE) would override the DNS server settings in GLOBAL. So the DHCPOFFER would only contain one DNS server (192.168.2.10).

Manual Host Bindings

What if we always want a specific host to get a certain IP address?
We can create a manual binding for that host like this :
ip dhcp pool COMPUTER_NAME
 hardware-address 0012.3456.789A
 host 192.168.1.100 mask 255.255.255.0
 client-name COMPUTER_NAME

If you have a lot of these, it helps to minimize the configuration if you use inheritance as discussed above. The DHCP pool name does not have to match the computer name, I just find it helpful if it does.  Also, the client-name command is not required except where network devices learn their hostname via DHCP.
It should also be noted that Microsoft DHCP clients send a client identifier rather than the MAC address of their network card. The client identifier includes a media identification byte at the beginning of the value. The value for ethernet media is 1. Therefore the above DHCP pool configuration for a Microsoft Windows client would look like this
ip dhcp pool COMPUTER_NAME
 client-identifier 0100.1234.5678.9A
 host 192.168.1.100 mask 255.255.255.0
 client-name COMPUTER_NAME

See how the client-identifier command includes the media type for ethernet (01) followed by the device MAC address?
Both hardware-address and client-identifier can be configured at the same time.

Persistance

What happens when our router dies due to power failure or some other unfortunate event?  We would lose all of our precious DHCP bindings… ok maybe not that big a deal, they are dynamic and all…  But this can cause issues, especially on larger networks.  If there is no binding table, then the DHCP server will take longer as it tries to find an unused IP address.  In a densely populated network, it could take a long time before the server finally found an available IP address.  To cause the DHCP binding table to be stored in a more permanent location we can use the following commands.

ip dhcp database ftp://user:password@192.168.1.10/data-dhcp

This tells the system to store the DHCP binding table on an FTP server at 192.168.1.10 using the username ‘user’ and the password ‘password’. The name of the file will be data-dhcp.
By default, this file will only be updated every 5 minutes.  And will wait for up to 5 minutes for the FTP transaction to complete.  Both of these settings can be adjusted with optional parameters to the ip dhcp database command.

In the above example FTP was used as the transport protocol, but TFTP and RCP are supported as well.

IOS DHCP Server – Part 1 (Basic DHCP)

Informational | Posted by admin
Apr 13 2010

An often overlooked, but very powerful tool in the Cisco IOS, the DHCP service provides a full DHCP implementation on your router. In this 3 part post, I’m going to cover the basics of simple DHCP services as well as advanced configuration.

To get started let’s do a quick review of DHCP functionality.

When a new host connects to the network, the first IP related action it takes (assuming DHCP here folks) is to request an address from the server. It does this by sending an unaddressed broadcast IP packet out to the network (DHCPDISCOVER). The packet still has the system’s MAC address attached to it, so the server knows which device is making the request. In most cases, the server (or servers) see this request and respond with an assigned IP address (DHCPOFFER).
At this point the DHCP client will choose one of the offers that it received and send out another broadcast (DHCPREQUEST) which notifies all DHCP servers that an offer has been accepted. Any offer that was not accepted is invalidated on the server. The server that sent the accepted offer will then send out an aknowledgement to the client (DHCPACK).

All DHCP packets are sent via UDP with a port number of 68 on the client and 67 on the server.

So, how do we setup a simple DHCP server on IOS?

ip dhcp pool MYNETWORK
 network 192.168.1.0 /24

The name of the DHCP pool can be whatever you want, you just need to make sure it’s unique.
And that’s it! Pretty worthless though without a default router or dns…
Let’s add that in
 default-router 192.168.1.1
 dns-server 192.168.1.10 192.168.1.11

At this point we have a fairly usable DHCP scope.
Lets say that we want to reserve the first 10 addresses in the scope for servers, routers, switches, etc.
We can do so like this
ip dhcp excluded-address 192.168.1.1 192.168.1.10
If you only wanted to exclude one address, you would enter the one address in twice like this
ip dhcp excluded-address 192.168.1.10 192.168.1.10
There are a few other commands that should be configured for basic DHCP. First is the domain name.
 domain-name mydomain.com
This command should be entered inside the ip dhcp pool block, so if you left dhcp pool configuration you’ll need to reenter that command.
This assigns a domain name to your clients. Usage of this domain name is application specific. One example would be for DNS queries though. If your software is only given a hostname it may assume that the fully qualified name of the host is host.(dhcp assigned domain)
The other command actually activates the DHCP server, without it the router will not respond to DHCP messages.
service dhcp
Some may argue that this is a default command… Most of the time you’d be correct, but I’ve worked on some devices where this is not the case. So remember to enter this command if for some unknown reason your router doesn’t appear to be accepting DHCP packets.

That about wraps it up for basic DHCP. I’ll be following up with two other posts for Advanced DHCP Settings and DHCP Tuning