Sunday 20 October 2019

Configure of DHCP server and DHCP Client on Cisco Router

Configure of DHCP server and DHCP Client on Cisco Router

In this section, you will get complete details on Configure of DHCP server and DHCP Client on Cisco Router. Step by step and all the commands you should learn. If you learn about what is DHCP you can visit here.
A Cisco router running Cisco IOS software can be configured to function as a DHCP server . The DHCP server used by Cisco IOS assigns and manages IPv4 addresses from specified address sets within the router for DHCP clients. The topology shown in figure is used to illustrate this functionality.

HOW TO CONFIGURE A DHCP SERVER IN CISCO ROUTER

  • Step 1: Exclude IPv4 addresses

The router that functions as a DHCP server assigns all IPv4 addresses in a set of DHCP addresses, unless it is configured to exclude specific addresses. Generally, some IPv4 addresses in a set are assigned to network devices that require static address assignments. Therefore, these IPv4 addresses should not be assigned to other devices. To exclude specific addresses, use the ip dhcp excluded-address command  , as shown below:
R1 (config) # ip dhcp excluded-address  low-address [ high-address ]
A single address or range of addresses can be excluded by specifying the lowest address and the highest address in the range. Excluded addresses must include the addresses assigned to routers, servers, printers and other devices that were configured or will be configured manually.
R1 (config) # ip dhcp excluded-address 192.168.10.1 192.168.10.9
R1 (config) # ip dhcp excluded-address 192.168.10.254

  • Step 2: Configure a DHCPv4 pool

The configuration of a DHCP server involves defining a set of addresses to be assigned. As shown below, the ip dhcp pool set-  name command   creates a set with the specified name and places the router in DHCP configuration mode, which is identified with the Router (dhcp-config) # flag.
R1 (config) # ip dhcp pool  pool-name 
R1 (dhcp-config) #
R1 (config) # ip dhcp pool LAN-POOL-1 
R1 (dhcp-config) #

  • Step 3: Configure specific tasks

Finally, the tasks to complete the configuration of the DHCP pool are indicated. Some of them are optional, while others must be configured.

REQUIRED AND OPTIONAL TASKS FOR DHCP

Required Tasks
Required Tasks
Command
Define the address set.
network network number [mask | prefix-length]
Define the default router or gateway.
default-router address [address2… address8]
Table of configuration of specific tasks.
Optional Tasks

Optional Tasks
Command
Define a DNS server.
dns-server address [address2… address8]
Define the domain name.
domain-name domain
Define the duration of the DHCP grant.
read {days [hours] [minutes] | infinite}
Define the WINS server with NetBIOS.
netbios-name-server address [address2… address8]
Table of configuration of specific tasks.
Use the default-router command   to define the default gateway router. Normally, the gateway is the LAN interface of the router closest to the client devices. A gateway is required, but up to eight addresses can be indicated if there are several gateways.
Other commands in the DHCP pool are optional. For example, the IPv4 address of the DNS server that is available to a DHCP client is configured using the dns-server command  . The  domain-name  domain command  is used to define the domain name. The lease duration of DHCPv4 can be modified using the lease command  . The default lease value is one day. The netbios-name-server command   is used to define the WINS server with NetBIOS.

DHCP CONFIGURATION EXAMPLE

An example configuration with basic DHCPv4 parameters configured on router R1 is shown below. R1 is configured as a DHCPv4 server for LAN 192.168.10.0/24 using the example topology of Image 1.
R1 (config) # ip dhcp excluded-address 192.168.10.1 192.168.10.9
R1 (config) # ip dhcp excluded-address 192.168.10.254 
R1 (config) # ip dhcp pool LAN-POOL-1
R1 (dhcp-config) # network 192.168.10.0 255.255.255.0
R1 (dhcp-config) # default-router 192.168.10.1
R1 (dhcp-config) # dns-server 192.168.11.5
R1 (dhcp-config) # domain-name example.com
R1 (dhcp-config) # end
R1 #
The DHCP service is enabled by default. To disable the service, use the global configuration mode no service dhcp command  . Use the dhcp  global configuration mode command  to re-enable the DHCP server process. If the parameters are not set, enabling the service has no effect.

DHCP VERIFICATION

In the example result, the topology shown in Image 1 is used. In this example, R1 was configured to provide DHCP services. Since PC1 did not turn on, it does not have an IP address.

