www.howtonetwork.org

CCNA & CCNP Certifcation Training

  • About
  • Contact
  • FAQ
  • Join
  • Home
  • CCNA
    • ICND1
    • ICND2
    • 101 CCNA LABS
  • CCNP
    • ROUTE
    • SWITCH
    • TSHOOT
    • 101 CCNP LABS
  • CompTIA
    • Security+
    • Network+
  • Design
    • CCDA
    • CCDP
You are here: Home / TSHOOT / Module 9 / Understanding DHCP

Understanding DHCP

As previously stated, the Dynamic Host Configuration Protocol (DHCP) is used to dynamically assign hosts with IP addressing information, which includes IP address, subnet mask, default gateway, and additional optional parameters such as Domain Name Service (DNS) servers, Windows Internet Name Service (WINS) servers, and Network Time Protocol (NTP) server information. DHCP uses UDP port 68. Cisco IOS routers and some switches can be configured as both DHCP clients and DHCP servers.

Client States and Message Exchanges

DHCP is a client / server protocol wherein the server provides the client dynamic addressing information. The server can be a standalone server or a Cisco IOS router or switch that can provide DHCP server functionality. While clients are typically network hosts, such as workstations, Cisco IOS routers and switches can also be configured as DHCP clients, allowing them to dynamically receive addressing information from the DHCP server.

DHCP clients transition through a series of states upon initialization. During these phases, the clients and servers exchange different messages. Clients transition through the following states:

  1. Initializing
  2. Selecting
  3. Requesting
  4. Bound
  5. Renewing
  6. Rebinding

When a client first boots up, it is in the initializing state. In this state, the client sends out the DHCPDISCOVER message UDP port 67 (BOOTP server) to the Broadcast address FFFF:FFFF:FFFF (Layer 2) / 255.255.255.255 (Layer 3). Because at this point the client has no IP address, the source IP address of this broadcast will be 0.0.0.0.

If a DHCP server exists on the local subnet and is configured and operating correctly, the DHCP server will hear the Broadcast and respond with a DHCPOFFER message using UDP port 68 (BOOTP client). However, if no DHCP server resides on the local subnet, then a DHCP or BOOTP Relay is required to forward the DHCPDISCOVER message to a remote DHCP server. If this functionality is not enabled, the client will not be able to communicate with the server.

After the client receives the DHCPOFFER message the DHCP server, the client then transitions into the selecting state. In the event that multiple DHCP servers have responded with DHCPOFFER messages, the client effectively selects which DHCPOFFER to accept during this state. Most commonly, the client will accept the message from the first server to respond.
This DHCPOFFER message contains the initial configuration information for the DHCP client. This information includes parameters such as the IP address, subnet mask, default gateway, and other additional parameters such as lease duration, renewal time, domain name, DNS server, and WINS server information, for example. The server will send the DHCPOFFER to the broadcast address, but will include the hardware address of the client in the offer, so the client knows that it is the intended destination. In the event that the DHCP server is not on the local subnet, the DHCP server will send the DHCPOFFER as a Unicast packet, on UDP port 67, back to the DHCP or BOOTP Relay Agent from which the DHCPDISCOVER came. The DHCP or BOOTP Relay Agent will then either Broadcast or Unicast the DHCPOFFER on the local subnet on UDP port 68, depending on the Broadcast flag set by the client.

After receiving the DHCPOFFER, the client moves into the requesting state. In this state, the client responds to the selected DHCP server (typically the first one it heard from) with a DHCPREQUEST message, which indicates that it is willing to accept the parameters in the DHCPOFFER message. The client does not respond to the other DHCPOFFER messages; instead, the DHCP client simply ignores them, implicitly declining the information received from those servers.

