In fact this is how your home Internet modem/router operates. Your PC obtains a private IP address via DHCP from a pool of IP addresses configured on the router. The modem/router is assigned with a public IP address by the Internet Service Provider (ISP) to connect to the Internet. As you connect more PCs or Android phones to Internet, internally each gets its own private IP address from the router (DHCP server) and by the mechanism of NAT (Network Address Translation) their IP addresses are mapped to a single public IP address.
I’ve created a simple topology in GNS3 consisting of one router and three PCs. The objective is to configure DHCP in the router so that all PCs get their IP address and other network parameters from the router.
First step is to enable dhcp service in the router. Although it’s enabled by default, running the command doesn’t hurt.
R2# conf t R2(config)#service dhcp
Next step is to create an IP address pool from which the server can pick and send IP addresses to the clients. Note that “IP-POOL” is the name of the DHCP pool we are creating.
R2(config)#ip dhcp pool IP-POOL R2(dhcp-config)#network 192.168.1.0 255.255.255.0
This tells the router to issue IP addresses for the network 192.168.1.0/24, which translates to the range 192.168.1.1 – 192.168.1.254.
Now we’ll configure the network parameters that will be given to each client. This includes default gateway, dns servers, domain name, lease period in days.
R2(dhcp-config)#default-router 192.168.1.1 R2(dhcp-config)#dns-server 192.168.1.127 192.168.1.128 R2(dhcp-config)#domain-name mynetwork.com R2(dhcp-config)#lease ? <0-365> Days infinite Infinite lease R2(dhcp-config)#lease 5
The last step is to exclude IP addresses from the pool that should not be given to the clients. These addresses are usually the IP addresses of servers such as FTP, HTTP, DNS, etc. Drop back to ‘global configuration mode‘ and enter the following:
R2(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.5 R2(config)#ip dhcp excluded-address 192.168.1.10
This excludes IP addresses 192.168.1.1 – 192.168.1.5 & 192.168.1.10. As you can see, there’s an option to exclude a range of IP addresses or a specific address.
That’s all there to it to get the DHCP service up and running on the Cisco router. Now let’s tell the PCs to get the IP address from the DHCP sever. The PCs are VPCS nodes that come with GNS3.
As you can see VPCS does a nice job of displaying the DORA messages as the DHCP conversation happens between the server and the client. Note that the DHCP gives out the IP addresses starting from 192.168.1.6 since we have excluded the first five IP addresses 192.168.1.1-5.
The show ip dhcp binding command shows all the DHCP bindings and their status, useful to ensure that the configuration is right and for troubleshooting.
R2#sh ip dhcp binding Bindings from all pools not associated with VRF: IP address Client-ID/ Lease expiration Type State Interface Hardware address/ User name 192.168.1.6 0100.5079.6668.00 Jan 30 2016 03:42 PM Automatic Active FastEthernet0/0 192.168.1.7 0100.5079.6668.01 Jan 30 2016 03:44 PM Automatic Active FastEthernet0/0 192.168.1.8 0100.5079.6668.02 Jan 30 2016 03:45 PM Automatic Active FastEthernet0/0