1. 程式人生 > 實用技巧 >企業級網路架構配置細則(壹)

企業級網路架構配置細則(壹)

文章目錄

企業網配置細則

實驗拓撲

需求:

分流互備
  • 1

說明:

​ SW1、SW2是核心層與匯聚層的集合

為什麼需要集合,為什麼不是三層架構?
	匯聚層存在的意義是為核心分擔壓力,三層架構其實是核心層的效能不夠
  • 1
  • 2
各層的用途與意義
	接入層:提供埠的密度,用於使用者終端的接入—二層交換機、AP
	匯聚層(分佈層):流量的集合,DHCP/VLAN/STP/HSRP/VRRP/channel…QOS/ACL
		為核心分擔壓力,三層架構其實是核心層的效能不夠
	核心層:nat、高速路由轉發

現在是二層架構(扁平化架構),不但效能提升了而且價格不貴
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

1、VLAN(Trunk、Access)

1.1 建立VLAN、修改介面模式

1、建立VLAN

四臺交換機做建立VLAN方式相同

[SW1]vlan batch 2 3
  • 1

接入層交換機的下聯PC介面設定為access模式,其他口設定為trunk模式,華為還存在一種Hybrid模式,詳情請

點選

配置:

2、更改介面模式

​ 單個介面的更改:

port link-type access 
port link-type trunk
  • 1
  • 2

​ 多個介面的模式更改:

[Huawei]port-group 1
[Huawei]group-member GigabitEthernet 0/0/1 to GigabitEthernet 0/0/10
[Huawei]port link-type access
  • 1
  • 2
  • 3

3、劃入 VLAN

單個將介面劃分到 vlan

[SWA]interface GigabitEthernet0/0/5
[SWA-GigabitEthernet0/0/5]port default vlan 3
  • 1
  • 2

批量將介面劃分到 vlan2

[Huawei]vlan 2
[Huawei-vlan2]port GigabitEthernet 0/0/1 to 0/0/2
  • 1
  • 2

1.3 鏈路聚合

過來的流量分佈在聚合介面上,並不是簡單的頻寬疊加;

按照流分佈,而不是包分佈;一個流只能被分佈在一個物理介面上的

某些屬性,比如五元組(源目IP、源目MAC、協議等)
  • 1
[SW1-Eth-Trunk1]load-balance ?
  dst-ip       According to destination IP hash arithmetic
  dst-mac      According to destination MAC hash arithmetic
  src-dst-ip   According to source/destination IP hash arithmetic
  src-dst-mac  According to source/destination MAC hash arithmetic
  src-ip       According to source IP hash arithmetic
  src-mac      According to source MAC hash arithmetic
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

注意:

做鏈路聚合的負載分擔時,分擔流的內容越詳細,匹配越精確,分擔流量卻準確

鏈路聚合的介面分佈在同一個板卡、不同板卡、不同裝置;若要分佈在不同的裝置上時存在堆疊、虛擬化(將兩個裝置合併為一個裝置)、M-LAG

配置:

[SW1-Eth-Trunk1]di th
#
interface Eth-Trunk1
 port link-type trunk
 port trunk allow-pass vlan 2 to 4094
#
return
[SW1-Eth-Trunk1]trunkport GigabitEthernet 0/0/2
[SW1-Eth-Trunk1]trunkport GigabitEthernet 0/0/3
檢視:
[SW1-GigabitEthernet0/0/2]di th
#
interface GigabitEthernet0/0/2
 eth-trunk 1
#
return
[SW1-GigabitEthernet0/0/3]di th
#
interface GigabitEthernet0/0/3
 eth-trunk 1
#
return

SW2做相同配置,注意聚合口有可能不一樣,本實驗一致
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

1.4 SW1 2間做出互聯地址

為什麼需要互聯?
	1、匯聚層交換機的互聯鏈路是為了承載VLAN間通訊,如果不存在的話VLAN間通訊就會走接入層進行繞路,使接入層稱為中轉裝置(匯聚層)

	2、當匯聚和核心上下連對角多條線路出現故障的時候,需要用到這條線路,防止繞路時使接入層成為匯聚層
  • 1
  • 2
  • 3
  • 4

配置

[SW1-Vlanif102]di th
#
interface Vlanif102
 ip address 10.2.102.1 255.255.255.0
#
return

[SW2-Vlanif102]di th
#
interface Vlanif102
 ip address 10.2.102.2 255.255.255.0
#
return
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

2、MSTP(生成樹)

2.1MST域

配置,為保證所有的交換機都在同一個MST域內,則name、level、instance配置都需相同,即以下配置都需相同

[SW1-mst-region]di th
#
stp region-configuration
 region-name hw
 revision-level 1
 instance 1 vlan 2
 instance 2 vlan 3
 active region-configuration
#
return
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

2.2 Master/Backup

主備分流,即使SW1作為例項1的主根,VLAN2是屬於例項1的

