Saturday, February 22, 2020

How to configure DHCP Server on Cisco IOS

Cisco IOS routers and layer 3 switches can be configured as DHCP server. It’s quite easy to do this and in this short lesson I want to explain to you how to do this and how to verify your configuration. If you are a little fuzzy how DHCP works, take a look at my introduction to DHCP first.
Let’s use the following topology:
dhcp server example
Above we have a router that I will call ‘DHCP’. The router and computer are connected to each other using a simple switch and in the same VLAN. We will use the 192.168.12.0 /24 subnet for this demonstration. Let’s prepare the interface first:
DHCP(config)#interface fastEthernet 0/0
DHCP(config-if)#no shutdown
DHCP(config-if)#ip address 192.168.12.1 255.255.255.0
Now let’s configure DHCP server:
DHCP(config)#ip dhcp pool MYPOOL
DHCP(dhcp-config)#network 192.168.12.0 255.255.255.0
Use the ip dhcp pool command to create a DHCP pool and give it a name. This DHCP pool will use network 192.168.12.0 /24. Basically this is all you have to do to get DHCP server going, there is no need to start a service or something. We can verify that we have DHCP clients using the following command:
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.2      0063.6973.636f.2d63.    Mar 02 2002 12:24 AM    Automatic
                    6330.372e.3132.3265.
                    2e30.3030.302d.4661.
                    302f.30
Above you can see that we have a DHCP client and it received IP address 192.168.12.2. In production networks we will also use DHCP to hand out some other useful things like a default gateway, DNS server and more. Let’s see how we can do this:
DHCP(config)#ip dhcp pool MYPOOL               
DHCP(dhcp-config)#default-router 192.168.12.1
DHCP(dhcp-config)#dns-server 208.67.222.222
Above I configured IP address 192.168.12.1 as the default gateway for the DHCP clients with the default-router command. The dns-server commands lets us specify a DNS server.
Something else you might want to do is exclude a number of IP addresses. With the configuration so far our DHCP server will hand out IP address .2,3,4,5,6 etc. Here’s how to do it:
DHCP(config)#ip dhcp excluded-address 192.168.12.100
Above I used ip dhcp excluded-address to make sure that IP address 192.168.12.100 will not be handed out to DHCP clients. Last but not least, if you have VoIP phones or wireless access points you probably have to use some “option” fields when giving IP addresses to clients. This is also possible with Cisco IOS and here’s how to do it:
DHCP(config)#ip dhcp pool MYPOOL
DHCP(dhcp-config)#option 150 ip 192.168.12.200
Option 150 is used by Cisco IP phones to locate the TFTP server so that they can get their configuration files. Above I used the option command so that the IP phones will go to TFTP server with IP address 192.168.12.200.
hostname DHCP
!
interface FastEthernet0/0
 ip address 192.168.12.1 255.255.255.0
!
ip dhcp excluded-address 192.168.12.100
!
ip dhcp pool MYPOOL
 network 192.168.12.0 255.255.255.0
 default-router 192.168.12.1
 dns-server 208.67.222.222
 option 150 ip 192.168.12.200
!
end
That’s all I wanted to show you for now, I hope this is useful to you. If you have any questions just leave a comment!

No comments:

Post a Comment