Allocating Static IP Addresses with DHCP

Problem

You want to ensure that your router assigns the same IP address to a particular device every time it connects.

Solution

The following commands ensure that the router assigns the same IP address to a device each time it requests one:

Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router1(config)#ip dhcp pool IAN Router1(dhcp-config)#host 172.25.1.33 255.255.255.0 Router1(dhcp-config)#client-identifier 0100.0103.85e9.87 Router1(dhcp-config)#client-name win2k Router1(dhcp-config)#default-router 172.25.1.1 Router1(dhcp-config)#domain-name oreilly.com Router1(dhcp-config)#dns-server 172.25.1.1 Router1(dhcp-config)#exit Router1(config)#end Router1#

 

Discussion

The router allows you to statically bind an IP address to a MAC address to ensure that a particular device always receives the same IP address. This is particularly useful for devices such as servers that must be available for access via a well-known IP address or DNS entry. Any device that accepts inbound sessions will probably require a static address. Being able to allocate these addresses via DHCP provides network administrator with greater control.

The configuration for a static DHCP mapping is slightly different than a dynamic pool. In particular, you must assign a separate dhcp pool for each static server. In our example, we created a pool named IAN to allocate a static IP address to user Ian. Also, instead of defining a network range of IP addresses, you assign a specific IP address using the host command. To avoid address conflicts, make sure that the static address you assign is not part of a dynamic pool already configured, using the excluded-address command if necessary.

You must configure the static pool with the device's MAC address using the client-identifier command. The client identifier is made up of two parts; the media type and the MAC address. The media type numbers can be found in RFC 3232 (assigned numbers) under the heading "Number Hardware Type." For 10/100/1000 Mb Ethernet, the media type number is 01. The router will combine the media type and MAC address into one large address. The router will automatically add the dots if you don't type them.

From this point on, the router will accept the same options as the dynamic pool options. Options can be inherited from dynamic pools as well. To view the configured static binding, use the show ip dhcp binding command as follows:

Router1#show ip dhcp binding IP address Hardware address Lease expiration Type 172.25.1.33 0100.0103.85e9.87 Infinite Manual 172.25.1.52 0100.50da.2a5e.a2 Apr 11 2006 09:00 PM Automatic 172.25.1.53 0100.0103.ea1b.ed Apr 11 2006 08:58 PM Automatic Router1#

This display shows that we have successfully mapped a static IP address of 172.25.1.33 to MAC address 0001-0385-e987. DHCP has put the code 01 at the start of this address to indicate that it is an Ethernet MAC.

Also, notice that the router marks the static clients as Manual clients to differentiate them. We should mention in passing that although the output indicates that the static lease is indefinite, in reality, it is not. The static dhcp pool can be assigned any lease period you desire, however, the router will only ever allocate the single static address. This can be useful if you want to change other DHCP options for this end device.

See Also

Recipe 20.5

Категории