兩種配置方式:
第一種 直接對例項進行根的主備配置
[SW1]stp instance 1 root primary 
[SW2]stp instance 1 root secondary 
第二種 採用優先順序的方式對例項進行根的主備配置
[SW1]stp instance 1 priority 0
[SW2]stp instance 1 priority 4096
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

檢視

可見SW1就是例項1的主根,根橋是自己,優先順序為最高0;是例項2的備根
[SW1]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID      :0.4c1f-cc65-7998
MSTI RegRoot/IRPC   :0.4c1f-cc65-7998 / 0
MSTI RootPortId     :0.0
Master Bridge       :32768.4c1f-cc65-7998
[SW1]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID      :4096.4c1f-cc65-7998
MSTI RegRoot/IRPC   :0.4c1f-ccfc-4e13 / 10000
MSTI RootPortId     :128.25
Master Bridge       :32768.4c1f-cc65-7998

SW2同理
[SW2]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID      :0.4c1f-ccfc-4e13
MSTI RegRoot/IRPC   :0.4c1f-ccfc-4e13 / 0
MSTI RootPortId     :0.0
Master Bridge       :32768.4c1f-cc65-7998
[SW2]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID      :4096.4c1f-ccfc-4e13
MSTI RegRoot/IRPC   :0.4c1f-cc65-7998 / 10000
MSTI RootPortId     :128.25
Master Bridge       :32768.4c1f-cc65-7998
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

3、VRRP(熱備份閘道器)

為什麼需要?

​ 1、裝置的宕機

​ 2、下聯與互聯交換機的介面down

​ 3、上聯介面down

如果做的是OSPF則需要VRRP的條件唯一是裝置的down

上行鏈路追蹤:

​ 增加優先順序使用情況:

​ 當做割接時,需要在短時間內將主閘道器切換到新閘道器上;當上行鏈路一旦啟動,優先順序增加,則實現切換。 優先順序越大越優

搶佔是搶佔回來的時候,而不是丟掉失去的時候

說明:

​ 由於上聯有兩個路由器,若需對上聯鏈路做跟蹤的話,需要監控兩端鏈路,每段鏈路減小15,即只有當兩端鏈路都出現故障後,主閘道器的優先順序才會減小的比備閘道器的小,實現切換

​ 為了防止終端的偽造資料對VRRP產生影響干擾,則再VRRP中做出認證

配置:

VLAN2的VRRP(SW1為主)

[SW1-Vlanif2]di th
#
interface Vlanif2
 ip address 10.2.2.1 255.255.255.0
 vrrp vrid 1 virtual-ip 10.2.2.254
 vrrp vrid 1 priority 120
 vrrp vrid 1 preempt-mode timer delay 5
 vrrp vrid 1 track interface GigabitEthernet0/0/5 reduced 15
 vrrp vrid 1 track interface GigabitEthernet0/0/6 reduced 15
 vrrp vrid 1 authentication-mode md5 h!1I8"-zqX$+cx#k/mS=SrB#
#
return

[SW2-Vlanif2]di th
#
interface Vlanif2
 ip address 10.2.2.2 255.255.255.0
 vrrp vrid 1 virtual-ip 10.2.2.254
 vrrp vrid 1 priority 101
 vrrp vrid 1 authentication-mode md5 FLAzLNtpS!Wq<}.DH-])vrr#
#
return
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

VLAN3的VRRP(SW1為主)

