Saturday, February 22, 2020

DHCP Static Binding on Cisco IOS

Cisco IOS devices can be configured as DHCP servers and it’s also possible to configure a static binding for certain hosts. This might sound easy but there’s a catch to it…in this lesson I’ll show you how to configure this for a Cisco router and Windows 7 and Linux host. This is the topology I’ll be using:
DHCP Binding Demo Topology
The router called “DHCP” will be the DHCP server, R1 and the two computers will be DHCP clients. Everything is connected to a switch and we’ll use the 192.168.1.0 /24 subnet. The idea is to create a DHCP pool and use static bindings for the two computers and R1:
  • R1: 192.168.1.100
  • Windows 7: 192.168.1.110
  • Linux: 192.168.1.120
First we will create a new DHCP pool for the 192.168.1.0 /24 subnet:
DHCP(config)#ip dhcp pool MYPOOL
DHCP(dhcp-config)#network 192.168.1.0 255.255.255.0
Whenever a DHCP client sends a DHCP discover it will send its client identifier or MAC address. We can see this if we enable a debug on the DHCP server:
DHCP#debug ip dhcp server packet

Cisco Router DHCP Client

Now we’ll configure R1 to request an IP address:
R1(config)#interface fastEthernet 0/0
R1(config-if)#no shutdown
R1(config-if)#ip address dhcp
In a few seconds you will see the following message on the DHCP server:
DHCP#
DHCPD: DHCPDISCOVER received from client 0063.6973.636f.2d63.3230.382e.3135.6430.2e30.3030.302d.4661.302f.30 on interface FastEthernet0/0.
When a Cisco router sends a DHCP Discover message it will include a client identifier to uniquely identify the device. We can use this value to configure a static binding, here’s what it looks like:
DHCP(config)#ip dhcp pool R1-STATIC
DHCP(dhcp-config)#host 192.168.1.100 255.255.255.0
DHCP(dhcp-config)#client-identifier 0063.6973.636f.2d63.3230.382e.3135.6430.2e30.3030.302d.4661.302f.30
We create a new pool called “R1-STATIC” with the IP address we want to use for R1 and its client identifier. We’ll renew the IP address on R1 to see what happens:
R1#renew dhcp fastEthernet 0/0
Use the renew dhcp command or do a ‘shut’ and ‘no shut’ on the interface of R1 and you’ll see this on the DHCP server:
DHCP#
DHCPD: Sending DHCPOFFER to client 0063.6973.636f.2d63.3230.332e.3065.3232.2e30.3030.302d.4661.302f.30 (192.168.1.100).
As you can see above the DHCP server uses the client identifier for the static binding and assigns IP address 192.168.1.100 to R1. If you don’t like these long numbers you can also configure R1 to use the MAC address as the client identifier instead:
R1(config)#interface fastEthernet 0/0
R1(config-if)#ip address dhcp client-id fastEthernet 0/0 
This tells the router to use the MAC address of its FastEthernet 0/0 interface as the client identifier, you’ll see this change on the DHCP server:
DHCP#
DHCPRELEASE message received from client 0063.6973.636f.2d63.3230.382e.3135.6430.2e30.3030.302d.4661.302f.30 (192.168.1.100).
DHCPD: Finding a relay for client 0063.6973.636f.2d63.3230.382e.3135.6430.2e30.3030.302d.4661.302f.30 on interface FastEthernet0/0.
DHCPD: DHCPDISCOVER received from client 01c2.0815.d000.00 on interface FastEthernet0/0.
Of course now we have to change the binding on the DHCP server to match the MAC address:
DHCP(config)#ip dhcp pool R1-STATIC
DHCP(dhcp-config)#no client-identifier 0063.6973.636f.2d63.3230.382e.3135.6430.2e30.3030.302d.4661.302f.30
DHCP(dhcp-config)#client-identifier 01c2.0815.d000.00
Do another release on R1:
R1#renew dhcp fastEthernet 0/0
And you’ll see that R1 gets its correct IP address from the DHCP server and is being identified with its MAC address:
DHCP#
DHCPD: DHCPDISCOVER received from client 01c2.0815.d000.00 on interface FastEthernet0/0.
DHCPD: Sending DHCPOFFER to client 01c2.0815.d000.00 (192.168.1.100).
So that’s how the Cisco router requests an IP address. Let’s look at the Windows 7 host now to see if there’s a difference.

Windows 7 DHCP Client

C:UsersWindows7>ipconfig /release C:UsersWindows7>ipconfig /renew
This is what you’ll find on the DHCP server:
DHCP#
DHCPD: DHCPDISCOVER received from client 0100.0c29.7e06.12 on interface FastEthernet0/0.
Windows 7 uses its MAC address as the client identifier. We can verify this by looking at ipconfig:
C:UsersWindows7>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : Windows7
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Network Connection
   Physical Address. . . . . . . . . : 00-0C-29-7E-06-12
