实验过程:
第一步:基本配置
sw1(config)#int f2/1
sw1(config-if)#no sh
sw1(config-if)#spanning-tree portfast
第二步:在sw1上开启DHCP服务。
sw1(config)#service dhcp
//在全局下默认是关闭的
sw1(config)#no ip dhcp conflict logging
//关闭DHCP分配冲突,日志记录消息
sw1(config)#ip dhcp pool libo
//创建DHCP地址池,名称可是为任意字符
sw1(dhcp-config)#network 192.168.0.0 /24
//指定要通过dhcp分配的网段和掩码
sw1(dhcp-config)#default-router 192.168.0.1
//网关地址
sw1(dhcp-config)#domain-name www.cisco.com.cn
//dns域名
sw1(dhcp-config)#dns-server 218.30.19.40 61.134.1.4
//dns域名解析地址
sw1(dhcp-config)#lease infinite
//租期
sw1(dhcp-config)#exi
sw1(config)#ip dhcp excluded-address 192.168.0.1
sw1(config)#ip dhcp excluded-address 192.168.0.10
//排除地址
sw1(config)#int vlan 1
sw1(config-if)#ip add 192.168.0.1 255.255.255.0
sw1(config-if)#no sh
第四步:查看当前交换机配置文件
sw1#sh run | b ip dh
no ip dhcp conflict logging
ip dhcp excluded-address 192.168.0.1
ip dhcp excluded-address 192.168.0.10
!
ip dhcp pool libo
network 192.168.0.0 255.255.255.0
default-router 192.168.0.1
domain-name www.cisco.com.cn
dns-server 218.30.19.40 61.134.1.4
lease infinite
第五步:查看
当配置了接口的ip 为dhcp获取时
出现
R1#Interface Ethernet0/1 assigned DHCP address 192.168.0.2, mask 255.255.255.0
R1#sh ip in b
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 unassigned YES unset administratively down down
Ethernet0/1 192.168.0.2 YES DHCP up up
Ethernet0/2 unassigned YES unset administratively down down
sw1#sh ip dhcp pool libo
Pool libo :
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.3 192.168.0.1 - 192.168.0.254 1
sw1#sh 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.2 0063.6973.636f.2d63. Infinite Automatic
6366.332e.3065.6630.
2e30.3030.312d.4574.
302f.31