首页 > 窍门 > 科技数码

在三层交换机配置DHCP的方法分享(3层交换机dhcp划分)

来源: 更新时间:2024-04-09 00:10:22
The Beginning

通过本实验掌握,如何在Cisco Catalyst 3550交换机来配置DHCP服务,实现对内网主机分配IP地址,网关,DNS,WINS,租期,域名等。可能你之前是在windows Server服务器或者Cisco Router 部署过DHCP,但在工程项目中,根据需求,大多是在接入层或者汇聚层多层交换机来配置的,可以同时实现DHCP Snooping等技术。uCw育儿早教网

在三层交换机配置DHCP的方法分享uCw育儿早教网

实验过程:uCw育儿早教网

第一步:Catalyst 3550底层配置uCw育儿早教网
Switch(config)#no ip do louCw育儿早教网
Switch(config)#line con 0uCw育儿早教网
Switch(config-line)#no exec-tuCw育儿早教网
Switch(config-line)#logg synuCw育儿早教网
Switch(config-line)#host Switch_DhcpuCw育儿早教网
Switch_Dhcp(config)#int f0/1uCw育儿早教网
Switch_Dhcp(config-if)#no shuCw育儿早教网
Switch_Dhcp(config-if)#spanning-tree portfastuCw育儿早教网
//连接终端的接口下,开启portfast特性,跳过生成树的选举,接口立即进入转发状态uCw育儿早教网
%Warning: portfast should only be enabled on ports connected to a singleuCw育儿早教网
host. Connecting hubs, concentrators, switches, bridges, etc... to thisuCw育儿早教网
interface when portfast is enabled, can cause temporary bridging loops.uCw育儿早教网
Use with CAUTIONuCw育儿早教网
%Portfast has been configured on FastEthernet0/1 but will onlyuCw育儿早教网
have effect when the interface is in a non-trunking mode.uCw育儿早教网
Switch_Dhcp(config-if)#enduCw育儿早教网
第二步: 开启DHCP服务,定义分配地址池范围及掩码,网关,DNS,域名,租期等uCw育儿早教网
//全局下开启DHCP服务,该服务默认是关闭的uCw育儿早教网
Switch_Dhcp(config)#service dhcpuCw育儿早教网
//关闭DHCP分配冲突,日志记录消息uCw育儿早教网
Switch_Dhcp(config)#no ip dhcp conflict logginguCw育儿早教网
//创建DHCP地址池,名称为可以是任意字符uCw育儿早教网
Switch_Dhcp(config)#ip dhcp pool ciscouCw育儿早教网
//指定要通过DHCP分配的网段和掩码,还有另外一种写法(192.168.0.0 255.255.255.0)uCw育儿早教网
Switch_Dhcp(dhcp-config)#network 192.168.0.0 /24uCw育儿早教网
//指定分配的网关地址uCw育儿早教网
Switch_Dhcp(dhcp-config)#default-router 192.168.0.1uCw育儿早教网
//指定DHCP域名,域名可以为任意字符uCw育儿早教网
Switch_Dhcp(dhcp-config)#domain-name www.cisco.com.cnuCw育儿早教网
//指定PC通过DHCP分配到DNS地址,(这里指定的是当地电信部门的真实地址,全国各地市不一样的)uCw育儿早教网
Switch_Dhcp(dhcp-config)#dns 218.30.19.40 61.134.1.4uCw育儿早教网
//netbios服务器地址,可选的配置uCw育儿早教网
Switch_Dhcp(dhcp-config)#netbios-name-server 192.168.0.10uCw育儿早教网
//指定通过DHCP分配到地址,租期为永久uCw育儿早教网
Switch_Dhcp(dhcp-config)#lease infiniteuCw育儿早教网
Switch_Dhcp(dhcp-config)#enduCw育儿早教网
//指定不通过DHCP 地址池中分配的地址,也就是排除的地址。如果这些地址被分配给PC使用,就有可能造成网络中IP地址冲突。如:192.168.0.1 是网关地址,该地址只能是分配所有PC做网关地址,不能做IP地址使用。所以要排除。uCw育儿早教网
Switch_Dhcp(config)#ip dhcp excluded-address 192.168.0.1uCw育儿早教网
Switch_Dhcp(config)# ip dhcp excluded-address 192.168.0.10uCw育儿早教网
第三步:查看VLAN信息,并启用SVI接口uCw育儿早教网

