前提:日常中,给大量的主机配置IP地址,如果手动一个一个的去配置,那是相当庞大的工作量,而且极易出错,故而选择服务器自动分配IP地址给主机
一,在路由器上配置
(一),直接配置:
基于接口的配置 G0/0/1 DHCP服务器:
[Huawei]interface g0/0/1 //进入接口
[Huawei-GigabitEthernet0/0/1]ip address 192.168.2.254 24 //给接口配置IP地址
[Huawei-GigabitEthernet0/0/1]dis this //查询当前的配置
[V200R003C00]
#
interface GigabitEthernet0/0/1
ip address 192.168.2.254 255.255.255.0
#
return
[Huawei-GigabitEthernet0/0/1]dhcp select interface //在接口上开启DHCP
[Huawei-GigabitEthernet0/0/1]dhcp server dns-list 8.8.8.8 //设置DNS服务器
[Huawei-GigabitEthernet0/0/1]dhcp server excluded-ip-address 192.168.2.200 192.1
68.2.253 设置排除的IP地址
[Huawei]dis ip pool interface GigabitEthernet0/0/1 used //查看已配置的IP地址
基于全局配置DHCP服务器:
[R2-DHCP]dhcp enable //开启dhcp 功能
[R2-DHCP]ip pool ntd2306 //创建IP地址池
[R2-DHCP-ip-pool-ntd2306]network 192.168.10.0 mask 24 //配置IP地址以及子网掩码
[R2-DHCP-ip-pool-ntd2306]gateway-list 192.168.10.254 //配置网关
[R2-DHCP-ip-pool-ntd2306]dns-list 8.8.8.8 //配置DNS服务器
[R2-DHCP-ip-pool-ntd2306]excluded-ip-address 192.168.10.253 //排除的IP地址
[R2-DHCP]int g0/0/0
[R2-DHCP-GigabitEthernet0/0/0]ip add 192.168.20.20 24 //给接口上配置IP地址
[R2-DHCP-GigabitEthernet0/0/0]dhcp select global //在接口上全局开启配置
(二),基于中继配置:
注意:这个基于中继的配置,只能是在全局配置,无法在接口上配置!
基于中继配置DHCP(服务器):
[r2]dhcp enable //开启DHCP服务器的配置
[r2]ip pool ntd2301 //创建IP地址池的名字 ntd2301
[r2-ip-pool-ntd2301]network 192.168.10.0 mask 24 //配置IP地址以及子网掩码
[r2-ip-pool-ntd2301]gateway-list 192.168.10.254 // 配置网关
[r2-ip-pool-ntd2301]dns-list 8.8.8.8 9.9.9.9 //配置DNS服务器的地址
[r2-ip-pool-ntd2301]excluded-ip-address 192.168.10.253 //配置排除的IP地址
[r2]interface g0/0/0
[r2-GigabitEthernet0/0/0]ip address 192.168.20.20 24 //给服务器连接中继的一段接口配置IP地址
[r2-GigabitEthernet0/0/0]dhcp select global //开启全局配置
在中继设备中的配置(中继):
1 [r1]sys r1-zj
2 [r1-zj]interface g0/0/1
3 [r1-zj-GigabitEthernet0/0/1]ip address 192.168.20.10 24 //给连接服务器的端口配置IP地址
4 [r1-zj]dhcp enable //开启DHCP服务配置
5 [r1-zj]interface g0/0/0
6 [r1-zj-GigabitEthernet0/0/0]ip address 192.168.10.254 24 //给连接PC主机一端的端口配置IP地址
7 [r1-zj-GigabitEthernet0/0/0]dhcp select relay //在这个接口下开启中继功能
8 [r1-zj-GigabitEthernet0/0/0]dhcp relay server-ip 192.168.20.20 //请求转发,指向DHCP服务器
最后发现,无法配置IP地址。原因是这个是跨网段配置IP地址,故而需要配置下一跳:
[r2]ip route-static 192.168.10.0 24 192.168.20.10 //配置下一跳
二,在交换机上配置(常用)
基于全局的DHCP配置:
2 <Huawei>u t m
3 [s1]sys s1-dhcp
4 [s1-dhcp]vlan batch 10 20
5 [s1-dhcp]port-group 1
6 [s1-dhcp-port-group-1]group-member g0/0/1 g0/0/2
7 [s1-dhcp-port-group-1]port link-type trunk
8 [s1-dhcp-port-group-1]port trunk allow-pass vlan all
9 [s1-dhcp]ip pool vlan10
10 [s1-dhcp-ip-pool-vlan10]network 192.168.10.0 mask 24
11 [s1-dhcp-ip-pool-vlan10]gateway-list 192.168.10.254
12 [s1-dhcp-ip-pool-vlan10]dns-list 8.8.8.8
13 [s1-dhcp]ip pool vlan20
14 [s1-dhcp-ip-pool-vlan20]network 192.168.20.0 mask 24
15 [s1-dhcp-ip-pool-vlan20]gateway-list 192.168.20.254
16 [s1-dhcp-ip-pool-vlan20]dns-list 8.8.8.8
17 [s1-dhcp]dhcp enable
18 [s1-dhcp]interface vlanif 10
19 [s1-dhcp-Vlanif10]ip address 192.168.10.254 24
20 [s1-dhcp-Vlanif10]dhcp select global
21 [s1-dhcp]interface vlanif 20
22 [s1-dhcp-Vlanif20]ip address 192.168.20.254 24
23 [s1-dhcp-Vlanif20]dhcp select global
1 [Huawei]sys s2
2 [s2]vlan batch 10 20
3 [s2-port-group-1]group-member g0/0/2 g0/0/3
4 [s2-port-group-1]port link-type access
5 [s2-port-group-1]port default vlan 10
6 [s2]interface g0/0/1
7 [s2-GigabitEthernet0/0/1]port link-type trunk
8 [s2-GigabitEthernet0/0/1]port trunk allow-pass vlan all
1 [Huawei]sys s3
2 [s3]vlan batch 10 20
3 [s3-port-group-1]group-member g0/0/1 g0/0/2
4 [s3-port-group-1]port link-type access
5 [s3-port-group-1]port default vlan 20
6 [s3]interface g0/0/3
7 [s3-GigabitEthernet0/0/3]port link-type trunk
8 [s3-GigabitEthernet0/0/3]port trunk allow-pass vlan all
基于接口配置的IP地址
在二层交换机的配置基本上都是这样,先就不做过多的赘述了!
1 [Huawei]sys s2
2 [s2]vlan batch 10 20
3 [s2-port-group-1]group-member g0/0/2 g0/0/3
4 [s2-port-group-1]port link-type access
5 [s2-port-group-1]port default vlan 10
6 [s2]interface g0/0/1
7 [s2-GigabitEthernet0/0/1]port link-type trunk
8 [s2-GigabitEthernet0/0/1]port trunk allow-pass vlan all