动态主机配置协议DHCP(Dynamic HostConfiguration Protocol)采用客户端/服务器模式对用户的网络参数进行动态配置和集中管理。其中,DHCP服务器通过地址池为用户分配IP地址等网络参数。地址池分为接口地址池和全局地址池两种。
接口地址池配置方式简单,只能用于用户与DHCP服务器在同一个网段的场景,并且只能给对应接口下的用户分配IP地址等网络参数;适用于设备数量有限、配置以及维护量可控的小型网络。在用户网关设备上配置基于接口地址池的DHCP服务器功能之后,对应接口下的固定主机、移动终端等都可以自动获取IP地址等网络参数,不需要用户手动配置修改。
与接口地址池相比,全局地址池可应用于大型网络,推荐在核心层设备上配置基于全局地址池的DHCP服务器功能或在服务器区域搭建一台专门的DHCP服务器统一分配IP地址等网络参数,而用户网关设备上只需要启用简单的DHCP中继功能即可,具体可参见配置设备作为DHCP中继示例(中继与服务器处于同一网络)。
组网需求
如图1所示,某企业内的一台主机通过Switch双归属到SwitchA和SwitchB,SwitchA为主设备,作为DHCP服务器为客户端分配IP地址。现用户希望当主设备故障时,客户端能够通过备设备重新获取IP地址。
图1 VRRP组网下同网段内配置基于全局地址池的DHCP服务器组网图
配置思路
VRRP组网下同网段内配置基于全局地址池的DHCP服务器,配置思路如下:
配置SwitchA和SwitchB设备上接口IP地址,使各设备间网络层连通;同时配置Switch上的二层透传功能。
在SwitchA和SwitchB上配置VRRP备份组。其中,SwitchA上配置较高优先级,作为Master设备为客户端分配IP地址;SwitchB上配置较低优先级,作为备用交换机。
在SwitchA和SwitchB上创建全局地址池,并配置地址池相关属性。
操作步骤
<HUAWEI> system-view
[HUAWEI] sysnameSwitchA
[SwitchA] vlanbatch 100
[SwitchA] interfacegigabitethernet 0/0/2
[SwitchA-GigabitEthernet0/0/2]port link-type hybrid
[SwitchA-GigabitEthernet0/0/2]port hybrid pvid vlan 100
[SwitchA-GigabitEthernet0/0/2]port hybrid untagged vlan 100
[SwitchA-GigabitEthernet0/0/2]quit
[SwitchA] interfacegigabitethernet 0/0/5
[SwitchA-GigabitEthernet0/0/5]port link-type hybrid
[SwitchA-GigabitEthernet0/0/5]port hybrid pvid vlan 100
[SwitchA-GigabitEthernet0/0/5]port hybrid untagged vlan 100
[SwitchA-GigabitEthernet0/0/5]quit
[SwitchA] interfacevlanif 100
[SwitchA-Vlanif100]ip address 10.1.1.1 24
[SwitchA-Vlanif100]quit
<HUAWEI> system-view
[HUAWEI] sysnameSwitch
[Switch] vlan100
[Switch-vlan100] quit
[Switch] interfacegigabitethernet 0/0/1
[Switch-GigabitEthernet0/0/1]port link-type hybrid
[Switch-GigabitEthernet0/0/1]port hybrid pvid vlan 100
[Switch-GigabitEthernet0/0/1]port hybrid untagged vlan 100
[Switch-GigabitEthernet0/0/1]quit
[Switch] interfacegigabitethernet 0/0/2
[Switch-GigabitEthernet0/0/2]port link-type hybrid
[Switch-GigabitEthernet0/0/2]port hybrid pvid vlan 100
[Switch-GigabitEthernet0/0/2]port hybrid untagged vlan 100
[Switch-GigabitEthernet0/0/2]quit
[Switch] interfacegigabitethernet 0/0/3
[Switch-GigabitEthernet0/0/3]port link-type access
[Switch-GigabitEthernet0/0/3]port default vlan 100
[Switch-GigabitEthernet0/0/3]quit
[SwitchA] dhcpenable
说明:
由于交换机主设备上的地址池信息不能实时备份到备设备上,为防止主备切换后出现IP地址分配冲突,主设备和备设备上配置的地址池必须要互相排除。
[SwitchA] ippool 1
[SwitchA-ip-pool-1]network 10.1.1.0 mask 255.255.255.0
[SwitchA-ip-pool-1]gateway-list 10.1.1.111
[SwitchA-ip-pool-1]excluded-ip-address 10.1.1.1
[SwitchA-ip-pool-1]excluded-ip-address 10.1.1.129 10.1.1.254
[SwitchA-ip-pool-1]lease day 10
[SwitchA-ip-pool-1]quit
[SwitchB] dhcpenable
[SwitchB] ippool 1
[SwitchB-ip-pool-1]network 10.1.1.0 mask 255.255.255.0
[SwitchB-ip-pool-1]gateway-list 10.1.1.111
[SwitchB-ip-pool-1]excluded-ip-address 10.1.1.1 10.1.1.110
[SwitchB-ip-pool-1]excluded-ip-address 10.1.1.112 10.1.1.129
[SwitchB-ip-pool-1]lease day 10
[SwitchB-ip-pool-1]quit
[SwitchA] interfacevlanif 100
[SwitchA-Vlanif100]vrrp vrid 1 virtual-ip 10.1.1.111
[SwitchA-Vlanif100]vrrp vrid 1 priority 120
[SwitchA-Vlanif100]dhcp select global
[SwitchA-Vlanif100]quit
[SwitchB] interfacevlanif 100
[SwitchB-Vlanif100]vrrp vrid 1 virtual-ip 10.1.1.111
[SwitchB-Vlanif100]dhcp select global
[SwitchB-Vlanif100]quit
[Switch] stpenable
[Switch] interfacegigabitethernet 0/0/3
[Switch-GigabitEthernet0/0/3]stp disable
[Switch-GigabitEthernet0/0/3]quit
[Switch] interfacegigabitethernet 0/0/1
[Switch-GigabitEthernet0/0/1]stp cost 20000
[Switch-GigabitEthernet0/0/1]quit
[SwitchA] displayvrrp
Vlanif100 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.111
Master IP : 10.1.1.1
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Backup-forward : disabled
Create time : 2017-01-12 20:15:46
Last change time : 2017-01-12 20:15:46
[SwitchB] displayvrrp
Vlanif100 | Virtual Router 1
State : Backup
Virtual IP : 10.1.1.111
Master IP : 10.1.1.1
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 120
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Backup-forward : disabled
Create time : 2017-01-12 20:15:46
Last change time : 2017-01-12 20:15:46
[SwitchA] displayip pool
Pool-name : 1
Pool-No : 0
Lease : 10 Days 0 Hours 0 Minutes
Position : Local
Status : Unlocked
Gateway-0 : 10.1.1.111
Network : 10.1.1.0
Mask : 255.255.255.0
*** instance : --
Conflicted address recycle interval: -
Address Statistic: Total :253 Used :1
Idle :125 Expired :0
Conflict :0 Disable :127
IP address Statistic
Total :253
Used :1 Idle :125
Expired :0 Conflict :0 Disable :127
[SwitchB] displayip pool
Pool-name : 1
Pool-No : 0
Lease : 10 Days 0 Hours 0 Minutes
Position : Local
Status : Unlocked
Gateway-0 : 10.1.1.111
Network : 10.1.1.0
Mask : 255.255.255.0
*** instance : --
Conflicted address recycle interval: -
Address Statistic: Total :253 Used :0
Idle :125 Expired :0
Conflict :0 Disable :128
IP address Statistic
Total :253
Used :0 Idle :125
Expired :0 Conflict :0 Disable :128
[SwitchA] interfacegigabitethernet 0/0/2
[SwitchA-GigabitEthernet0/0/2]shutdown
[SwitchA-GigabitEthernet0/0/2]quit
[SwitchA] interfacegigabitethernet 0/0/5
[SwitchA-GigabitEthernet0/0/5]shutdown
[SwitchA-GigabitEthernet0/0/5]quit
[SwitchA] displayvrrp
Vlanif100 | Virtual Router 1
State : Initialize
Virtual IP : 10.1.1.111
Master IP : 0.0.0.0
PriorityRun : 120
PriorityConfig : 120
MasterPriority : 0
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Backup-forward : disabled
Create time : 2017-01-12 20:15:46
Last change time : 2017-01-12 20:15:46
[SwitchB] displayvrrp
Vlanif100 | Virtual Router 1
State : Master
Virtual IP : 10.1.1.111
Master IP : 10.1.1.129
PriorityRun : 100
PriorityConfig : 100
MasterPriority : 100
Preempt : YES Delay Time : 0 s
TimerRun : 1 s
TimerConfig : 1 s
Auth type : NONE
Virtual MAC : 0000-5e00-0101
Check TTL : YES
Config type : normal-vrrp
Backup-forward : disabled
Create time : 2017-01-12 20:15:46
Last change time : 2017-01-12 20:15:46
[SwitchB] displayip pool
Pool-name : 1
Pool-No : 0
Lease : 10 Days 0 Hours 0 Minutes
Position : Local
Status : Unlocked
Gateway-0 : 10.1.1.111
Network : 10.1.1.0
Mask : 255.255.255.0
*** instance : --
Conflicted address recycle interval: -
Address Statistic: Total :253 Used :1
Idle :124 Expired :0
Conflict :0 Disabled :128
IP address Statistic
Total :253
Used :1 Idle :124
Expired :0 Conflict :0 Disabled :128
配置文件
· SwitchA的配置文件
#
sysname SwitchA
#
vlan batch 100
#
dhcp enable
#
ip pool 1
gateway-list 10.1.1.111
network 10.1.1.0 mask 255.255.255.0
excluded-ip-address 10.1.1.1
excluded-ip-address 10.1.1.129 10.1.1.254
lease day 10 hour 0 minute 0
#
interface Vlanif100
ip address 10.1.1.1 255.255.255.0
vrrp vrid 1 virtual-ip 10.1.1.111
vrrp vrid 1 priority 120
dhcp select global
#
interface GigabitEthernet0/0/2
port link-type hybrid
port hybrid pvid vlan 100
port hybrid untagged vlan 100
#
interface GigabitEthernet0/0/5
port link-type hybrid
port hybrid pvid vlan 100
port hybrid untagged vlan 100
#
return
· SwitchB的配置文件
#
sysname SwitchB
#
vlan batch 100
#
dhcp enable
#
ip pool 1
gateway-list 10.1.1.111
network 10.1.1.0 mask 255.255.255.0
excluded-ip-address 10.1.1.1 10.1.1.110
excluded-ip-address 10.1.1.112 10.1.1.129
lease day 10 hour 0 minute 0
#
interface Vlanif100
ip address 10.1.1.129 255.255.255.0
vrrp vrid 1 virtual-ip 10.1.1.111
dhcp select global
#
interface GigabitEthernet0/0/2
port link-type hybrid
port hybrid pvid vlan 100
port hybrid untagged vlan 100
#
interface GigabitEthernet0/0/5
port link-type hybrid
port hybrid pvid vlan 100
port hybrid untagged vlan 100
#
return
· Switch的配置文件
#
sysname Switch
#
vlan batch 100
#
interface GigabitEthernet0/0/1
port link-type hybrid
port hybrid pvid vlan 100
port hybrid untagged vlan 100
stp instance 0 cost 20000
#
interface GigabitEthernet0/0/2
port link-type hybrid
port hybrid pvid vlan 100
port hybrid untagged vlan 100
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 100
stp disable
#
return
扫描二维码关注微信公众号:网络民工 了解更多内容
原文:https://blog.51cto.com/jiajunjie/2473846