The client identifies the selected server by populating the Server Identifier option field with the DHCP server’s IP address. The DHCPREQUEST is also a Broadcast, so all DHCP servers that sent a DHCPOFFER will see the DHCPREQUEST, and each will know whether its DHCPOFFER was accepted or declined. Any additional configuration options that the client requires will be included in the options field of the DHCPREQUEST message. Even though the client has been offered an IP address, it will send the DHCPREQUEST message with a source IP address of 0.0.0.0 because it has not yet received verification that it is clear to use the address.

When the DHCP server receives the DHCPREQUEST from the client, it acknowledges it by sending the client a DHCPACK. When the client receives this message from the server, it transitions to the bound state. The DHCPACK message has a source IP address of the DHCP server, and the destination address is a Broadcast. This message contains all the parameters that the client requested in the DHCPREQUEST message. Before the DHCP client begins using the new address, the DHCP client must calculate the time parameters associated with a leased address, which are Lease Time (LT), Renewal Time (T1), and Rebind Time (T2).

The DHCPACK tells the client that it is free to use the provided address to access the network. After this message has been sent, the DHCP server then stores the lease in the database and uniquely identifies it using the client identifier and the associated IP address. Both the client and server will use this combination of identifiers to refer to the lease. The client identifier is the MAC address of the device plus the media type. The sequence of messages exchanged between server and client during this phase is illustrated in Figure 9-1:

img1 (4)

Fig. 9-1. DHCP Client and Server Message Exchanges

After getting a lease from the DHCP server, the client must renew that lease when one half of the lease time has expired. To do so, the client transitions to the renewing state and sends a DHCPREQUEST message to the server which holds the current lease. Upon receiving this message, the server responds to the client with a DHCPACK message that contains the new lease and any other new configuration parameters that may have been made since the previous lease. For example, this might include an updated DNS server IP address.

If the client is unable to reach the server holding the lease, it will attempt to renew the address from any DHCP server if the original DHCP server has not responded to the renewal requests within a specified interval.

A client transitions into the rebinding state if, after it has been allocated addressing information, it is restarted. In this state, the client will specifically request the previously leased IP address using a DHCPREQUEST packet. This DHCPREQUEST will still have the source IP address as 0.0.0.0 and the destination Broadcast address 255.255.255.255. If the DHCP server determines that the client can still use the requested IP address, it will either remain silent or send a DHCPACK for the DHCPREQUEST. If the server determines that the client cannot use the requested IP address, it will send a DHCPNACK back to the client. The client will then move to the Initializing state, and send a DHCPDISCOVER message. The entire process starts again.

NOTE: The DHCPNACK is described in the following section.

Additional DHCP Exchanges

In addition to the messages described in the previous section, there are some other additional DHCP messages that can be sent by the client or server. These messages include the following:

  1. DHCPNAK or DHCPNACK
  2. DHCPDECLINE
  3. DHCPINFORM
  4. DHCPRELEASE

The DHCPNAK or DHCPNACK message is sent by the DHCP server if it is unable to satisfy the client DHCPREQUEST message. When the client receives a DHCPNAK message, or does not receive a response to a DHCPREQUEST message, the client restarts the configuration process by going into the Requesting state. The client will retransmit the DHCPREQUEST at least four times within sixty (60) seconds before restarting the initializing state.

The DHCPDECLINE message is sent when the client discovers that the IP address provided by the server in the DHCPACK message is already in use. The client verifies the availability of the address by sending out ARP requests for the IP address specified in the DHCPACK. If already in use, the client sends the server a DHCPDECLINE message and restarts the configuration process by transitioning into the requesting state. This is typically a rare message as the DHCP server will typically send out ping packets to ensure that the address provided is available.

The DHCPINFORM message is sent by a client to request additional configuration parameters. This may be the case when the client has a manually configured IP address but requires additional information from the DHCP server such as DNS server information, for example. When a DHCP sever receives a DHCPINFORM message, it responds to the client with a DHCPACK message that contains the requested configuration parameters without allocating the client a new IP address. This message is Unicast to the requesting client.

