1.实验目的
通过本实验可以掌握通过DHCP中继实现跨网络的DHCP服务。
2.拓扑结构
实验拓扑图如图10-3所示。
配置简单的DHCP中继_路由交换
10-3 DHCP中继配置
在本实验中,R1仍然担任DHCP服务器的角色,负责向PC所在网络和PC2所在网络的主机动态分配IP地址,所以,R1上需要定义两个地址池。整个网络运行RIPv2协议,确保网络IP连通性。
3.实验步骤
1)步骤1:配置路由器R1提供DHCP服务
R1(config)#interface gigabitEhternet0/0
R1(config-if)# no switchport
R1(config-if)#ip address 192.168.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config)#ip routing
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#no auto-summary
R1(config-router)#network 192.168.1.0
R1(config-router)# network 192.168.12.0
R1(config)#service dhcp                  
R1(config)#no ip dhcp conflict logging       //取消地址冲突记录
R1(config)#ip dhcp pool ccie               //定义第一个地址池
R1(dhcp-config)#network 192.168.1.0 /24  
R1(dhcp-config)#default-router 192.168.1.1
R1(dhcp-config)#domain-name cisco.com  

R1(dhcp-config)#netbios-name-server 192.168.1.2   
R1(dhcp-config)#dns-server 192.168.1.4           
R1(dhcp-config)#option 150 ip 192.168.1.3         
R1(dhcp-config)#lease infinite                    
R1(dhcp-config)#ip dhcp excluded-address 192.168.1.1 192.168.1.5
R1(config)#ip dhcp pool ccnp               //定义第二个地址池
R1(dhcp-config)#network 172.16.1.0 255.255.255.0  
R1(dhcp-config)#domain-name szpt.net  
R1(dhcp-config)#default-router 172.16.1.2
R1(dhcp-config)#netbios-name-server 192.168.1.2   
R1(dhcp-config)#dns-server 192.168.1.4           
R1(dhcp-config)#option 150 ip 192.168.1.3         
R1(dhcp-config)#lease infinite                    
R1(dhcp-config)#ip dhcp excluded-address 172.16.1.1 172.16.1.2
2)步骤2:配置路由器R2
 
R2(config)#interface gigabitEhternet0/0
R2(config-if)# no switchport
R2(config-if)#ip address 172.16.1.2 255.255.255.0
R2(config-if)#ip helper-address 192.168.12.1 //配置帮助地址
R2(config-if)#no shutdown
R2(config)#router rip
R2(config-router)#version 2
R2(config-router)#no auto-summary
R2(config-router)# network 192.168.12.0
R2(config-router)# network 172.16.0.0
【技术要点】路由器是不能转发”255.255.255.255”广播的,但是很多服务(如DHCPTFTP等)的客户请求都是以泛洪广播的方式发起的,我们不可能将每个网段都旋转这样的服务器,因此使用Cisco IOS帮助地址特性是很好的选择。通过使用帮助地址,路由器可以被配置为接受对UDP服务的广播请求,然后将之以单点传送的方式发给某个具体的IP地址,或者以定向广播形式向某个网段转发这些请求,这就是中继。
4.实验调试
1show ip dhcp binding
PC1PC2上自动获取IP地址后,在R1上执行:
R1#show ip dhcp binding
Bindings from all pools not associated with VRF;
IP address             Client-ID/    Lease expiration     Type

           Hardware address/
           Username
172.16.1.3             0100.6067.00dd.5b
192.168.1.6        0063.6973.636f.2d       Infinite          Automatic
192.168.1.7     0100.6067.00ef.31       Infinite          Automatic
以上输出表明两个地址池都为相应的网络上的主机分配了IP地址
2show ip dhcp pool
R1#show ip dhcp pool
Pool ccie;
 Utilization mark(high/low)    ;100/0
 Subnet size(first/next)        ;0/0
 Total addresses             ;254       
 Leased addresses            ;2        
 Pending event               ;none
 1 subnet is currently in the pool;
 Current index           IP address range                     Leased addresses
192.168.1.8              192.168.1.1       -192.168.1.254       2
Pool ccnp;
 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
172.16.1.4             172.16.1.1 -192.168.1.254              1
 
3debug ip dhcp server events
PC2上先执行”ipconfig/release”,再执行”ipconfig/renew”,显示如下:
R1#debug ip dhcp server
R1#clear ip dhcp binding *
*Feb 2 05;50;24.475;DHCPD;Sending notification of DISCOVER;
*Feb 2 05;50;24.475;DHCPD;htype 1 chaddr 0060.6700.dd5b
*Feb 2 05;50;24.475;DHCPD;circuit id 00000000
*Feb 2 05;50;24.475;DHCPD;Seeing if there is an internally specified pool class;
*Feb 2 05;50;24.475;DHCPD;htype 1 chaddr 0060.6700.dd5b
*Feb 2 05;50;24.475;DHCPD;circuit id 00000000
*Feb 2 05;50;26.475;DHCPD;client requests 172.16.1.4.
*Feb 2 05;50;26.475;DHCPD;Adding binding to radix tree (172.16.1.4)
*Feb 2 05;50;26.475;DHCPD;Adding binding to hash tree

*Feb 2 05;50;26.475;DHCPD;assigned IP address 172.16.1.4 to client 0100.6067.00dd.5b
*Feb 2 05;50;26.519;DHCPD;Sending notification of ASSIGNMENT;
*Feb 2 05;50;26.519;DHCPD;address 172.16.1.4 mask 255.255.255.0
*Feb 2 05;50;26.519;DHCPD;htype 1 chaddr 0060.6700.dd5b
*Feb 2 05;50;26.519;DHCPD;lease time remaining(secs)=4294967295
4show ip interface
R2#show ip interface gigabitEthernet0/0
GigabitEthernet0/0 is up line protocol is up
  Internet address is 172.16.1.2/24
  Broadcast address is 255.255.255.255
  Address determined by setup command
  MTU is 1500 bytes
  Helper address is 192.168.12.1
  ......
从以上输出看到gigabitEthernet0/0