复制代码uCw育儿早教网
uCw育儿早教网
代码如下:uCw育儿早教网

Switch_Dhcp#show vlan briefuCw育儿早教网
VLAN Name Status PortsuCw育儿早教网
---- -------------------------------- --------- -------------------------------uCw育儿早教网
1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4uCw育儿早教网
Fa0/5, Fa0/6, Fa0/7, Fa0/8uCw育儿早教网
Fa0/9, Fa0/10, Fa0/11, Fa0/12uCw育儿早教网
Fa0/13, Fa0/15, Fa0/16, Fa0/17uCw育儿早教网
Fa0/18, Fa0/19, Fa0/20, Fa0/21uCw育儿早教网
Fa0/22, Fa0/23, Fa0/24, Gi0/1uCw育儿早教网
Gi0/2uCw育儿早教网
1002 fddi-default act/unsupuCw育儿早教网
1003 token-ring-default act/unsupuCw育儿早教网
1004 fddinet-default act/unsupuCw育儿早教网
1005 trnet-default act/unsupuCw育儿早教网
Switch_Dhcp#conf tuCw育儿早教网
Enter configuration commands, one per line. End with CNTL/Z.uCw育儿早教网
//进入管理VLAN1 下,启用SVI功能uCw育儿早教网
Switch_Dhcp(config)#int vlan 1uCw育儿早教网
//配置VLAN的地址为192.168.0.1 掩码为24位,默认情况下Cisco Catalyst交换机所有的物理接口都属于VLAN1,此地址也就是PC网关地址。uCw育儿早教网
Switch_Dhcp(config-if)#ip add 192.168.0.1 255.255.255.0uCw育儿早教网
Switch_Dhcp(config-if)#no shuCw育儿早教网
Switch_Dhcp(config-if)#enduCw育儿早教网
Switch_Dhcp#uCw育儿早教网
00:09:07: %SYS-5-CONFIG_I: Configured from console by consoleuCw育儿早教网
Switch_Dhcp#uCw育儿早教网
00:09:08: %LINK-3-UPDOWN: Interface Vlan1, changed state to upuCw育儿早教网
00:09:09: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state touCw育儿早教网

第四步:查看当前交换机配置文件uCw育儿早教网

复制代码uCw育儿早教网
uCw育儿早教网
代码如下:uCw育儿早教网

//验证DHCP的配置信息uCw育儿早教网
Switch_Dhcp#sh run | begin ip dhcpuCw育儿早教网
no ip dhcp conflict logginguCw育儿早教网
ip dhcp excluded-address 192.168.0.1uCw育儿早教网
ip dhcp excluded-address 192.168.0.10uCw育儿早教网
!uCw育儿早教网
ip dhcp pool ciscouCw育儿早教网
network 192.168.0.0 255.255.255.0uCw育儿早教网
default-router 192.168.0.1uCw育儿早教网
domain-name www.cisco.com.cnuCw育儿早教网
dns-server 218.30.19.40 61.134.1.4uCw育儿早教网
netbios-name-server 192.168.0.10uCw育儿早教网
lease infiniteuCw育儿早教网
interface Vlan1uCw育儿早教网
ip address 192.168.0.1 255.255.255.0uCw育儿早教网

第五步:此时将PC1的网线插入Catalyst 3550 的F0/1接口,并在PC上查看IP地址获得信息。PC上的本地连接,TCP/IP 设置为自动获得IP地址形式。uCw育儿早教网
PC上查看方法:开始-运行-cmd-ipconfig/alluCw育儿早教网

在三层交换机配置DHCP的方法分享uCw育儿早教网

从以上信息可以得出,PC已经能从DHCP服务器获得IP地址等信息,实验现象成功。uCw育儿早教网

