华为DHCP简单配置

前言

DHCP(Dynamic Host Configuration Protocol,动态主机配置协议是IETF为实现IP的自动配置而设计的协议,它可以为客户机自动分配IP地址、子网掩码以及缺省网关、DNS服务 器的IP地址等TCP/IP参数

实验目的

  • 通过SW1自动分配IP地址
  • 不同Vlan之间可以互通

常规配置

AR1

1
2
3
4
5
system-view 
undo info-center enable
interface GigabitEthernet0/0/0
ip address 10.1.1.1 255.255.255.0
ip route-static 192.168.0.0 255.255.0.0 10.1.1.2

SW1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
system-view 
undo info-center enable
vlan batch 10 20
interface Vlanif1
ip address 10.1.1.2 255.255.255.0
interface Vlanif10
ip address 192.168.1.1 255.255.255.0
interface Vlanif20
ip address 192.168.2.1 255.255.255.0
interface GigabitEthernet0/0/1
port link-type access
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 2 to 4094
interface GigabitEthernet0/0/3
port link-type trunk
port trunk allow-pass vlan 2 to 4094
ip route-static 0.0.0.0 0.0.0.0 10.1.1.1

SW2

1
2
3
4
5
6
7
8
9
10
11
12
13
system-view 
undo info-center enable
vlan batch 10 20
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
interface GigabitEthernet0/0/2
port link-type access
port default vlan 10
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20

SW3

1
2
3
4
5
6
7
8
9
10
11
12
system-view 
undo info-center enable
vlan batch 10 20
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
interface GigabitEthernet0/0/2
port link-type access
port default vlan 10
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20

DHCP配置

AR1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
dhcp enable
ip pool 1
gateway-list 192.168.1.1
network 192.168.1.0 mask 255.255.255.0
lease day 10 hour 0 minute 0
dns-list 114.114.114.114
ip pool 2
gateway-list 192.168.2.1
network 192.168.2.0 mask 255.255.255.0
lease day 10 hour 0 minute 0
dns-list 114.114.114.114

#开启DHCP全局模式
interface Vlanif10
dhcp select global
interface Vlanif10
dhcp select global

将PC设置成DHCP

2025_01_03_13_50_33.png

成功获取IP地址
2025_01_03_13_54_19.png