VRRP组网下同网段内配置基于全局地址池的DHCP服务器

DHCP服务器简介
通常用户希望网络中的每台终端能够动态获取IP地址、DNS服务器的IP地址、路由信息、网关信息等网络参数,不需要手动配置终端的IP地址等网络参数;另外,针对一些移动终端(手机、ipad、办公笔记本等)希望能够即插即用,不需要每次修改终端的IP等网络参数。如果用户网络中有这些需求,就可以在汇聚层的用户网关设备或核心层设备上配置DHCP服务器功能,来给终端分配IP地址等网络参数。

动态主机配置协议DHCP(Dynamic HostConfiguration Protocol)采用客户端/服务器模式对用户的网络参数进行动态配置和集中管理。其中,DHCP服务器通过地址池为用户分配IP地址等网络参数。地址池分为接口地址池和全局地址池两种。

接口地址池配置方式简单,只能用于用户与DHCP服务器在同一个网段的场景,并且只能给对应接口下的用户分配IP地址等网络参数;适用于设备数量有限、配置以及维护量可控的小型网络。在用户网关设备上配置基于接口地址池的DHCP服务器功能之后,对应接口下的固定主机、移动终端等都可以自动获取IP地址等网络参数,不需要用户手动配置修改。

与接口地址池相比,全局地址池可应用于大型网络,推荐在核心层设备上配置基于全局地址池的DHCP服务器功能或在服务器区域搭建一台专门的DHCP服务器统一分配IP地址等网络参数,而用户网关设备上只需要启用简单的DHCP中继功能即可,具体可参见配置设备作为DHCP中继示例(中继与服务器处于同一网络)。

组网需求

如图1所示,某企业内的一台主机通过Switch双归属到SwitchA和SwitchB,SwitchA为主设备,作为DHCP服务器为客户端分配IP地址。现用户希望当主设备故障时,客户端能够通过备设备重新获取IP地址。

VRRP组网下同网段内配置基于全局地址池的DHCP服务器
图1 VRRP组网下同网段内配置基于全局地址池的DHCP服务器组网图

配置思路

VRRP组网下同网段内配置基于全局地址池的DHCP服务器,配置思路如下:

  1. 配置SwitchA和SwitchB设备上接口IP地址,使各设备间网络层连通;同时配置Switch上的二层透传功能。

  2. 在SwitchA和SwitchB上配置VRRP备份组。其中,SwitchA上配置较高优先级,作为Master设备为客户端分配IP地址;SwitchB上配置较低优先级,作为备用交换机。

  3. 在SwitchA和SwitchB上创建全局地址池,并配置地址池相关属性。

  4. 在SwitchA、SwitchB和Switch上配置破环协议,防止环路的产生(此处以配置STP为例)。

操作步骤

  1. 配置设备间的网络互连

配置设备各接口的IP地址,以SwitchA为例。SwitchB的配置与SwitchA类似,详见配置文件。

<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

配置Switch的二层透传功能。

<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

  1. 创建地址池并配置相关属性

在SwitchA上启动DHCP服务。

[SwitchA] dhcpenable

在SwitchA上创建地址池,配置地址池范围是10.1.1.2~10.1.1.128,和SwitchB上配置的地址池地址互相排除。

说明:

由于交换机主设备上的地址池信息不能实时备份到备设备上,为防止主备切换后出现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上创建地址池,配置地址池范围是10.1.1.130~10.1.1.254,和SwitchA上配置的地址池地址互相排除。

[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

  1. 配置VRRP备份组

在SwitchA上创建VRRP备份组1,配置SwitchA在该备份组中的优先级为120,并配置客户端从全局地址池中获取IP地址。

[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上创建VRRP备份组1,其在该备份组中的优先级为缺省值100,并配置客户端从全局地址池中获取IP地址。

[SwitchB] interfacevlanif 100

[SwitchB-Vlanif100]vrrp vrid 1 virtual-ip 10.1.1.111

[SwitchB-Vlanif100]dhcp select global

[SwitchB-Vlanif100]quit

  1. 配置STP协议,实现破除环路

在Switch上全局使能STP功能,SwitchA和SwitchB的配置与之类似,详见配置文件。

[Switch] stpenable

在Switch的GE0/0/3接口上去使能STP并将端口GE0/0/1的路径开销值配置为20000。

[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

  1. 验证配置结果

完成上述配置以后,在SwitchA和SwitchB上分别执行display vrrp命令,可以看到SwitchA在备份组中的状态为Master,SwitchB在备份组中的状态为Backup。

[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和SwitchB上使用display ip pool命令用来查看地址池中的IP地址分配情况,可以看到作为主设备的SwitchA成功为DHCP客户端分配了IP地址,而作为备设备的SwitchB则没有为DHCP客户端分配IP地址。以下显示信息以V200R011C10版本为例。

[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的接口GE0/0/2和接口GE0/0/5上执行shutdown命令,模拟SwitchA出现故障。

[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和SwitchB上分别执行display vrrp命令,可以看到SwitchA在备份组中的状态为Initialize,SwitchB在备份组中的状态为Master。

[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上使用display ip pool命令用来查看IP地址池配置情况。以下显示信息以V200R011C10版本为例。

[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
VRRP组网下同网段内配置基于全局地址池的DHCP服务器

扫描二维码关注微信公众号:网络民工 了解更多内容

猜你喜欢

转载自blog.51cto.com/jiajunjie/2473846