The DHCP (Dynamic Host Configuration Protocol) protocol is a feature to provide machines that require a full IP, IPv4 address, subnet mask, default gateway, dns server... 
This article is about How to configure DHCP on a Cisco router.
 
Topology for how to configure DHCP on a Cisco router

DHCP Topology
DHCP Topology

Here, we will perform the configuration of R1, access to network internet and DHCP router, router acting as DHCP server. Course DHCP services could be configured on R1, but for didactic reasons I chose to separate this functionality. understand you why later in the article.
Initial configuration

In order to avoid finishing with a several page long article, I will put here only the necessary configuration. The default settings are not included.
On ISP
hostname ISP
!
interface Loopback0
 ip address 8.8.8.8 255.255.255.255
!
interface Serial0/0
 ip address 80.100.200.1 255.255.255.252
 clock rate 2000000

On R1
interface FastEthernet0/0
 ip address 192.168.0.1 255.255.255.0
 ip nat inside
 ip virtual-reassembly
 duplex auto
 speed auto
!
interface Serial0/0
 ip address 80.100.200.2 255.255.255.252
 ip nat outside
 ip virtual-reassembly
 clock rate 2000000
!
interface FastEthernet0/1
 ip address 192.168.1.1 255.255.255.0
 ip nat inside
 ip virtual-reassembly
 duplex auto
 speed auto
!
ip route 0.0.0.0 0.0.0.0 Serial0/0
!
ip nat inside source list 1 interface Serial0/0 overload
!
access-list 1 permit any
 
On DHCP
hostname DHCP
!
interface FastEthernet0/0
 ip address 192.168.1.5 255.255.255.0
 duplex auto
 speed auto
!
ip route 0.0.0.0 0.0.0.0 192.168.1.1
 

Attention, the default route on DHCP is required for the rest of the Setup, I'll put in a word more far.



Reminder
The DHCP protocol is conveyed directly in a frame. More machine that emits a DHCP request, with still no identity (address IPv4 etc) has another opportunity to communicate through broadcast. This means that the DHCP request from this machine is a broadcast frame.

This
may seem unimportant, but do not forget that a broadcast is confined in his broadcast domain, in other words, it does not exceed a router. Out, here, between the DHCP server and the LAN1 there are R1... a router!

We
will have to eventually ensure that R1 is configured to relay the DHCP request to the DHCP server.
Configuration method
So that DHCP can hand out addresses both the LAN1 and LAN2 the we have to configure the following

 
  • Exclude addresses that we desire not to distribute (that of the gateway, or of machines with fixed addresses)
  •  for each LAN configure a DHCP pool in which we will specify the options (gateway, DNS server, network address, …)
  •  Configure the DHCP Relay for LAN1, on R1.
The configuration

Good practice is to configure the DHCP server in order that may seem illogical at first. What the question is that once the DHCP pool is configured, the router will begin to assign addresses. So it is advisable to first configure options (addresses to exclude the pool settings... all before you set the address range to take in charge), otherwise the first received by the machine configurations may incomplete.

Let's start with the router DHCP...

Exclusion of necessary addresses (address of gateways, DHCP server...) here we will exclude the first ten of each LAN (arbitrary choice).



DHCP(config)#ip dhcp excluded-address 192.168.0.1 192.168.0.10

