华为路由器与交换机配置DHCP

整理的关于华为DHCP方面的基本配置。

基于路由的全局配置

1
2
3
4
5
6
7
8
9
10
<huawei> sys
[huawei] ip pool test //建立地址池并命名
[Huawei-ip-pool-test] network 192.168.1.0 mask 24
[Huawei-ip-pool-test] gateway-list 192.168.1.254
[Huawei-ip-pool-test] dns-list 114.114.114.114
[Huawei-ip-pool-test] lease day 5 //指定租约时间(默认1天)
[Huawei-ip-pool-test] excluded-ip-address 192.168.1.200 192.168.1.254 //设置保留地址范围
[Huawei] dhcp enable
[Huawei-GigabitEthernet0/0/0] ip address 192.168.1.1 24
[Huawei-GigabitEthernet0/0/0] dhcp select global //接口下启用DHCP功能

基于接口的DHCP

1
2
3
4
5
6
7
8
[Huawei] dhcp enable
[Huawei] interface g0/0/0
[Huawei-GigabitEthernet0/0/0] ip address 192.168.2.1 24
[Huawei-GigabitEthernet0/0/0] dhcp select interface // 接口下启用DHCP功能
[Huawei-GigabitEthernet0/0/0] dhcp server dns-list 8.8.8.8
[Huawei-GigabitEthernet0/0/0] dhcp server lease day 5
[Huawei-GigabitEthernet0/0/0]dhcp server excluded-ip-address 192.168.2.200 192.1
68.2.254

DHCP中继

1
2
3
4
5
6
7
8
9
10
11
DHCP服务器配置
[Huawei] interface g0/0/0
[Huawei-GigabitEthernet0/0/0] ip address 1.1.1.1 24
[Huawei-GigabitEthernet0/0/0] ip route-static 192.168.3.0 24 1.1.1.2
[Huawei] ip pool test
[Huawei-ip-pool-test] network 192.168.3.0 mask 24
[Huawei-ip-pool-test] ateway-list 192.168.3.1
[Huawei-ip-pool-test] dns-list 8.8.8.8
[Huawei] dhcp enable
[Huawei]interface g0/0/0
[Huawei-GigabitEthernet0/0/0] dhcp select global
1
2
3
4
5
6
7
8
9
中继路由配置
[Huawei] interface g0/0/0
[Huawei-GigabitEthernet0/0/0] ip address 1.1.1.2 24
[Huawei-GigabitEthernet0/0/0] interface g0/0/1
[Huawei-GigabitEthernet0/0/1] ip address 192.168.3.1 24
[Huawei] dhcp enable
[Huawei] interface g0/0/1
[Huawei-GigabitEthernet0/0/1] dhcp select relay // 在接口上应用DHCP中继功能
[Huawei-GigabitEthernet0/0/1] dhcp relay server-ip 1.1.1.1 //指向DHCP服务器的IP地址

交换机配置DHCP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sw1的配置
[Huawei] hcp enable
[Huawei] ip pool test
[Huawei-ip-pool-test] network 192.168.1.0 mask 24
[Huawei-ip-pool-test] gateway-list 192.168.1.1
[Huawei-ip-pool-test1] dns-list 8.8.8.8
[Huawei-ip-pool-test1] lease day 5
[Huawei] vlan batch 10 20
[Huawei] interface Vlanif 10
[Huawei-Vlanif10] ip address 192.168.1.1 24
[Huawei-Vlanif10] hcp select global
[Huawei] interface Vlanif 20
[Huawei-Vlanif20] ip address 192.168.2.1 24
[Huawei-Vlanif20] dhcp select global
[Huawei-Vlanif20] interface g0/0/1
[Huawei-GigabitEthernet0/0/1] port link-type trunk
[Huawei-GigabitEthernet0/0/1] port trunk allow-pass vlan all
[Huawei-GigabitEthernet0/0/1] interface g0/0/2
[Huawei-GigabitEthernet0/0/2] port link-type trunk
[Huawei-GigabitEthernet0/0/2] port trunk allow-pass vlan all
1
2
3
4
5
6
7
8
9
sw2的配置
[Huawei] vlan batch 10 20
[Huawei] dhcp enable
[Huawei] interface e0/0/1
[Huawei-Ethernet0/0/1] port link-type access
[Huawei-Ethernet0/0/1] port default vlan 10
[Huawei-Ethernet0/0/1] interface g0/0/1
[Huawei-GigabitEthernet0/0/1] port link-type trunk
[Huawei-GigabitEthernet0/0/1] port trunk allow-pass vlan all
1
2
3
4
5
6
7
8
9
sw3的配置
[Huawei] vlan batch 10 20
[Huawei] dhcp enable
[Huawei] interface g0/0/1
[Huawei-GigabitEthernet0/0/1] port link-type trunk
[Huawei-GigabitEthernet0/0/1] port trunk allow-pass vlan all
[Huawei-GigabitEthernet0/0/1] interface e0/0/2
[Huawei-Ethernet0/0/2] port link-type access
[Huawei-Ethernet0/0/2] port default vlan 20

正常的话两个pc之间互相ping通。