In this short tutorial let’s configure a DHCP server on a Cisco Router. Why would we want to do that? Well configuring a basic DHCP server on a router is a good idea if this is a branch/satellite office or just a small business. There are some pros and cons of configuring DHCP on a Cisco Router so let’s briefly discuss them and then start configuring.
Putting DHCP on a router is pretty easy and that’s one advantage of setting up DHCP no need to setup a Linux or Windows server. However this also depends on what type of environment you are running, if the company has an Active Directory structure that can be a showstopper if you want have DHCP on the router. There can be a problems because while your domain controller controls DNS any PC that gets an address from DHCP that the router is handing out may not be updated in DNS. (Active Directory likes to have DNS that is current)
There have been issues with Active Directory and the best solution is to setup the DHCP service on the Windows server and disable DHCP on the router. That way both DNS and DHCP is automatically added/updated when a new PC joins the network. Along with way more functionality on the server side than the router side, like such as clustering and or load balancing DHCP servers if there is ever need. Although Cisco routers are great it’s not designed for a clustering load balancing DHCP server. A router’s main job is forwarding and routing data and although routers can have more than one job besides routing this also adds more load to the router if it already has big shoes to fill. 😉
So now let’s begin learning how to configure DHCP, listed below is the current running-config on the router called Branch-1 in which we will configure DHCP on.
BRANCH-1#show run Building configuration... Current configuration : 1075 bytes ! version 12.3 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname BRANCH-1 ! boot-start-marker boot-end-marker ! ! no network-clock-participate aim 0 no network-clock-participate aim 1 no aaa new-model ip subnet-zero ! ! ip cef ! ! ip ips po max-events 100 no ftp-server write-enable ! ! ! interface FastEthernet0/0 ip address 192.168.40.1 255.255.255.0 duplex auto speed auto ! interface FastEthernet0/1 no ip address shutdown duplex auto speed auto ! ! ip classless no ip http server no ip http secure-server ! ! ! ! control-plane ! ! line con 0 logging synchronous line aux 0 line vty 0 4 login ! scheduler allocate 20000 1000 ! end
This configuration is pretty basic and if PCs where connected to FastEthernet 0/0 they would be able to ping the gateway if they where manually setup with the correct IP addresses. This maybe be ok if you only had a couple of PCs to work with but even then it is pretty simple to set up a DHCP server instead of manually configuring PCs so let’s start configuring it!
- For this example we are going to be configuring a DHCP pool called DHCP-40-POOL.
- We are also going to be excluding address from this pool which will be 192.168.40.0 – 192.168.40.5
- In this example we don’t have an internal DNS server so we will be using one of OpenDNS‘s servers. That IP address is 220.127.116.11. We will also configure a secondary DNS server, that IP address is 18.104.22.168 (Thanks Google)
- Finally are domain name for this example will be BRANCH1.CISCOSKILLS.NET
Let’s get connected to Branch-1 and verify you are in global configuration mode and type the following to create a DHCP pool. (This example is using DHCP-40-POOL)
BRANCH-1(config)#ip dhcp pool DHCP-40-POOL BRANCH-1(dhcp-config)#
You’ll notice that we are now in the DHCP-Config area. If you type a question mark we will see the available options we can configure while under this mode.
BRANCH-1(dhcp-config)#? DHCP pool configuration commands: accounting Send Accounting Start/Stop messages bootfile Boot file name class Specify a DHCP class client-identifier Client identifier client-name Client name default-router Default routers dns-server DNS servers domain-name Domain name exit Exit from DHCP pool configuration mode hardware-address Client hardware address host Client IP address and mask import Programatically importing DHCP option parameters lease Address lease time netbios-name-server NetBIOS (WINS) name servers netbios-node-type NetBIOS node type network Network number and mask next-server Next server in boot process no Negate a command or set its defaults option Raw DHCP options origin Configure the origin of the pool subnet Subnet allocation commands update Dynamic updates utilization Configure various utilization parameters vrf Associate this pool with a VRF
So for this example we first need to type the network that will be using DHCP. (For this tutorial it’s the 192.168.40.0 network so the command would look something like this:
BRANCH-1(dhcp-config)#network 192.168.40.0 255.255.255.0
To set the default router for DHCP (This is usually the router’s interface address, PCs would call this their default gateway.)
To set the domain name of this network (This example is using BRANCH1.CISCOSKILLS.NET)
To set DNS servers (You can type more than one in this example I have two DNS servers 22.214.171.124 is the first DNS server followed by 126.96.36.199)
BRANCH-1(dhcp-config)#dns-server 188.8.131.52 184.108.40.206
Our last setup is to exclude some address for this example we are going to excluding the first five address in the the 192.168.40.0/24 range. We have to exit out of the DHCP-config mode and go back to the global configuration mode:
BRANCH-1(dhcp-config)#exit BRANCH-1(config)#ip dhcp excluded-address 192.168.40.0 192.168.40.5
Let’s do a copy run start to save changes and if we now look at the running-config to verify our DHCP settings it should look something like the example below.
BRANCH-1#copy run startup-config Destination filename [startup-config]? Building configuration... [OK] BRANCH-1#show run Building configuration... Current configuration : 1083 bytes ! version 12.3 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname BRANCH-1 ! -- OMITITED-- ! ip dhcp excluded-address 192.168.40.0 192.168.40.5 ! ip dhcp pool DHCP-40-POOL network 192.168.40.0 255.255.255.0 dns-server 220.127.116.11 18.104.22.168 default-router 192.168.40.1 domain-name BRANCH1.CISCOSKILLS.NET ! -- OMITITED--
We should now have DHCP running on our router, if we look at a PC in command prompt and issue the ipconfig /all command all the settings we configured on the router are passing to the PC. Here is some output of the PC that is connected to Branch-1.
C:\Windows\system32>ipconfig /all -- OMITITED-- IPv4 Address. . . . . . . . . . . : 192.168.40.6(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Lease Obtained. . . . . . . . . . : Sunday, November 25, 2012 11:13:58 AM Lease Expires . . . . . . . . . . : Monday, November 26, 2012 11:13:57 AM Default Gateway . . . . . . . . . : 192.168.40.1 DHCP Server . . . . . . . . . . . : 192.168.40.1 DHCPv6 IAID . . . . . . . . . . . : 234884137 DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-18-21-0E-A6-00-0C-29-22-D2-2 DNS Servers . . . . . . . . . . . : 22.214.171.124 126.96.36.199 NetBIOS over Tcpip. . . . . . . . : Enabled -- OMITITED--
That’s it! I hope this tutorial was helpful, to review we just configured a DHCP server on a Cisco IOS Router! As mentioned there are pros and cons when setting up DHCP on a router instead of a Windows or Linux server and the overall configuration in setting up DHCP is simple. If you noticed there are commands available while in the DHCP mode that we have not even touched and I would encourage you to either search them on the web or try them out in a lab environment. Once again I hope this information is helpful and please comment below if you have any questions.
- Coping with Holiday Traffic – Secondary DHCP Subnets (ioshints.info)
- Top 10 Important command prompt’s commands (andiwijaya.wordpress.com)
- Real World DNS Abuse: Finding Common Ground (blogs.cisco.com)
- Cisco IOS DHCP Server tip (diecarvi.wordpress.com)