SHOW RUNNING-CONFIG COMMAND

As shown below, in the result of the  show running-config | dhcp section , the DHCP commands configured in R1 are displayed. The parameter  | section  shows only the commands associated with the DHCP configuration.
R1 # show running-config | dhcp section
ip dhcp excluded-address 192.168.10.1 192.168.10.9
ip dhcp excluded-address 192.168.10.254
ip dhcp excluded-address 192.168.11.1 192.168.11.9
ip dhcp excluded-address 192.168.11.254
ip dhcp pool LAN-POOL-1
 network 192.168.10.0 255.255.255.0
 default-router 192.168.10.1 
 dns-server 192.168.11.5 
 domain-name example.com
ip dhcp pool LAN-POOL-2
 network 192.168.11.0 255.255.255.0
 default-router 192.168.11.1 
 dns-server 192.168.11.5 
 domain-name example.com
R1 #
SHOW IP DHCP BINDING COMMAND
As shown in the following result, DHCPv4 operation can be verified using the show ip dhcp binding command  . This command shows a list of all the links of the IPv4 address with the MAC address that were provided by the DHCPv4 service.

R1 # show ip dhcp binding Bindings from all pools not associated with VRF: IP address Client-ID / Lease expiration Type Hardware address / User Name
The following command,  show ip dhcp server statistics , is used to verify if the router receives or sends messages. This command displays counting information regarding the number of DHCPv4 messages that were sent and received.R1 # show ip dhcp server statistics
Memory usage 23543
Address pools 1
Database agents 0
Automatic bindings 0
Manual bindings 0
Expired bindings 0
Malformed messages 0
Secure arp entries 0

Message Received
BOOTREQUEST 0
DHCPDISCOVER 0
DHCPREQUEST 0
DHCPDECLINE 0
DHCPRELEASE 0
DHCPINFORM 0

Message Sent
BOOTREPLY 0
DHCPOFFER 0
DHCPACK 0
DHCPNAK 0
R1 #
As seen in the result of these commands, there are currently no links, and statistics indicate that there are no messages sent or received. At this time, no device requested DHCPv4 services from router R1.

SHOW IP DHCP COMMAND

In the following result, the commands are issued after PC1 and PC2 were turned on and the boot process finished.
R1 # 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.10.10 0100.e018.5bdd.35 May 28 2013 01:06 PM Automatic
192.168.11.10 0100.b0d0.d817.e6 May 28 2013 01:10 PM Automatic
R1 # show ip dhcp server statistics
Memory usage 25307
Address pools 2
Database agents 0
Automatic bindings 2
Manual bindings 0
Expired bindings 0
Malformed messages 0
Secure arp entries 0

Message Received
BOOTREQUEST 0
DHCPDISCOVER 8
DHCPREQUEST 3
DHCPDECLINE 0
DHCPRELEASE 0
DHCPINFORM 0

Message Sent
BOOTREPLY 0
DHCPOFFER 3
DHCPACK 3
DHCPNAK 0
R1 #
Note that the information about the bindings now shows that IPv4 addresses 192.168.10.10 through 192.168.11.10 joined the MAC addresses. Statistics also show DHCPDISCOVER, DHCPREQUEST, DHCPOFFER and DHCPACK activity.

IPCONFIG / ALL COMMAND

As shown in Image 2, the ipconfig / all command  , when issued on PC1, shows the TCP / IP parameters. Since PC1 was connected to network segment 192.168.10.0/24, it automatically received a DNS suffix, an IPv4 address, a subnet mask, a default gateway and a DNS server address from that pool. No DHCP specific router interface configuration is required. If a computer is connected to a network segment that has an available DHCPv4 pool, the computer can obtain an IPv4 address from the appropriate pool automatically.

DHCP RELAY

In a complex hierarchical network, business servers are usually located in a server farm. These servers can provide DHCP, DNS, TFTP and FTP services for the network. Generally, network clients are not on the same subnet as those servers. To locate servers and receive services, clients often use broadcast messages.

In figure, PC1 attempts to acquire an IPv4 address from a DHCP server through a broadcast message. In this situation, router R1 is not configured as a DHCPv4 server and does not forward the broadcast message. Since the DHCPv4 server is located on a different network, PC1 cannot receive an IP address via DHCP.