And finally, the DHCPRELEASE message is sent by the client when it wishes to release or give up its IP address. This action is typically manually performed by an administrator. As an example, a Windows-based client will send this message after the ipconfig /release command is executed on the command prompt. The client identifies the lease to be released by the use of the client identifier field and network address in the DHCPRELEASE message.

Understanding the DHCP / BOOTP Relay Agent

As was previously stated, Cisco IOS software routers and switches may be configured as DHCP servers and clients. In addition to this, Cisco IOS software also supports DHCP or BOOTP relay functionality. As we already know, DHCP uses Broadcast messages. This works well when client and server reside within the same Broadcast domain; however, it does present a challenge when the DHCP server is located in a remote subnet. This is because, by default, routers will not forward Broadcast packets. This essentially means that if a router resides between the client and the server, the DHCP messages will never be exchanged between the two.

In order to allow clients to communicate with servers on remote subnets, the DHCP or BOOTP relay agent function must be enabled on the router. When enabled, the relay agent will the forward request on behalf of the client to the server, using its own IP address as the source of those requests. This allows the server to allocate an IP address on the same subnet as the messages received from the relay agent. The DHCP server Unicasts responses to the relay agent.

Configuring A Cisco IOS Router or Switch as a DHCP Client

Cisco IOS DHCP client configuration functionality requires the implementation of only a single command, which is the ip address dhcp interface configuration command. This command is required on the interface that will be receiving configuration information from the DHCP server. The following example shows how you would configure the router as a DHCP client:

Router(config)#interface fastethernet 0/0
Router(config-if)#description “Connected To ISP XYZ Cable Modem”
Router(config-if)#ip address dhcp
Router(config-if)#end

Assuming that the router is able to communicate with the DHCP server, when the DHCP server provides the router with the addressing parameters, you will see a message that is similar to the following printed on the console:

*Oct 20 02:02:10.592 CST: %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 150.1.1.1, mask 255.255.255.0, hostname R1

You can validate whether or not the device has been configured as a DHCP client using either theshow dhcp server or show dhcp lease commands. The show dhcp server command provides information on DHCP message statistics, such as the number of offers or acknowledgements received for example. It also provides basic addressing parameters such as DNS server addresses, the domain name and subnet mask assigned by the server. Below is a sample output of the information printed by this command:

R1#show dhcp server
DHCP server: ANY (255.255.255.255)
Leases:   1
Offers:   1      Requests: 1     Acks : 1     Naks: 0
Declines: 0      Releases: 0     Query: 0     Bad: 0
DNS0:   172.16.1.253,   DNS1:  172.16.1.254
NBNS0:  172.16.1.254,   NBNS1: 0.0.0.0
Subnet: 255.255.255.0   DNS Domain: howtonetwork.net

The show dhcp lease command provides additional configuration details, which include the assigned IP address, subnet mask, default gateway and lease duration, amongst other things. Following is a sample output of the information that is printed by this command:

R1#show dhcp lease
Temp IP addr: 150.1.1.1  for peer on Interface: FastEthernet0/0
Temp  sub net mask: 255.255.255.0
DHCP Lease server: 150.1.1.2, state: 3 Bound
DHCP transaction id: 191F
Lease: 691200 secs,  Renewal: 345600 secs,  Rebind: 604800 secs
Temp default-gateway addr: 150.1.1.254
Next timer fires after: 3d23h
Retry count: 0   Client-ID: cisco-000c.cea7.f3a0-Fa0/0
Client-ID hex dump: 636973636F2D303030632E636561372E
663361302D4661302F30
Hostname: R1

NOTE: You can also use the show ip interface <name> command to determine if the interface has derived its IP address from a DHCP server as illustrated in the output below:

R1#show ip interface fastethernet 0/0
FastEthernet0/0 is up, line protocol is up
Internet address is 150.1.1.1/24
  Broadcast address is 255.255.255.255
  Address determined by DHCP
