Previous section   Next section

Recipe 20.3 Using DHCP to Dynamically Configure Router IP Addresses

20.3.1 Problem

You want the router to dynamically obtain its IP addressing information.

20.3.2 Solution

The ip address dhcp configuration command allows the router to dynamically obtain the address information for an interface:

Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#interface Ethernet0
Router1(config-if)#ip address dhcp client-id Ethernet0
Router1(config-if)#end
Router1#
Interface Ethernet0 assigned DHCP address 172.25.1.57, mask 255.255.255.0
Router1#

20.3.3 Discussion

Cisco started to include DHCP client functionality in IOS Version 12.1(2)T. This allows routers to obtain interface IP address information via DHCP. While we don't recommend using dynamic addressing for routers in an internal network, this can be extremely useful for routers that connect to the Internet through an ISP. It is increasingly common for service providers to use DHCP to give address information to allocate information to client devices.

When an interface on the router is configured as a DHCP client like this, it is able to dynamically learn its IP address, netmask, and default gateway via DHCP. You can also configure the router to accept domain name and DNS server information through DHCP.

In the following screen capture, the router has learned its default route via DHCP. The router displays this DHCP route as a static route and assigns it an administrative distance of 254. This ensures that the default address learned via DHCP is the absolutely last possible route, and any other static or dynamic routes will take precedence:

Router1#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route
   
Gateway of last resort is 172.25.1.1 to network 0.0.0.0
   
     172.25.0.0/24 is subnetted, 1 subnets
C       172.25.1.0 is directly connected, Ethernet0
S*   0.0.0.0/0 [254/0] via 172.25.1.1
Router1#

In the ISP situation, the end devices will also need domain name and DNS server information. You can see this information with the show host command. This example shows domain name and DNS server information learned via DHCP:

Router1#show host
Default domain is oreilly.com
Name/address lookup uses domain service
Name servers are 255.255.255.255, 172.25.1.1
   
Host                      Port  Flags      Age Type   Address(es)
www.oreilly.com           None  (temp, OK)  0   IP    192.168.22.57
Router1#

Note that the router dynamically learned about the domain name and name server information via DHCP, but this information will not overwrite statically configured information. For example, if you manually configure the router with a domain name, the router will quietly ignore the one that it learns through DHCP. The router will simply add any name servers that it learns through DHCP to the static list of manually configured name servers.

The show ip interface command tells you that the router learned IP address from DHCP:

Router1#show ip interface
Ethernet0 is up, line protocol is up
  Internet address is 172.25.1.57/24
  Broadcast address is 255.255.255.255
  Address determined by DHCP
  MTU is 1500 bytes
  <removed for brevity>

Cisco routers do not currently include a way to specify which options the router will request from the server. You also can't see the address lease time remaining. Hopefully Cisco will include these options in a future IOS release.

Although controlling your router addresses from a centralized DHCP server might seem like a good idea, we don't generally recommend it. Routers are the core architecture of a network and should never rely on an external server to obtain IP addressing. Unless a DHCP server is available on every segment, the router needs a DHCP proxy, which is usually another router with a hardcoded IP address. In disaster scenarios in which many routers fail simultaneously, it can be extremely difficult to bootstrap the network back into operation.

So, except for specific circumstances (such as using a router at the edge of the network to connect to an ISP), we strongly discourage using this DHCP client functionality.


  Previous section   Next section
Top