IPCONFIG / RELEASE AND IPCONFIG / RENEW COMMANDS

In Image 4, PC1 tries to renew its IPv4 address. To do this, the ipconfig / release command is issued  . Note that the IPv4 address is released, and the address is shown to be 0.0.0.0. Next, the ipconfig / renew command is issued  . This command causes PC1 to broadcast a DHCPDISCOVER message. The result shows that PC1 cannot locate the DHCPv4 server. Since routers do not forward broadcast messages, the request is not correct.

As a solution to this problem, an administrator can add DHCP servers on all subnets. However, running these services on several computers generates an additional cost and administrative overhead.
A better solution is to configure a Cisco IOS help address. This solution allows the router to forward DHCPv4 broadcasts to the DHCPv4 server. When a router forwards assignment requests / address parameters, it acts as a DHCPv4 relay agent. In the example topology, PC1 would broadcast a request to locate a DHCPv4 server. If R1 was configured as a DHCPv4 relay agent, it would forward the request to the DHCPv4 server located on subnet 192.168.11.0.

IP HELPER-ADDRESS COMMAND

As shown below, the interface on R1 that receives the broadcast is configured with the ip helper-address interface configuration mode command  . The DHCP server address is configured as the only parameter.
R1 (config) # interface g0 / 0
R1 (config-if) # ip helper-address 192.168.11.6
R1 (config-if) # end
R1 # show ip interface g0 / 0
GigabitEthernet0 / 0 is up, line protocol is up 
 Internet address is 192.168.10.1/24
 Broadcast address is 255.255.255.255
 Address determined by setup command
 MTU is 1500 bytes
 Helper address is 192.168.11.6
When R1 is configured as a DHCP relay agent, it accepts broadcast requests for the DHCP service and then forwards those requests as a unicast to IPv4 address 192.168.11.6. The show ip interface command   is used to verify the configuration.
As shown in Image 5, PC1 can now acquire an IPv4 address from the DHCPv4 server.

DHCPv4 is not the only service that can be configured to relay the router. By default, the ip helper-address command   forwards the following eight UDP services:

  • Port 37: Time
  • Port 49: TACACS
  • Port 53: DNS
  • Port 67: DHCP / BOOTP client
  • Port 68: DHCP / BOOTP server
  • Port 69: TFTP
  • Port 137: NetBIOS Name Service
  • Port 138: NetBIOS datagram service

Configuration of a router as a DHCPv4 client

Occasionally, Cisco routers in small offices and home offices (SOHO) and at branch sites must be configured as DHCPv4 clients similar to client computers. The specific method used depends on the ISP. However, in its simplest configuration, the Ethernet interface is used to connect to a cable modem or a DSL modem. To configure an Ethernet interface as a DHCP client, use the ip address dhcp interface configuration mode command  .

In figure, suppose an ISP was configured to provide IP addresses of the network range 209.165.201.0/27 to select clients. After the G0 / 1 interface is configured with the  ip address dhcp command, the show ip interface g0 / 1 command   confirms that the interface is activated and that the address was assigned by a DHCPv4 server.

SOHO (config) # interface g0 / 1
SOHO (config-if) # ip address dhcp
SOHO (config-if) # no shutdown
SOHO (config-if) #
* Jan 31 17: 31: 11.507:% DHCP-6-ADDRESS_ASSIGN: Interface
GigabitEthernet0 / 1 assigned DHCP address 209.165.201.12, mask
255.255.255.224, hostname SOHO
SOHO (config-if) # end
SOHO # show ip interface g0 / 1
GigabitEthernet0 / 1 is up, line protocol is up
 Internet address is 209.165.201.12/27
 Broadcast address is 255.255.255.255
 Address determined by DHCP

CONFIGURING A WIRELESS ROUTER AS A DHCP CLIENT

Normally, wireless routers for home or small office use are connected to an ISP using a cable modem or DSL. In most cases, wireless routers are configured to receive IPv4 addressing information automatically from the ISP.

For example, the illustration shows the default WAN configuration page for a Packet Tracer wireless router. Note that the type of Internet connection is set to  Automatic Configuration - DHCP  . This selection is used when the router connects to a modem or DSL cable and acts as a DHCP client and requests an IPv4 address from the ISP.

No comments:

Post a Comment