实验室要求主机无需手动配置ip地址,只要连接网线,即可自动获取IP地址。实验室的交换机用的是H3C,下面通过控制台在华三交换机上配置DHCP服务。
1. 连接交换机
通过ssh连接交换机
2. 进入系统视图
<H3C>system-view
3. 启用dhcp服务
[H3C]dhcp enable
4. 进行dhcp服务配置
4.1 配置地址池
# 设置ip地址池名字,vlan1-dhcp是我设置的名字,可根据自己情况设置
[H3C]dhcp server ip-pool vlan1-dhcp
# 配置ip,掩码
[H3C-dhcp-pool-vlan1-dhcp]network 192.168.0.1 mask 255.255.254.0
#配置网关
[H3C-dhcp-pool-vlan1-dhcp]gateway-list 192.168.0.1
#配置起始地址范围
[H3C-dhcp-pool-vlan1-dhcp]address range 192.168.0.30 192.168.1.254
#配置dns
[H3C-dhcp-pool-vlan1-dhcp]dns-list 114.114.114.114
#查看配置
[H3C-dhcp-pool-vlan1-dhcp]dis this
#
dhcp server ip-pool vlan1-dhcp
gateway-list 192.168.0.1
network 192.168.0.0 mask 255.255.254.0
address range 192.168.0.30 192.168.1.254
dns-list 192.168.0.1
#
return
#设置保留地址,不参与自动分配的ip段(可选)
[H3C-dhcp-pool-vlan1-dhcp]dhcp server forbidden-ip 192.168.0.1 192.168.0.30
补充:undo dhcp server forbidden-ip 192.168.0.2 192.168.0.30 #删除禁止的ip
#退出
[H3C-dhcp-pool-vlan1-dhcp]quit
4.2 将地址池应用到接口
#将ip地址池应用到vlan接口
[H3C]vlan 1 #创建vlan 1,如果已有vlan接口可不执行此步
[H3C]interface vlan-interface 1 #进入vlan 1 接口
[H3C-Vlan-interface1]dhcp server apply ip-pool vlan1-dhcp
[H3C-Vlan-interface1]dis this
#
interface Vlan-interface1
ip address 192.168.0.1 255.255.254.0
dhcp server apply ip-pool vlan1-dhcp
#
return
[H3C-Vlan-interface1]quit
至此,交换机的dhcp服务已配置完成,连接此交换机的主机可通过DHCP方式获取ip地址。
其他
#设置ip租约期限
[H3C-dhcp-pool-vlan1-dhcp]expired day 2
#删除dhcp地址池
[H3C]undo dhcp server ip-pool pool_name
#显示vlan信息
[H3C]display vlan
#删除地址池
[H3C]undo dhcp server ip-pool vlan1-dhcp
#关闭DHCP功能:
[H3C] undo dhcp enable