Dynamically Allocating Client IP Addresses via DHCP


You want to configure your router to be a DHCP server and allocate dynamic IP addresses to client workstations.


The following set of configuration commands allows the router to dynamically allocate IP addresses to client workstations:

Router1#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#service dhcp
Router1(config)#ip dhcp pool
Router1(config)#ip dhcp excluded-address
Router1(config)#ip dhcp excluded-address



Cisco incorporated DHCP server functionality starting in IOS Version 12.0(1)T. This allows routers to dynamically allocate IP addresses to client workstations without needing a centralized DHCP server.

Providing DHCP services from a router has some interesting advantages over using a central server. First, distributing the DHCP functionality into the access routers of a large network reduces the risk of a server configuration problem affecting the entire corporate network. Second, maintaining DHCP services within each remote branch router reduces the utilization over expensive WAN links. Third, when a WAN link fails, workstations are still able to function on the local segment. And fourth, the router based DHCP services can easily be administered by your network engineers via one common interface, the IOS prompt.

In our example, we have configured the router to dynamically allocate IP addresses for the subnet First, we define a range of IP addresses using the network command. Then we need to exclude some addresses from the dynamic range with the ip dhcp exclude-address command. If you do not exclude a range of addresses, then the router will assign IP addresses from the entire subnet (254 addresses in total). But in most networks, at least some of the addresses are reserved for other purposes, such as servers or network equipment.

At a minimum, you should exclude the router's own IP address to prevent the DHCP service from trying to assign it elsewhere, causing a conflict. Many network engineers allocate the lower portion of the subnet to static devices such as routers, servers, printers, and other devices that do not support DHCP. In our example we reserved the first 50 addresses for statically addressed devices ( We also chose to reserve addresses from to for future use, and to show that you can reserve multiple blocks of addresses.

When DHCP is enabled, the router will allocate IP addresses dynamically by binding them to device MAC addresses in the configured pool. IP addresses are allocated for a defined period of time called a lease, which we will discuss further in Recipe 20.6. You can view the address bindings with the show ip dhcp binding command as follows:

Router1#show ip dhcp binding
IP address Hardware address Lease expiration Type 0100.0103.85e9.87 Apr 10 2003 08:55 PM Automatic 0100.50da.2a5e.a2 Apr 10 2003 09:00 PM Automatic 0100.0103.ea1b.ed Apr 10 2003 08:58 PM Automatic

You will notice in this output that the MAC addresses look a little bit funny, because they have two extra hex digits (one extra octet) at the start. We will explain this in Recipe 20.7.

The router maintains an internal database of assigned IP addresses and their associated MAC addresses. In Recipe 20.8, we will show how to write this database to a remote server for backup purposes.

Note also that the example dynamically configures DCHP clients with the default router setting using the default-router command. We will discuss these DHCP options in detail in Recipe 20.5.

See Also

Recipe 20.5; Recipe 20.6; Recipe 20.7; Recipe 20.8; Recipe 20.9

Router Configuration and File Management

Router Management

User Access and Privilege Levels


IP Routing





Frame Relay

Handling Queuing and Congestion

Tunnels and VPNs

Dial Backup

NTP and Time


Router Interfaces and Media

Simple Network Management Protocol





First Hop Redundancy Protocols

IP Multicast

IP Mobility




Appendix 1. External Software Packages

Appendix 2. IP Precedence, TOS, and DSCP Classifications


show all menu

Cisco IOS Cookbook
Cisco IOS Cookbook (Cookbooks (OReilly))
ISBN: 0596527225
EAN: 2147483647
Year: 2004
Pages: 505
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net