第六步:查看交换机DHCP 动态绑定,以及交换机DHCP Server状态信息uCw育儿早教网

复制代码uCw育儿早教网
uCw育儿早教网
代码如下:uCw育儿早教网

//查看DHCP动态绑定信息,从这里可以看到PC,从DHCP地址池中的得到IP地址,以及PC的MAC地址等uCw育儿早教网
Switch_Dhcp#show ip dhcp bindinguCw育儿早教网
IP address Client-ID/ Lease expiration TypeuCw育儿早教网
Hardware addressuCw育儿早教网
192.168.0.2 0100.16d3.249f.fd Infinite AutomaticuCw育儿早教网
//查看DHCP服务器工作状态uCw育儿早教网
Switch_Dhcp#show ip dhcp server statisticsuCw育儿早教网
Memory usage 5661uCw育儿早教网
Address pools 1uCw育儿早教网
Database agents 0uCw育儿早教网
Automatic bindings 1uCw育儿早教网
Manual bindings 0uCw育儿早教网
Expired bindings 0uCw育儿早教网
Malformed messages 0uCw育儿早教网
Message ReceiveduCw育儿早教网
BOOTREQUEST 0uCw育儿早教网
DHCPDISCOVER 2uCw育儿早教网
DHCPREQUEST 3uCw育儿早教网
DHCPDECLINE 0uCw育儿早教网
DHCPRELEASE 0uCw育儿早教网
DHCPINFORM 3uCw育儿早教网
Message SentuCw育儿早教网
BOOTREPLY 0uCw育儿早教网
DHCPOFFER 2uCw育儿早教网
DHCPACK 6uCw育儿早教网
DHCPNAK 0uCw育儿早教网
Switch_Dhcp#uCw育儿早教网
Switch_Dhcp#clear ip dhcp binding *uCw育儿早教网

第七步:使用debug 调试命令查看PC申请IP地址过程(DHCP工作过程)uCw育儿早教网
在PC上:开始-运行-cmd-ipconfig /release (释放获得IP地址)uCw育儿早教网
重新申请IP地址ipconfig /renewuCw育儿早教网
此时查看交换机日志信息uCw育儿早教网

复制代码uCw育儿早教网
uCw育儿早教网
代码如下:uCw育儿早教网

Switch_Dhcp#debug ip dhcp server eventsuCw育儿早教网
01:13:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upuCw育儿早教网
Switch_Dhcp#uCw育儿早教网
01:13:13: DHCPD: DHCPDISCOVER received from client 0100.16d3.249f.fd on interface Vlan1.uCw育儿早教网
Switch_Dhcp#uCw育儿早教网
01:13:20: DHCPD: assigned IP address 192.168.0.3 to client 0100.16d3.249f.fd.uCw育儿早教网
01:13:20: DHCPD: Sending DHCPOFFER to client 0100.16d3.249f.fd (192.168.0.3).uCw育儿早教网
01:13:20: DHCPD: broadcasting BOOTREPLY to client 0016.d324.9ffd.uCw育儿早教网
01:13:20: DHCPD: DHCPREQUEST received from client 0100.16d3.249f.fd.uCw育儿早教网
01:13:20: DHCPD: Sending DHCPACK to client 0100.16d3.249f.fd (192.168.0.3).uCw育儿早教网
01:13:20: DHCPD: broadcasting BOOTREPLY to client 0016.d324.9ffd.uCw育儿早教网
Switch_Dhcp#uCw育儿早教网
01:13:23: DHCPD: DHCPINFORM received from client 0100.16d3.249f.fd (192.168.0.3).uCw育儿早教网
01:13:23: DHCPD: Sending DHCPACK to client 0100.16d3.249f.fd (192.168.0.3).uCw育儿早教网
01:13:23: DHCPD: unicasting BOOTREPLY to client 0016.d324.9ffd (192.168.0.3).uCw育儿早教网

本文出自 “王万利的博客” 博客uCw育儿早教网

THE END

TAG:地址  交换机  分配  

猜你喜欢

相关文章