Saturday, February 22, 2020

DHCP Client on Cisco IOS

DHCP server is often used on Cisco IOS routers so you supply hosts with an IP address. We can also use DHCP client on our routers which is useful if your ISP uses dynamic IP addresses for customers.
In this lesson, we’ll take a look how to configure your router as DHCP client.

Configuration

This is the topology we will use:
Cisco IOS DHCP Client
Let’s start with the DHCP server.

DHCP Server

Let’s create a pool for our local subnet and include a default route:
Server(config)#ip dhcp pool MY_POOL
Server(dhcp-config)#network 192.168.1.0 /24
Server(dhcp-config)#default-router 192.168.1.254
That’s all we need, let’s look at the DHCP client now.

DHCP Client

You only need one command on the interface to use DHCP:
Client(config)#interface FastEthernet 0/0
Client(config-if)#ip address dhcp
Client(config-if)#no shutdown
After a few seconds you will see this:
Client#
%DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 192.168.1.1, mask 255.255.255.0, hostname Client
Great so we got an IP address:
Client#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.1.1     YES DHCP   up                    up
The router also installs a default route:
Client#show ip route static 
Codes: L - local, C - connected, S - static, 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
       i - IS-IS, su - IS-IS summary, 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, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is 192.168.1.254 to network 0.0.0.0

S*    0.0.0.0/0 [254/0] via 192.168.1.254
You can see that the administrative distance is very high (254). This ensures that any other default route will be preferred over this one.
hostname Client
!
ip cef
!
interface FastEthernet0/0
 ip address dhcp
!
end
hostname Server
!
ip cef
!
ip dhcp pool MY_POOL
 network 192.168.1.0 255.255.255.0
 default-router 192.168.1.254
!
interface FastEthernet0/0
 ip address 192.168.1.254 255.255.255.0
!
end
That’s all there is to it. If you have any questions, feel free to leave a comment.

No comments:

Post a Comment