DHCP和DHCP中继
DHCP——动态主机配置协议,是一个局域网的网络协议,使用UDP协议工作
DHCP用途
1:给内部网络或网络服务供应商自动分配IP地址
2:给用户或内部网络管理员作为对所有计算机作*管理的手段
使用DHCP的好处
1:减少管理员的工作量
2:避免输入错误的可能
3:避免IP地址冲突
4:当更改IP地址段时,不需要重新配置每个用户的IP地址
5:提高了IP地址的利用率
6:方便客户端的配置
DHCP的IP地址自动获取工作原理
1:客户端在网络中搜索服务器
2:服务器向客户端响应服务
3:客户端向服务器发出服务请求
4:服务器像客户端提供服务
华为系统的DHCP服务器会按照由大到小的顺序从IP地址池里分配IP。
DHCP配置
一:接口模式
R2配置
The device is running!
<Huawei>
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable
Info: Information center is disabled.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 192.168.20.1 24
[Huawei-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[Huawei-GigabitEthernet0/0/0]q
[Huawei]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]dhcp select interface
[Huawei-GigabitEthernet0/0/0]dhcp server dns-list 8.8.8.8
分配结果
PC1
Welcome to use PC Simulator!
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe1e:46ee
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-1E-46-EE
DNS server........................: 8.8.8.8
PC2
Welcome to use PC Simulator!
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe79:7d9a
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.253
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-79-7D-9A
DNS server........................: 8.8.8.8
二:全局模式
R1
Please press enter to start cmd line!
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
Info: Information center is disabled.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 192.168.20.1 24
[Huawei-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 192.168.30.1 24
[Huawei-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[Huawei-GigabitEthernet0/0/1]q
[Huawei]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[Huawei]ip pool 1
Info:It's successful to create an IP address pool.
[Huawei-ip-pool-1]gateway-list 192.168.30.1
[Huawei-ip-pool-1]network 192.168.30.0 mask 24
[Huawei-ip-pool-1]dns-list 8.8.8.8
[Huawei-ip-pool-1]int g0/0/0
[Huawei-GigabitEthernet0/0/0]dhcp select global
[Huawei-GigabitEthernet0/0/0]q
[Huawei]ip pool 2
Info:It's successful to create an IP address pool.
[Huawei-ip-pool-2]gateway-list 192.168.20.1
[Huawei-ip-pool-2]network 192.168.20.0 mask 24
[Huawei-ip-pool-2]dns-list 114.114.114.114
[Huawei-ip-pool-2]int g0/0/1
[Huawei-GigabitEthernet0/0/1]dhcp select global
分配结果
PC1
Welcome to use PC Simulator!
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe99:54a3
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-99-54-A3
DNS server........................: 114.114.114.114
PC2
Welcome to use PC Simulator!
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe5f:6ad6
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.253
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-5F-6A-D6
DNS server........................: 114.114.114.114
PC3
Welcome to use PC Simulator!
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe54:4c81
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.30.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.30.1
Physical address..................: 54-89-98-54-4C-81
DNS server........................: 8.8.8.8
三:DHCP中继服务器
R1——中继服务器
The device is running!
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable
Info: Information center is disabled.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 192.168.20.1 24
[Huawei-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 192.168.30.1 24
[Huawei-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[Huawei-GigabitEthernet0/0/1]q
[Huawei]ip route-static 3.3.3.3 32 192.168.30.2
[Huawei]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]dhcp select relay
[Huawei-GigabitEthernet0/0/0]dhcp relay server-ip 192.168.30.2
R2——DHCP服务器
The device is running!
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable
Info: Information center is disabled.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 192.168.30.2 24
[Huawei-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[Huawei-GigabitEthernet0/0/0]int loop1
[Huawei-LoopBack1]ip add 3.3.3.3 32
[Huawei-LoopBack1]q
[Huawei]ip route-static 0.0.0.0 0 192.168.30.1
[Huawei]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[Huawei]ip pool 1
Info:It's successful to create an IP address pool.
[Huawei-ip-pool-1]gateway-list 192.168.20.1
[Huawei-ip-pool-1]network 192.168.20.0 mask 24
[Huawei-ip-pool-1]dns-list 8.8.8.8
[Huawei-ip-pool-1]int g0/0/0
[Huawei-GigabitEthernet0/0/0]dhcp select global
分配结果
PC1
Welcome to use PC Simulator!
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe12:51ac
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-12-51-AC
DNS server........................: 8.8.8.8
PC2
Welcome to use PC Simulator!
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fedb:52e5
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.253
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-DB-52-E5
DNS server........................: 8.8.8.8