MTU is 1500 bytes
Helper address is not set
Directed broadcast forwarding is disabled
Outgoing access list is not set
Inbound  access list is not set
Proxy ARP is enabled
Local Proxy ARP is disabled[Truncated Output]

Configuring A Cisco IOS Router or Switch as a DHCP Server

While quite straightforward, the configuration of the Cisco IOS DHCP server function requires more steps than when configuring a router or switch as a DHCP client. The following sequence of steps is required when configuring a router or switch as a Cisco IOS DHCP server:

  1. Exclude the IP addresses that you do not want the Cisco IOS DHCP server to assign to clients using the ip dhcp excluded-address <starting address> <ending address>global configuration command. By default, Cisco IOS DHCP server functionality assumes that all IP addresses specified in the pool are available for assigning and will begin assigning addresses from the bottom IP address to the top IP address, e.g. from .1 to .254. This order cannot be changed

NOTE: By default the Cisco IOS DHCP server will ping a pool IP address twice before it will assign it to a client. If the ping is unanswered, the DHCP server will assign the address to a client because it assumes that it is available. However, while this does minimize the probability of duplicate addresses being assigned to the client, keep in mind that some devices, e.g. servers, residing on the subnet may have a firewall running which blocks ping packets. Therefore, it is quite possible that a client could be assigned an address already manually assigned to another such device because the Cisco IOS DHCP server did not receive a response from the device. It is therefore recommended that all statically assigned addresses are excluded from the pool

  1. Configure the DHCP pool using the ip dhcp pool <name> global configuration command. Each individual DHCP pool must have a unique name. The device then transitions to DHCP pool configuration mode
  2. In DHCP pool configuration mode, next configure the network number and mask of the DHCP address pool using the network <network> <mask> or network <network> /<prefix-length> DHCP pool configuration command. Both options are acceptable and both perform the same function
  3. In DHCP pool configuration mode, specify the IP address of the default gateway using thedefault-router <address 1…address 8> DHCP pool configuration command. You can specify up to eight different addresses in a single configuration line

Following this core configuration, you can configuration additional parameters such as DNS servers, WINS servers, domain name, and lease duration, for example. In DHCP pool configuration mode, you can specify DNS servers for the pool using the dns-server <address 1…address 8> DHCP pool configuration command. You can specify up to eight different addresses in a single configuration line.  The WINS server information can be specified by issuing the netbios-name-server <address 1…address 8> DHCP pool configuration command. Again, you can specify up to eight different addresses in a single configuration line. The domain name for the client can be specified using the domain-name <name> DHCP pool configuration command. And finally, you can change the default one day lease duration used by Cisco IOS DHCP server via the lease <days [hours][minutes]|infinite> DHCP pool configuration command. If the infinite keyword is specified, the lease for that pool will never expire.

The following configuration example illustrates how to configure two DHCP pools on the same router. The configuration parameters for the first pool are illustrated below:

Excluded Address(es) 10.1.1.1 – 10.1.1.9
Pool Name POOL-A
Subnet / Mask 10.1.1.0/24
Gateway(s) 10.1.1.1
DNS Server(s) 172.16.1.252, 172.16.1.253, 172.16.1.254
WINS Server(s) 172.16.1.253, 172.16.1.254
Lease 8 days

The configuration parameters for the second pool are illustrated below:

Excluded Address(es) 10.2.2.1
Pool Name POOL-B
Subnet / Mask 10.2.2.0/29
Gateway(s) 10.2.2.1
DNS Server(s) 172.16.1.254
WINS Server(s) N/A
Lease 8 hours

The configuration for these two pools is implemented on the router as follows:

