Get Your Free IT Resume Guide

How to Configure DHCP on Cisco IOS Devices

The Dynamic Host Configuration Protocol (DHCP) is considered to be an evolution of the Bootstrap Protocol (BootP).

DHCP is literally build upon BootP, and BootP remains an internal part of DHCP. Both protocols have been created to provide IP addresses to clients when needed.

The difference between them is that while BootP provides an IP address to a client according to the client’s hardware address on the BootP server table, DHCP by default provides an IP address automatically to the client from a pool of IP addresses.

Besides an IP address, the DHCP server can provide the client a lot of information, such as DNS server IP address, Default gateway IP address, Domain name and much more.

A Cisco IOS device can be configured to act as:

  • a DHCP server – by providing IP addresses when requested to do so
  • a DHCP client – when it requests an IP address
  • a DHCP relay agent – when it captures IP requests from clients, adds extra information to the request for user identification purposes, and forwards the request to the DHCP server

Cisco IOS devices can be configured to act as all of the above and even in combinations of two or three of roles. In this article I will investigate the operation of Cisco routers under all of the above roles.

Cisco IOS Router Acting as a DHCP Server

Let’s start by investigating the process of IP address assignment when a DHCP client requests an IP address from a DHCP server. The messages exchanged between client and server can be seen in the diagram below:

DHCP Configuration Protocol

The above diagram presents the DHCP message sequence. Here’s how it all goes down:

  1. The client sends a DHCP Discover message to locate a DHCP server – this is a broadcast message
  2. The DHCP server responds with a DHCP Offer unicast message – this message includes the IP address offered to the client, default gateway address and lease time for the IP address offered; it may also include DNS servers, TFTP server, and other information
  3. The client responds with a DHCP Request message which is a formal request for the IP address offered by the server – this is again a broadcast message
  4. Finally the server responds with a DHCP Ack unicast message confirming that the IP address has been leased to the client

Below is a list of the most important commands to enable a Cisco router to emulate a DHCP server:

Cisco IOS Commands for DHCP

Now let’s use the above commands in a real scenario. A Cisco router is configured to provide DHCP functionality as follows:

  • Router(config)# ip dhcp excluded-address 172.16.1.1 172.16.1.3
  • Router(config)# ip dhcp pool DATA
  • Router(config-dhcp)#network 172.16.1.0 255.255.255.0
  • Router(config-dhcp)#dns-server 172.16.1.1 172.16.1.21
  • Router(config-dhcp)#default-router 172.16.1.1
  • Router(config-dhcp)#lease 7

Based on the above configuration let’s see the messages exchanged as captured from Ethereal application. A screen shot of the messages can be seen below:

Configuring DHCP

Details on the DHCP Offer message sent by the Cisco router can be seen below. Make a note of the client’s offered IP address (172.16.1.5), option 3 – default router’s address, option 51- IP address lease time, option 6 – IP addresses of DNS servers.

Configure DHCP on Cisco

Cisco IOS Router Acting as a DHCP Client

A Cisco router can be configured to act as DHCP client and obtain dynamically an interface address by using the command ip address dhcp in interface configuration mode. Issuing this command causes the router to transmit DHCP Discover messages on the specific interface.

Cisco IOS Router Acting as a DHCP Relay Agent

By default routers do not forward broadcasts. In internetworks, most of the times, a DHCP server is located on a different network than the majority of its clients.

For DHCP messages to be able to reach the server, configuration of IP helper addresses is required. IP helper address [DHCP server IP address] interface command instructs a router to intercept DHCP broadcast messages and forward them as unicasts to the DHCP server hence providing “relay” functionality.

DHCP relay agents provide extra security to the network by hiding the server’s IP address from the clients. The client knows only the IP address of the relay agent.

The image below shows a common scenario where IP helper address is required.

IP Helper Address Required

The next image shows an IP DHCP Offer message as received on the client.

Note the IP address of the relay agent specified in the message. The client with the help of IP helper address on the relay agent is able to receive its IP address and all other information options provided.

Configuring DHCP

Telecom companies use the services provided by DHCP relay agents extensively. Specifically the ip dhcp relay information option global configuration command which enables the DHCP relay agent to include information about itself to the DHCP requests sent from clients to DHCP server.

