DHCP服務器簡介
一般用戶但願網絡中的每臺終端可以動態獲取IP地址、DNS服務器的IP地址、路由信息、網關信息等網絡參數,不須要手動配置終端的IP地址等網絡參數;另外,針對一些移動終端(手機、ipad、辦公筆記本等)但願可以即插即用,不須要每次修改終端的IP等網絡參數。若是用戶網絡中有這些需求,就能夠在匯聚層的用戶網關設備或核心層設備上配置DHCP服務器功能,來給終端分配IP地址等網絡參數。服務器
動態主機配置協議DHCP(Dynamic HostConfiguration Protocol)採用客戶端/服務器模式對用戶的網絡參數進行動態配置和集中管理。其中,DHCP服務器經過地址池爲用戶分配IP地址等網絡參數。地址池分爲接口地址池和全局地址池兩種。微信
接口地址池配置方式簡單,只能用於用戶與DHCP服務器在同一個網段的場景,而且只能給對應接口下的用戶分配IP地址等網絡參數;適用於設備數量有限、配置以及維護量可控的小型網絡。在用戶網關設備上配置基於接口地址池的DHCP服務器功能以後,對應接口下的固定主機、移動終端等均可以自動獲取IP地址等網絡參數,不須要用戶手動配置修改。網絡
與接口地址池相比,全局地址池可應用於大型網絡,推薦在覈心層設備上配置基於全局地址池的DHCP服務器功能或在服務器區域搭建一臺專門的DHCP服務器統一分配IP地址等網絡參數,而用戶網關設備上只須要啓用簡單的DHCP中繼功能便可,具體可參見配置設備做爲DHCP中繼示例(中繼與服務器處於同一網絡)。ide
組網需求ui
如圖1所示,某企業內的一臺主機經過Switch雙歸屬到SwitchA和SwitchB,SwitchA爲主設備,做爲DHCP服務器爲客戶端分配IP地址。現用戶但願當主設備故障時,客戶端可以經過備設備從新獲取IP地址。orm
圖1 VRRP組網下同網段內配置基於全局地址池的DHCP服務器組網圖blog
配置思路接口
VRRP組網下同網段內配置基於全局地址池的DHCP服務器,配置思路以下:ip
配置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
掃描二維碼關注微信公衆號:網絡民工 瞭解更多內容