R1(config)#ip dhcp excluded-address 10.1.1.1 10.1.1.9
R1(config)#ip dhcp excluded-address 10.2.2.1
R1(config)#ip dhcp pool POOL-A
R1(dhcp-config)#network 10.1.1.0 /24
R1(dhcp-config)#default-router 10.1.1.1
R1(dhcp-config)#dns-server 172.16.1.252 172.16.1.253 172.16.1.254
R1(dhcp-config)#netbios-name-server 172.16.1.253 172.16.1.254
R1(dhcp-config)#lease 8 0 0
R1(dhcp-config)#exit
R1(config)#ip dhcp pool POOL-B
R1(dhcp-config)#network 10.2.2.0 255.255.255.248
R1(dhcp-config)#default-router 10.2.2.1
R1(dhcp-config)#dns-server 172.16.1.254
R1(dhcp-config)#lease 0 8 0
R1(dhcp-config)#exit

Following this configuration, you can also use the show ip dhcp pool command to view the configured DHCP pool parameters as well as pool address allocation as follows:

R1#show ip dhcp poolPool POOL-A :
Utilization mark (high/low)    : 100 / 0
Subnet size (first/next)       : 0 / 0
Total addresses                : 254
Leased addresses               : 2
Pending event                  : none
1 subnet is currently in the pool :
Current index        IP address range                    Leased addresses
10.1.1.1             10.1.1.1         – 10.1.1.254        2Pool POOL-B :
Utilization mark (high/low)    : 100 / 0
Subnet size (first/next)       : 0 / 0
Total addresses                : 6
Leased addresses               : 0
Pending event                  : none
1 subnet is currently in the pool :
Current index        IP address range                    Leased addresses
10.2.2.1             10.2.2.1         – 10.2.2.6          0

Additionally, you can use the show ip dhcp binding command to view the DHCP binding database on the local device. This command prints information which includes the DHCP client IP and hardware (MAC) addresses, as well as the lease expiration time and date as illustrated in the following output:

R1#show ip dhcp binding
Bindings from all pools not associated with VRF:
IP address          Client-ID/              Lease expiration        Type
Hardware address/
User name
10.1.1.10           0063.6973.636f.2d30.    Oct 28 2010 02:03 AM    Automatic
3030.632e.6365.6137.
2e66.3361.302d.4661.
302f.3010.1.1.11           0100.24e8.f57e.a2       Oct 28 2010 02:12 AM    Automatic

Importing DHCP Options

In some cases, a router or switch may be configured as both a client and server. This is common when the device has a Broadband connection, e.g. DSL or cable, and is also providing addressing information to hosts connected to the LAN. The Cisco IOS DHCP server import and Autoconfiguration feature is enabled by issuing the import all DHCP pool configuration command. When this command is issued, the pool under which it is configured will import the DHCP option parameters into the DHCP server database. These options include parameters such as the DNS and WINS server information, as well as the domain name.

The following configuration example illustrates how to configure a router that is acting as both a DHCP client and server to import DHCP option parameters into the DHCP pool:

R1(config)#ip dhcp excluded-address 10.3.3.1 10.1.1.5
R1(config)#ip dhcp pool POOL-C
R1(dhcp-config)#network 10.3.3.0 255.255.255.0
R1(dhcp-config)#default-router 10.3.3.1
R1(dhcp-config)#import all
R1(dhcp-config)#exit
R1(config)#interface fastethernet 0/0
R1(config-if)#description ‘Connected To Internal LAN’
R1(config-if)#ip address 10.3.3.1 255.255.255.0
R1(config-if)#exit
R1(config)#interface fastethernet 0/1
R1(config-if)#description ‘Connected To The ISP’
R1(config-if)#ip address dhcp
R1(config-if)#exit

This configuration can be validated using the show ip dhcp import command as follows:

R1#show ip dhcp importAddress Pool Name: POOL-C
Domain Name Server(s): 172.16.1.253 172.16.1.254
NetBIOS Name Server(s): 172.16.1.252
Domain Name Option: howtonetwork.net

These imported parameters are then passed onto clients assigned addressing information from the configured local pool named POOL-C.

Configuring A Cisco IOS Router or Switch as a DHCP Relay Agent