This is very useful for telecom operators when ATM routed bridge encapsulation (RBE) is used so that ATM interface and PVC over which the DHCP request came in is transmitted to the server from the relay agent. This information can be used to authenticate the client and help the DHCP server to apply the appropriate policy decisions.

The image below shows schematically the DHCP relay information option concept.

DHCP Relay Information Option

Summary

  • DHCP functionality can be reliably configured on Cisco IOS devices. Cisco devices can be configured to act as DHCP servers, DHCP clients, or DHCP relay agents or even a combination of these.
  • DHCP options like DNS servers, Domain name, lease time, etc. can be configured on Cisco devices.
  • IP helper address activates the DHCP relay agent functionality on Cisco devices.
  • DHCP relay agent options can be activated on Cisco devices so that supplementary services such as RBE functionality could be effective.

Prepare for Your Next Exam with Cisco Training by TrainSignal

Cisco Certification Training

TrainSignal’s Cisco Certification Training will help you master all the critical Cisco Networking Skills to prepare you for your next Cisco Exam! Learn more…

More Related Posts

  1. Cisco ATA 180 Series Analog Phone Adapters
  2. Basic Networking Protocols: Part 2
  3. Cisco Network Troubleshooting for Beginners
  4. Cisco Routers – What to Know BEFORE You Buy
  5. 5 Things I Hate about the Cisco IOS (and How to Fix Them!)

Discussion

15 comments and trackbacks for “How to Configure DHCP on Cisco IOS Devices