DHCP(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.10



Attention in the definition of the addresses to be excluded, the first address is the start of the range and the second end of the range to exclude. If you don't want that to exclude an address, simply do not give end address.
Now let's configure the DHCP for the LAN1 pool...


DHCP(config)#ip dhcp pool LAN1

DHCP(dhcp-config)#default-router 192.168.0.1

DHCP(dhcp-config)#dns-server 8.8.8.8

DHCP(dhcp-config)#network 192.168.0.0 255.255.255.0

DHCP(dhcp-config)#exit

 

So they created here a DHCP pool named LAN1, in which machines will receive as default gateway 192.168.0.1 (address of R1 in the LAN1), a DNS 8.8.8.8 (completely fictional here, but it seemed essential to show how to configure)... and this configuration will be valid for the network 192.168.0.0/24 (address range to be distributed to subtract previously excluded addresses).

Do the same for the LAN2...
 
DHCP(config)#ip dhcp pool LAN2
DHCP(dhcp-config)#default-router 192.168.1.1
DHCP(dhcp-config)#dns-server 8.8.8.8
DHCP(dhcp-config)#network 192.168.1.0 255.255.255.0
DHCP(dhcp-config)#exit
 
Now the machines of the LAN2 must properly receive their configuration because the DHCP server is in the same domain that they broadcast.

Check on C2...

VPCS[2]> ip dhcp
DDORA IP 192.168.1.11/24 GW 192.168.1.1
 
The DHCP server should also have kept this DHCP lease in memory...
 
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.1.11 0100.5079.6668.01 Mar 02 2002 12:34 AM Automatic
DHCP#
 
On the other hand... impossible for C1 to receive its configuration...
 
VPCS[1]> ip dhcp
DDD
Can't find dhcp server
 
Indeed, when R1 receives the plot of broadcast containing the query DHCP of C1, because he cannot do anything, he "throws it' purely and simply.

We need to configure the relay of the DHCP frames to the DHCP server. For this we need to explicitly tell R1 to relay these frames to 192.168.1.5 (DHCP server) when they enter the Fa0/0 interface. Here is the manipulation:
 
R1(config)#interface fastEthernet 0/0
R1(config-if)#ip helper-address 192.168.1.5
 
Note that the command 'ip helper-address' has more utility than the simple relay DHCP requests. It is used to relay the broadcasts several protocols (DHCP, NTP, Netbios...) UDP.

C1 can now also get its configuration by DHCP
 
VPCS[1]> ip dhcp
DDORA IP 192.168.0.11/24 GW 192.168.0.1
 
DHCP must also have withheld information about the DHCP lease...
 
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.0.11 0100.5079.6668.00 Mar 02 2002 01:27 AM Automatic
192.168.1.11 0100.5079.6668.01 Mar 02 2002 12:34 AM Automatic
DHCP#
 
Some further explanation...
How Does DHCP to know in what pool of address it must draw in response to a query from the LAN1 or LAN2?

 In the case of the LAN2, the request arrives in the form of a broadcast, on the Ethernet interface of DHCP, it is sufficient to provide a configuration for a machine inthe same broadcast domain that him therefore the pool LAN2.

 By contrast, in the case of the LAN1, the request arrives to DHCP in the form of unicast, because it is relayed by R1. R1 has in reality, built a unicast packet, with as the source address that of its interface in the LAN1 and as the destination of the DHCP server.

 Since then when DHCP receives the unicast request, it offers an address from the pool which the address range corresponds to that configured on interface Fa0/0 of R1.

A few settings and more...
Of course the DHCP configuration is not limited to an address, mask, gateway, and a DNS server. Here are a few other configurable parameters...

Set the domain name that will be associated with the interface receiving the configuration...

DHCP(config)#ip dhcp pool LAN1
DHCP(dhcp-config)#domain-name test.lab

Configure the DHCP lease...

DHCP(dhcp-config)#lease 5 10 30
 
The format is "lease . You can also set an unlimited lease by using "infinite lease.

It is also possible to configure options 'raw '. These are specific parameters with no name. But the syntax varies depending on the data to be provided.

For example, should fill a TFTP server address so that a machine can pick up a boot image (this is the case in with deployment network systems), must indicate the option 150, with as parameter the ip address of the TFTP server.

DHCP(dhcp-config) #option 150 ip 192.168.1.50

Yet a check...
We have seen the 'show ip dhcp binding' command that displays a list of the current leases. It is also possible to display the DHCP pools and their statistics...
 
DHCP#sh ip dhcp pool LAN1
 Pool LAN1 :
 Utilization mark (high/low) : 100 / 0
 Subnet size (first/next) : 0 / 0
 Total addresses : 254
 Leased addresses : 1
 Pending event : none
 1 subnet is currently in the pool :
 Current index IP address range Leased addresses
 192.168.0.12 192.168.0.1 - 192.168.0.254 1
DHCP#

That's what set up a functional DHCP server.

0 comments:

Post a Comment

 
Top