Cisco IOS software routers and switches can be configured as DHCP relay agents, allowing the hosts connected to the local LANs they server to acquire addressing information from remote DHCP servers. This functionality is enabled via the ip helper-address <address> interface configuration command under the inside or internal interface which resides on the same subnet as the hosts on the local network. In other words, this command should be configured under the interface that will be receiving the Broadcasts from host. You can specify this command and specify multiple server addresses for high availability. In the event that multiple servers are specified, Cisco routers forward the DHCPDISCOVER message to all the helper addresses configured under the interface. These messages are Unicast to the servers.
By default, the ip helper-address will forward the following UDP Broadcasts:

  1. Trivial File Transfer Protocol (TFTP) (port 69)
  2. DNS (port 53), time service (port 37)
  3. NetBIOS name server (port 137)
  4. NetBIOS datagram server (port 138)
  5. Boot Protocol (DHCP/BOOTP) client and server datagrams (ports 67 and 68)
  6. Terminal Access Control Access Control System (TACACS) service (port 49)
  7. IEN-116 name service (port 42)

However, this command can be configured to forward any UDP Broadcast based on UDP port number. While supported, it should be noted, however, that this is not recommended as forwarding Broadcasts from one subnet to the Broadcast address of another subnet increases Broadcast flooding which can have an adverse impact on network and device performance.

While the ip helper-address command will forward the default list of UDP Broadcasts listed in the previous section, you can also use the ip forward-protocol global configuration command to modify the UDP Broadcasts that the router or switch will forward. This command can be used to remove certain Broadcasts or even include others that are not forwarded by default. For example, assume you only wanted to forward BOOTP / DHCP Broadcasts and no others to the specified servers. In this case, configure the device as follows:

R1(config)#no ip forward-protocol udp 69
R1(config)#no ip forward-protocol udp 37
R1(config)#no ip forward-protocol udp 137
R1(config)#no ip forward-protocol udp 138
R1(config)#no ip forward-protocol udp 49
R1(config)#no ip forward-protocol udp 42
R1(config)#interface fastethernet 0/0
R1(config-if)#ip helper-address 172.17.1.254

The configuration above prevents the router from forwarding all other default Broadcasts save for the Boot Protocol (DHCP/BOOTP) client and server datagrams which use UDP ports 67 and 68. Additionally, the ip forward-protocol command can be used to forward additional Broadcasts in addition to the default ports. For example, to configure the router to forward UDP port 1812 in addition to the default ports, you would issue the following configuration:

R1(config)#ip forward-protocol udp 1812
R1(config)#interface fastethernet 0/0
R1(config-if)#ip helper-address 172.17.1.254

You can verify the helper addresses specified under the interface by either checking the device configuration or using the show ip interfaces <name> command as follows:

R1#show ip interface fastethernet 0/0
FastEthernet0/0 is up, line protocol is up
Internet address is 150.1.1.3/24
Broadcast address is 255.255.255.255
Address determined by DHCP
MTU is 1500 bytes
  Helper addresses are 172.16.1.254
                       172.17.1.254
                       172.18.1.254
Directed broadcast forwarding is disabled
Outgoing access list is not set[Truncated Output]

Additionally, you can also use the show ip helper-address <interface> command to view all configured helper addresses under a specific interface, or under all interfaces on the device, if you do not include the interface argument,  as is illustrated in the following output:

R1#show ip helper-address
Interface                  Helper-Address  VPN VRG Name             VRG State
FastEthernet0/0            172.16.1.254    0   None                 Unknown
172.17.1.254    0   None                 Unknown
172.18.1.254    0   None                 Unknown
FastEthernet0/1            172.20.1.254    0   None                 Unknown
172.21.1.254    0   None                 Unknown
172.22.1.254    0   None                 Unknown

Prev

Next

About Us

This is a free bonus site for members of www.howtonetwork.com

Copyright

The content on this copyright Reality Press Ltd.
Copyright Reality Press Ltd.