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服務器

掃描二維碼關注微信公衆號:網絡民工 瞭解更多內容

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章