Comments

  1. Posted by yogesh on September 30, 2008, 8:36 am

    its great this information is very very useful.

  2. Posted by rajesh dhapola on October 7, 2008, 2:12 am

    hi chris,

    The DHCP topic which u have described is quite GOOD .

  3. Posted by Willy Maldonado on October 20, 2008, 12:25 am

    very clear and smothly explained..

  4. Posted by Marcel Koudstaal on January 21, 2009, 9:42 am

    OK, I configured my new cisco1801 to act as a DHCP server.
    And it works .. (of course).
    But … one question though …

    My config is as below:


    !
    ! exclude the IP-address
    !
    ip dhcp excluded-address 10.10.0.65
    !
    ip dhcp pool laptop_pool
    import all
    network 10.10.0.64 255.255.255.248
    default-router 10.10.0.65
    dns-server 10.10.0.65
    domain-name myown.net
    lease 0 2
    !

    The server starts giving away IP-addresses from 10.10.0.66 until 10.10.0.70.
    I connected a device (an WiFi access point) to the interface Fa3 (layer2 int Fa3 with layer3 on interface VLAN3) of the c1801 and indeed I see a binding, no problem with that!

    The problem is that every hour I do see the following in the logging (DHCP server event debugging enabled):

    Jan 21 10:23:10: DHCPD: Sending notification of ASSIGNMENT:
    Jan 21 10:23:10: DHCPD: address 10.10.0.66 mask 255.255.255.248
    Jan 21 10:23:10: DHCPD: htype 1 chaddr 0012.1770.5574
    Jan 21 10:23:10: DHCPD: lease time remaining (secs) = 7200

    Jan 21 11:23:11: DHCPD: Sending notification of ASSIGNMENT:
    Jan 21 11:23:11: DHCPD: address 10.10.0.66 mask 255.255.255.248
    Jan 21 11:23:11: DHCPD: htype 1 chaddr 0012.1770.5574
    Jan 21 11:23:11: DHCPD: lease time remaining (secs) = 7200

    Jan 21 12:23:12: DHCPD: Sending notification of ASSIGNMENT:
    Jan 21 12:23:12: DHCPD: address 10.10.0.66 mask 255.255.255.248
    Jan 21 12:23:12: DHCPD: htype 1 chaddr 0012.1770.5574
    Jan 21 12:23:12: DHCPD: lease time remaining (secs) = 7200

    and so on …

    The “lease time remaining (secs) = 7200″ means a 2 hours lease, am I right ?
    Why does the c1801 every hour this check and not as I expected every 2 hours?

    Best regards,
    Marcel Koudstaal.

    Cisco IOS Router Acting as a DHCP Server

  5. Posted by Stelios Antoniou on January 21, 2009, 1:26 pm

    This is not a check sequence. Actually every hour the lease is renewed that is why you see a notification every hour. The lease time is 2 hours. Your device every hour renews its lease. If it fails to do so, then after 1 hour it will remove its lease and request for a new lease (new IP address)

  6. Posted by Marcel Koudstaal on January 21, 2009, 11:27 pm

    Thanks Stelios Antoniou … that indeed must be the explanation. I just did not think about this device be the one renewing the lease it got every hour.
    I am a bit to cisco-minded I am afraid :)

  7. Posted by ken on April 23, 2009, 12:29 am

    great explanation!

    you are gifted man! in explaining things!

    you make complicated things simple!

    where do i get your other articles?

    thnx
    :)

  8. Posted by Jammi on May 20, 2009, 3:41 pm

    Can Anyone help me that why i can not ping default gateway address 96.52.160.1

    I am kind of frustrate that it looks everything OK to me but since last one week day and night i am trying to figure out that why it can not ping ISP and neither can open webpage (DNS are entered correctly)

    PC————————-Cisco 1600-Router—————————————-ISP
    192.168.1.2 192.168.1.1 96.52.160.200 96.52.160.1

    1600_Router#sh run
    Building configuration…
    Current configuration : 787 bytes
    !
    version 12.1
    service timestamps debug datetime msec
    service timestamps log datetime msec
    no service password-encryption
    !
    hostname 1600_Router
    !
    logging buffered 4096 debugging
    !
    ip subnet-zero
    no ip finger
    !
    interface Ethernet0
    ip address 96.52.160.200 255.255.252.0
    ip nat outside
    !
    interface Serial0
    ip address 192.168.1.1 255.255.255.0
    ip nat inside
    clockrate 500000
    !
    router rip
    network 96.0.0.0
    network 192.168.1.0
    !
    ip nat inside source list 10 interface Ethernet0 overload
    ip classless
    ip route 0.0.0.0 0.0.0.0 96.52.160.1
    no ip http server
    !
    access-list 10 permit 192.168.0.0 0.0.255.255
    !
    end

  9. Posted by StanSmith on May 22, 2009, 11:22 am

    well, i can ping your routers DG, the 96.52.160.1, from where i am.

    so according to your config, you either have your IPs mixed up between your two interfaces or you have a wrong subnet mask. i believe it should be the first option.

    serial interfaces often dont connect to PCs, but they can in certain rare setups which i am not about to presume.

  10. Posted by Chuck B on September 17, 2009, 5:23 am

    I’m just started a Wan Class and I am very interested in this, Where can I get a list of Cisco router commands so I can use it for practice with my class?
    Thank you,
    Chuck B

  11. Posted by Norman Paterson on November 17, 2009, 2:27 pm

    I want to configure some Cisco 29xx switches by using DHCP and TFTP followed by some manual editing. The IOS manual says the switch uses DHCP if it has no config.text, so once the configuration has been downloaded and saved, it won’t use DHCP again unless I choose to reset it.

    The problem is that although the switch gets its IP address from the DHCP server, it doesn’t take its host name, default gateway, or name server addresses. The information is in the DHCP server but it doesn’t end up in the switch. Here’s the DHCP server entry:

    host switch-a {
    hardware ethernet 00:11:93:e5:8f:84;
    fixed-address switch-a;
    option host-name switch-a;
    option domain-name-servers 11.22.33.44, 11.22.33.55;
    }

    (I know the host-name option is not required – I’ve tried it both ways.)

    Any suggestions?

  12. Posted by rick on January 14, 2010, 2:26 pm

    If a pc that is running dhcp, has received an ip address reboots his pc , will the lease be broken and a new dhcp request sent by the pc?

  13. Posted by Mohit singh on April 23, 2010, 6:34 am

    So,thanks this about information

  14. Posted by Mohit singh on April 23, 2010, 6:45 am

    I am ask the question how to network speed same in workgroup pc.
    please submit the solution………….OK by………………..

  15. Posted by Raj on July 30, 2010, 7:59 am

    But is there any way to specify the “Subnet Mask” client will receive?
    I configured but my client (client router) getting only /32 IP address

Post a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>