That’s easy enough, we’ll create another static binding on the DHCP server so that our Windows 7 computers receives IP address 192.168.1.110:
DHCP(config)#ip dhcp pool WIN7-STATIC
DHCP(dhcp-config)#host 192.168.1.110 255.255.255.0
DHCP(dhcp-config)#client-identifier 0100.0c29.7e06.12
Let’s verify our work:
C:UsersWindows7>ipconfig /release C:UsersWindows7>ipconfig /renew
This is what the debug on the DHCP server will tell us:
DHCP# DHCPD: DHCPRELEASE message received from client 0100.0c29.7e06.12 (192.168.1.3). DHCPD: DHCPDISCOVER received from client 0100.0c29.7e06.12 on interface FastEthernet0/0. DHCPD: Sending DHCPOFFER to client 0100.0c29.7e06.12 (192.168.1.110).
There you go, Windows 7 has received the correct IP address. Last but not least is our Linux computer which acts a little different.

Linux DHCP Client

Linux (Ubuntu) in my example acts a little different when it comes to DHCP client, let me show you:
# sudo dhclient eth0
The DHCP server shows this:
DHCP#
DHCPD: DHCPDISCOVER received from client 000c.29c9.4bb1 on interface FastEthernet0/0.
DHCPD: Sending DHCPOFFER to client 000c.29c9.4bb1 (192.168.1.4).
We see the MAC address of the linux server so we’ll create a static binding that matches this:
DHCP(config)#ip dhcp pool LINUX-STATIC
DHCP(dhcp-config)#host 192.168.1.120 255.255.255.0
DHCP(dhcp-config)#client-identifier 000c.29c9.4bb1
We’ll release the IP address on our Linux host:
# sudo dhclient eth0 -r
# sudo dhclient eth0
Now take a good look at the debug:
DHCP#
DHCPD: DHCPRELEASE message received from client 000c.29c9.4bb1 (192.168.1.4).
DHCPD: DHCPDISCOVER received from client 000c.29c9.4bb1 on interface FastEthernet0/0.
DHCPD: Sending DHCPOFFER to client 000c.29c9.4bb1 (192.168.1.4).
That’s not good, even though we configured the client identifier it’s not working. Let’s double check the MAC address:
DHCP#show ip dhcp binding 
Bindings from all pools not associated with VRF:
IP address          Client-ID/       Lease expiration        Type
      Hardware address/
      User name
192.168.1.4         000c.29c9.4bb1          Mar 02 2002 12:24 AM    Automatic
192.168.1.100       01c2.0815.d000.00       Infinite                Manual
192.168.1.110       0100.0c29.7e06.12       Infinite                Manual
192.168.1.120       000c.29c9.4bb1          Infinite                Manual
The MAC address is correct so that’s not the issue. To explain what is going on here I need to show you some wireshark captures of the DHCP discover messages. First I’ll show you the DHCP discover of R1 and the Windows 7 computer.

DHCP Discover Wireshark Captures

Cisco DHCP Discover Wireshark
Windows 7 DHCP Discover Wireshark
Both have an option called “Client Identifier” in their DHCP discover message. Now look at the Linux computer:
Linux DHCP Discover Wireshark
As you can see there is no option called “Client Identifier” here. It does include the MAC address however. There’s probably a method to tell your Linux host to include an option for the client identifier but if not, we can change the DHCP server to look for the MAC address instead.

Fix Linux DHCP Static Binding

DHCP(config)#ip dhcp pool LINUX-STATIC          
DHCP(dhcp-config)#no client-identifier 000c.29c9.4bb1
DHCP(dhcp-config)#hardware-address 000c.29c9.4bb1
The trick is to remove the client-identifier command and include the MAC address. Let’s see if this works:
# sudo dhclient eth0 -r
# sudo dhclient eth0
This is what you’ll see on the DHCP server:
DHCPD: DHCPRELEASE message received from client 000c.29c9.4bb1 (192.168.1.4).
DHCPD: DHCPDISCOVER received from client 000c.29c9.4bb1 on interface FastEthernet0/0.
DHCPD: Sending DHCPOFFER to client 000c.29c9.4bb1 (192.168.1.120).
There we go, problem solved!
hostname DHCP
!
ip cef
!
ip dhcp pool MYPOOL
 network 192.168.1.0 255.255.255.0
!
ip dhcp pool R1-STATIC
 host 192.168.1.100 255.255.255.0
 client-identifier 01c2.0815.d000.00
!
ip dhcp pool WIN7-STATIC
 host 192.168.1.110 255.255.255.0
 client-identifier 0100.0c29.7e06.12
!
ip dhcp pool LINUX-STATIC
 host 192.168.1.120 255.255.255.0
 hardware-address 000c.29c9.4bb1
!
interface FastEthernet0/0
 ip address 192.168.1.254 255.255.255.0
!
end
hostname R1
!
ip cef
!
interface FastEthernet0/0
 ip address dhcp client-id FastEthernet0/0
!
end

I hope this lesson has helped you to solve any problems with static bindings. If you have any questions just leave a comment.

No comments:

Post a Comment