A Cisco router as a DHCP server, and ip helper-address
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
ip dhcp pool MYPOOLcreates a pool.networksays which network to hand out IP addresses for,default-routergives clients their gateway,dns-servertheir DNS server.ip dhcp excluded-address 192.168.12.10 192.168.12.20keeps that range from being handed to clients. Be careful: it is a global command, not under the pool.ip address dhcpmakes an interface a DHCP client. On the server you check the result withshow ip dhcp binding.- Routers don't forward broadcasts: if the DHCP server is in another subnet, the client's DHCP Discover never reaches it.
- The fix:
ip helper-address <server IP>on the interface facing the clients. The router sends the DHCP messages to the server as unicast, and the server's reply is relayed back to the client through the router.
A router as a DHCP server
We talked about DHCP and DHCP servers before but never showed the configuration. Let's see how to configure a Cisco router as a DHCP server. The topology:
- On the left is a router called "Client". We'll configure its FastEthernet 0/0 interface as a DHCP client, so it will request an IP address.
- On the right is a router called "DHCP": this will be our DHCP server.
Server configuration
DHCP(config)#interface fastEthernet 0/0 DHCP(config-if)#no shutdown DHCP(config-if)#ip address 192.168.12.254 255.255.255.0 DHCP(config-if)#exit DHCP(config)#ip dhcp pool MYPOOL DHCP(dhcp-config)#network 192.168.12.0 DHCP(dhcp-config)#default-router 192.168.12.254 DHCP(dhcp-config)#dns-server 8.8.8.8 DHCP(dhcp-config)#exit
| Command | What it does |
|---|---|
ip dhcp pool MYPOOL | Creates a DHCP pool (named MYPOOL) |
network 192.168.12.0 | Says which network to hand out IP addresses for |
default-router 192.168.12.254 | Gives clients a default gateway (optional) |
dns-server 8.8.8.8 | Gives clients a DNS server (optional); 8.8.8.8 is Google DNS |
Keeping some addresses back: excluded-address
Optionally, you can stop certain IP addresses from being handed out to DHCP clients:
DHCP(config)#ip dhcp excluded-address 192.168.12.10 192.168.12.20In this example 192.168.12.10 – 192.168.12.20 will not be given to clients.
Be careful! ip dhcp excluded-address is a global command: the prompt is DHCP(config)#, not (dhcp-config)#. The book's author notes it would have made more sense to configure this under the pool, but that is not how it works.
The client side
Client(config)#interface fastEthernet 0/0 Client(config-if)#ip address dhcp Client(config-if)#no shutdown
We tell the router to configure its IP address through DHCP. This is what you will see on its console:
Client# %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 192.168.12.1, mask 255.255.255.0, hostname Client
We received an IP address from the DHCP server. We can also verify this on the server:
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.12.1 0063.6973.636f.2d63. Mar 02 2002 12:06 AM Automatic 3230.372e.3065.3734. 2e30.3030.302d.4661. 302f.30
The DHCP server has given 192.168.12.1 to the client.
The problem: the DHCP server is in another subnet
DHCP isn't difficult to configure, but there is one issue you might run into:
On the left is a DHCP client connected to R1. The DHCP server is on the right side of R1, in another subnet. You will often see this, because most networks have their servers centralized.
When the DHCP client tries to get an IP address and sends a DHCP Discover, what will R1 do?
Routers don't forward broadcasts, so this DHCP Discover will never reach the DHCP server! There is a solution, called ip helper:
R1(config)#interface fa0/0 R1(config-if)#ip helper-address 192.168.23.3
This little command forwards the DHCP messages to the DHCP server as unicast. The DHCP server sends the DHCP Offer back to the router so it can be forwarded to the client.
Remember: when there is no DHCP server on the local subnet, use ip helper so the router forwards the DHCP packets to the DHCP server. The command goes on the interface facing the clients (here Fa0/0) and points to the DHCP server's IP address.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1Which command in a DHCP pool gives clients their default gateway?
default-router gives clients a default gateway; dns-server gives them a DNS server.2Where is the ip dhcp excluded-address command configured?
3Which command makes a router interface a DHCP client?
ip address dhcp makes the interface get its IP address from a DHCP server.4The DHCP server is in another subnet and the client gets no IP. Why?
5On which R1 interface must ip helper-address 192.168.23.3 be configured?
Comments
Sign in to comment.