[SW2-Vlanif3]di th
#
interface Vlanif3
 ip address 10.2.3.1 255.255.255.0
 vrrp vrid 1 virtual-ip 10.2.3.254
 vrrp vrid 1 priority 120
 vrrp vrid 1 track interface GigabitEthernet0/0/5 reduced 15
 vrrp vrid 1 track interface GigabitEthernet0/0/6 reduced 15
 vrrp vrid 1 authentication-mode md5 :EQX>]u(&E:.`&R&e7S(fJ)#
 dhcp select global
#
return

[SW1-Vlanif3]di th
#
interface Vlanif3
 ip address 10.2.3.2 255.255.255.0
 vrrp vrid 1 virtual-ip 10.2.3.254
 vrrp vrid 1 priority 101
 vrrp vrid 1 authentication-mode md5 e2VJ&)RP"!Hj<w)JO!C@&H##
#
return
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

檢視VRRP的狀態

[SW1]dis vrrp brief 
VRID  State        Interface                Type     Virtual IP     
----------------------------------------------------------------
1     Master       Vlanif2                  Normal   10.2.2.254     
1     Backup       Vlanif3                  Normal   10.2.3.254     
----------------------------------------------------------------
Total:2     Master:1     Backup:1     Non-active:0 

[SW2]dis vrrp brief 
VRID  State        Interface                Type     Virtual IP     
----------------------------------------------------------------
1     Master       Vlanif3                  Normal   10.2.3.254     
1     Backup       Vlanif2                  Normal   10.2.2.254     
----------------------------------------------------------------
Total:2     Master:1     Backup:1     Non-active:0    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

4.DHCP

分析說明:

​ 由於本實驗中存在VRRP,即閘道器的備份,那麼當閘道器切換後,DHCP也就失效,那麼就需要兩個DHCP池塘;存在以下兩種配置方案

1、兩邊同時配,池子切半(使用去除地址的方式)

2、使用中繼,即使用一個DHCP伺服器,交換機就是一箇中繼裝置

採用方案一

將SW1上的DHCP池塘地址設定為1-128

將SW2上的DHCP池塘地址設定為129-253

全域性模式下 dhcp enable
進入vlan2 dhcp select global
[SW1-ip-pool-vlan2]di th
#
ip pool vlan2
 gateway-list 10.2.2.254
 network 10.2.2.0 mask 255.255.255.0
 excluded-ip-address 10.2.2.129 10.2.2.253  去掉的地址,即主閘道器存在時,DHCP分配的地址為除了129-253的地址
 dns-list 114.114.114.114
#
return
[SW2-ip-pool-vlan2]di th
#
ip pool vlan2
 gateway-list 10.2.2.254
 network 10.2.2.0 mask 255.255.255.0
 excluded-ip-address 10.2.2.1 10.2.2.128 去掉的地址,即閘道器切換後,備裝置上DHCP分配的地址為除了1-128的地址
 dns-list 114.114.114.114
#
return


VLAN3地址池的配置類似,如下所示
[SW2-ip-pool-vlan3]di th
#
ip pool vlan3
 gateway-list 10.2.3.254
 network 10.2.3.0 mask 255.255.255.0
 excluded-ip-address 10.2.3.129 10.2.3.253
 dns-list 114.114.114.114
#
return
[SW1-ip-pool-vlan3]di th
#
ip pool vlan3
 gateway-list 10.2.3.254
 network 10.2.3.0 mask 255.255.255.0
 excluded-ip-address 10.2.3.1 10.2.3.128
 dns-list 114.114.114.114
#
return
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

測試驗證:

預期,主裝置存在時,VLAN2 3 的PC獲取到的IP為2-128;當閘道器切換後,VLAN2 3 的PC獲取到的IP為129-253

down掉SW1上聯的兩個介面,使VRRP進行閘道器的切換

5、資料(上聯外網)

5.1 連線外網的介面

說明:真機上可以使用如下命令直接將二層介面改成三層的,但是模擬器不能這麼敲,所以採用將介面劃分進VLAN的情況來進行模擬

[SW1-GigabitEthernet0/0/5]undo portswitch 
  • 1

5.2 路由

去外網(出)

[SW1]ip route-static 0.0.0.0 0 10.2.11.1 
[SW1]ip route-static 0.0.0.0 0 10.2.12.1 preference 100

[SW2]ip route-static 0.0.0.0 0 10.2.22.1 
[SW2]ip route-static 0.0.0.0 0 10.2.21.1 preference 100
  • 1
  • 2
  • 3
  • 4
  • 5

外網回來(進)

[R1]ip route-static 10.2.2.0 24 10.2.11.2 
[R1]ip route-static 10.2.2.0 24 10.2.21.2 preference 100
[R1]ip route-static 10.2.3.0 24 10.2.21.2 
[R1]ip route-static 10.2.3.0 24 10.2.11.2 preference 100

[R2]ip route-static 10.2.2.0 24 10.2.12.2 
[R2]ip route-static 10.2.2.0 24 10.2.22.2 preference 100
[R2]ip route-static 10.2.3.0 24 10.2.22.2 
[R2]ip route-static 10.2.3.0 24 10.2.12.2 preference 100
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

注意:由於存在兩個外網,即R1、R2,可以理解為兩個運營商,即電信、聯通;所以兩個運營商之間是需要有路由的;由於這裡寫的是靜態,所以路由會比較多,後期直接用OSPF一跑直接完事

由於測試使用的是R1 R2的環回,其二者本身也需要通,即寫兩條靜態

[R1]ip route-static 2.2.2.0 24 10.2.201.2
[R2]ip route-static 1.1.1.0 24 10.2.201.1
  • 1
  • 2

6、測試

6.1 VLAN2的閘道器切換

斷掉SW1的一條上行鏈路,注意這裡也要斷掉VLAN11,要不預設預設走的還是R1上去,可見,斷掉一條上行並不會切換閘道器

PC1pingR1的環回

斷掉SW1的所有上聯,此時不用斷掉vlan,因為閘道器已經被VRRP切換了

6.2 VLAN3的閘道器切換

斷掉SW2的一條上行鏈路,注意這裡也要斷掉VLAN11,要不預設預設走的還是R1上去,可見,斷掉一條上行並不會切換閘道器

PC7pingR2的環回

斷掉SW2的所有上聯,此時不用斷掉vlan,因為閘道器已經被VRRP切換了

當上行鏈路正常時,即正常情況下的走法如下

測試完成,與預期相符