簡介
本檔案介紹如何使用Cisco Catalyst系列交換器設定VLAN間路由。
必要條件
需求
思科建議您瞭解以下主題:
採用元件
本文中的資訊係根據以下軟體和硬體版本:
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
慣例
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
相關產品
此組態也可以搭配以下軟硬體版本使用:
背景資訊
通過實施VLAN間路由,組織可以保持VLAN分段的優點,同時仍然允許在網路的不同部分之間進行必要的通訊。
這在不同部門或服務需要安全高效地互動的複雜網路環境中尤其有用。
在Catalyst 3850系列交換器上設定了VLAN間路由的範例組態,並以一對Catalyst 4500系列交換器作為直接連線到Catalyst 3850的第2層(L2)交換器。
Catalyst 3850交換器具有所有目的地為網際網路的流量的預設路由。下一跳是Cisco路由器,但也可以是任何Internet網關,例如防火牆。
在LAN中,VLAN將裝置劃分為不同的衝突域和第3層(L3)子網。
同一個VLAN中的裝置可以直接通訊,無需路由。
但是,不同VLAN中的裝置之間的通訊需要路由裝置。
第2層(L2)交換機需要第3層路由裝置來促進VLAN之間的通訊。
此路由裝置可以位於交換機外部,也可以整合到同一機箱內的另一個模組中。
現代交換機(如Catalyst 3K/9K)直接將路由功能整合到交換機中。
這些交換器可以接收封包,識別該封包屬於不同的VLAN,並將其轉送到目的地VLAN上的適當連線埠。
典型的LAN設計根據裝置的組或功能劃分網路。
例如,工程VLAN僅包含與工程部門相關的裝置,而財務VLAN僅包含與財務相關的裝置。
啟用路由允許不同VLAN中的裝置在不位於同一廣播域的情況下通訊。T
他的VLAN設計還提供了其他優勢:管理員可以使用訪問清單限制VLAN之間的通訊。
例如,訪問清單可用於防止工程VLAN中的裝置訪問財務VLAN中的裝置。
設定
本節提供設定本檔案中所述的VLAN間路由所需的資訊。
附註:使用思科支援工具可找到此處所用命令的詳細資訊。只有註冊的思科使用者有權存取這類工具以及其他內部資訊。
網路圖表

在此圖中,Catalyst 3850交換器提供不同VLAN之間的VLAN間路由功能。Catalyst 3850交換機可以用作停用IP路由的L2裝置。
為了使交換機作為L3裝置運行並提供VLAN間路由,請確保ip routing已全域性啟用。
組態
以下三個VLAN是為此設定定義的:
-
VLAN 2 — User-VLAN
-
VLAN 3 — Server-VLAN
-
VLAN 10 — Mgmt-VLAN
每個伺服器和主機裝置都必須將其預設網關配置為Catalyst 3850上對應的VLAN介面IP地址。
例如,伺服器的預設網關為10.1.3.1。接入層交換機(即Catalyst 4500)通過中繼鏈路連線到Catalyst 3850。
對於網際網路流量,Catalyst 3850具有指向Cisco路由器的預設路由,該路由器充當Internet網關。
因此,Catalyst 3850在其路由表中沒有路由的任何流量都會被轉送到Cisco路由器以進行進一步處理。
行動
- 確保802.1Q中繼鏈路兩端的本徵VLAN相同。如果本徵VLAN不同,則本徵VLAN上的流量無法正確傳輸,可能導致網路中的連線問題。
- 如圖所示,將管理VLAN與其他VLAN分開。這種隔離可確保使用者或伺服器VLAN中的任何廣播或資料包風暴都不會影響交換機管理。
- 請勿使用 VLAN 1 進行管理。Catalyst交換器上的所有連線埠預設為VLAN 1,且所有未設定的連線埠都放在VLAN 1中。使用VLAN 1進行管理可能會導致潛在問題。
- 使用第 3 層(路由)連接埠連接至預設閘道連接埠。在本示例中,可以用連線到網際網路網關路由器的防火牆來替換Cisco路由器。
- 此示例在Catalyst 3850上配置一條通往Cisco路由器的靜態預設路由,以到達網際網路。如果只有一條路由可到達Internet,則此設定是理想的。
- 在網關路由器上為Catalyst 3850可到達的子網配置靜態路由(最好是總結路由)。此步驟非常重要,因為此配置不使用路由協定。
- 如果您的網路中有兩台L3交換器,您可以將存取層交換器連線到兩台3850交換器,並在它們之間執行熱待命路由器通訊協定(HSRP)以提供網路備援。
- 如果上行鏈路埠需要額外的頻寬,您可以配置EtherChannel,它還可以提供鏈路冗餘以應對鏈路故障。
拓撲中使用的交換機的運行配置如下所示:
註:Internet網關路由器的配置不相關,因此本文檔不介紹它。
-
Catalyst 3850
-
Catalyst 4500-A
-
Catalyst 4500-B
Catalyst 3850 |
SW_3850#show running-config
Building configuration...
Current configuration : 11543 bytes
!
! Last configuration change at 12:16:54 UTC Tue Nov 15 2022
!
version 16.12
no service pad
service timestamps debug datetime msec
service timestamps log datetime msec
service internal
service call-home
no platform punt-keepalive disable-kernel-core
!
hostname SW_3850
! !--- IP routing enabled for Inter-VLAN routing.
ip routing
!
!
no ip domain lookup
!
!
login on-success log
!
!
!
vtp mode off ! !--- Output suppressed.
!--- Configure IEEE 802.1q trunks. !--- Issue the switchport mode trunk command to force the switch port to trunk mode.
!
interface GigabitEthernet1/0/1
shutdown
!
interface GigabitEthernet1/0/2
shutdown
!
interface GigabitEthernet1/0/3
description To_Switch-B
switchport mode trunk
!
interface GigabitEthernet1/0/4
no switchport
no ip address
shutdown ! interface GigabitEthernet1/0/5 description To_Switch-A switchport mode trunk ! interface GigabitEthernet1/0/6 no switchport no ip address shutdown
!
interface Vlan1
no ip address
shutdown
!
!--- This Switch Virtual Interface (SVI) is the default gateway for Users. ! interface Vlan2 description User-SVI ip address 10.1.2.1 255.255.255.0 !
!--- This SVI is the default gateway for Servers VLAN. ! interface Vlan3 description Server-SVI ip address 10.1.3.1 255.255.255.0 !
!--- This SVI is the default gateway for other L2 switches management interface. ! interface Vlan10 description Management-SVI ip address 10.1.10.1 255.255.255.0 !
!--- This route statement allows the 3850 to send Internet traffic to the Cisco router.
ip route 0.0.0.0 0.0.0.0 10.1.1.2
ip forward-protocol nd
ip http server
ip http authentication local
ip http secure-server ! ! ! line con 0 line vty 5 15 ! end
|
附註:在本範例中,所有交換器上的VLAN主幹通訊協定(VTP)都設定為off,並使用vtp mode off指令。
SW_3850(config)#vtp mode off
Setting device to VTP Off mode for VLANS.
SW_3850(config)#vlan 2
SW_3850(config-vlan)#name User_VLAN
SW_3850(config-vlan)#exit
SW_3850(config)#vlan 3
SW_3850(config-vlan)#name Server_VLAN
SW_3850(config-vlan)#exit
SW_3850(config)#vlan 10
SW_3850(config-vlan)#name Mgmt_VLAN
SW_3850(config-vlan)#exit
SW_3850(config)#end
Catalyst 4500-A |
Switch-A#show running-config
Building configuration...
Current configuration : 15360 bytes
!
! Last configuration change at 01:06:17 UTC Wed Nov 16 2022
!
version 15.2
no service pad
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
service internal
service compress-config
!
hostname Switch-A
!
no ip domain-lookup
no ip dhcp snooping information option
!
!
login block-for 60 attempts 3 within 60
login delay 1
login quiet-mode access-class testblock
login on-failure log
login on-success log
vtp mode off
!
!
spanning-tree mode pvst
spanning-tree extend system-id
! !
vlan 3
name Server-VLAN
!
vlan 10
name Mgmt-VLAN
!
!--- Output suppressed
!
interface GigabitEthernet1/1
shutdown
!
interface GigabitEthernet1/2
shutdown
!
interface GigabitEthernet1/3
switchport mode trunk
!
!--- Configure Server (Host-A) to be the on the access VLAN 3.
!
interface TenGigabitEthernet3/1
switchport access vlan 3
switchport mode access
!
interface TenGigabitEthernet3/2
shutdown
!
interface TenGigabitEthernet3/3
!
interface TenGigabitEthernet3/4
!
!--- Output suppressed.
!--- IP address on VLAN 10 manages this switch.
!
interface Vlan1
no ip address
!
interface Vlan10
ip address 10.1.10.2 255.255.255.0
!
ip forward-protocol nd
ip http server
ip http banner
ip http authentication local
!
!--- Configure the default gateway so that the switch is reachable from other
!--- VLANs/subnets. The gateway points to the VLAN 10 interface on the 3850.
ip default-gateway 10.1.10.1 ip forward-protocol nd
ip http server
ip http banner
ip http authentication local !
!
line con 0
stopbits 1
line vty 0 4
logging synchronous
transport input all
line vty 5 15
logging synchronous
transport input all
! end
|
Catalyst 4500-B |
Switch-B#show running-config
Building configuration...
Current configuration : 6841 bytes
!
! Last configuration change at 10:44:33 UTC Tue Nov 15 2022
!
version 15.2
no service pad
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
service compress-config
!
hostname Switch-B
!
boot-start-marker
boot system bootflash:cat4500es8-universal.SPA.03.11.06.E.152-7.E6.bin
boot-end-marker
!
!
vrf definition mgmtVrf
!
address-family ipv4
exit-address-family
!
address-family ipv6
exit-address-family
!
no aaa new-model
hw-module module 7 mode 1
!
vtp mode off
!
spanning-tree mode pvst
spanning-tree extend system-id
! vlan 2 name User-VLAN ! vlan 10 name Mgmt-VLAN !
!
interface GigabitEthernet1/1
switchport mode trunk
!
interface GigabitEthernet1/2
!
interface GigabitEthernet1/3
shutdown
!
interface GigabitEthernet1/4
shutdown
!
!--- Output suppressed.
!--- Configure User (Host-B) in VLAN 2.
!
interface GigabitEthernet8/5
switchport access vlan 2
switchport mode access
!
!--- Configure the management IP address in VLAN 10.
!
interface Vlan1
no ip address
!
interface Vlan10
ip address 10.1.10.3 255.255.255.0
!
!--- Define the default route so that the switch is reachable.
!
ip default-gateway 10.1.10.1
ip forward-protocol nd
ip http server
ip http banner
ip http authentication local
!
!
line con 0
stopbits 1
line vty 0 4
login
transport input none
!
!
end
|
驗證
接下來,您可以找到一系列基本命令,可用來檢查裝置的狀態以及確認您的配置是否正常工作:
show vtp status — 此命令會顯示交換器上VLAN主幹通訊協定(VTP)的狀態。它提供有關VTP版本、域名、模式(伺服器、客戶端或透明)以及現有VLAN數量的資訊。這對於檢驗VTP配置並確保整個網路中的VLAN資訊一致非常有用。
show interfaces trunk — 此命令顯示交換機上中繼埠的狀態。它提供了有關將哪些介面配置為中繼、封裝型別(例如802.1Q)以及每個中繼上允許的VLAN的詳細資訊。這對於排除VLAN連線問題和確保正確的中繼配置至關重要。
show ip route — 此命令顯示交換器的IP路由表。其中列出了所有已知路由,包括直連網路、靜態路由和通過動態路由協定獲知的路由。這對於檢驗路由路徑和確保交換機可以到達所有必要的網路都至關重要。
show ip cef — 此命令顯示Cisco Express Forwarding(CEF)輸出。它提供有關CEF條目的資訊,包括下一跳地址和相關介面。這對於排除轉發問題和確保高效資料包處理非常有用。
附註:有關CLI命令的詳細資訊,請參閱特定交換平台的命令參考指南。
附註:只有註冊的思科使用者有權存取這類工具以及其他內部資訊。
Catalyst 3850
SW_3850#show vtp status
VTP Version capable : 1 to 3
VTP version running : 1
VTP Domain Name :
VTP Pruning Mode : Disabled
VTP Traps Generation : Disabled
Device ID : bc67.1c5d.3800
Configuration last modified by 10.0.0.10 at 0-0-00 00:00:00
Feature VLAN:
--------------
VTP Operating Mode : Off
Maximum VLANs supported locally : 1005
Number of existing VLANs : 8
Configuration Revision : 0
MD5 digest : 0x7E 0xC3 0x8D 0x91 0xC8 0x53 0x42 0x14
0x79 0xA2 0xDF 0xE9 0xC0 0x06 0x1D 0x7D
SW_3850#show interfaces trunk
Port Mode Encapsulation Status Native vlan
Gi1/0/3 on 802.1q trunking 1
Gi1/0/5 on 802.1q trunking 1
Port Vlans allowed on trunk
Gi1/0/3 1-4094
Gi1/0/5 1-4094
Port Vlans allowed and active in management domain
Gi1/0/3 1-3,10
Gi1/0/5 1-3,10
Port Vlans in spanning tree forwarding state and not pruned
Gi1/0/3 1-3,10
Gi1/0/5 1,3,10
SW_3850#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
H - NHRP, G - NHRP registered, g - NHRP registration summary
o - ODR, P - periodic downloaded static route, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is 10.100.100.2 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 10.100.100.2
10.0.0.0/8 is variably subnetted, 8 subnets, 2 masks
C 10.1.2.0/24 is directly connected, Vlan2
L 10.1.2.1/32 is directly connected, Vlan2
C 10.1.3.0/24 is directly connected, Vlan3
L 10.1.3.1/32 is directly connected, Vlan3
C 10.1.10.0/24 is directly connected, Vlan10
L 10.1.10.1/32 is directly connected, Vlan10
C 10.100.100.0/24 is directly connected, GigabitEthernet1/0/2
L 10.100.100.1/32 is directly connected, GigabitEthernet1/0/2
Catalyst 4500-A
Switch-A#show vtp status
VTP Version capable : 1 to 3
VTP version running : 2
VTP Domain Name : cisco.com
VTP Pruning Mode : Disabled
VTP Traps Generation : Disabled
Device ID : 6400.f13e.dc40
Configuration last modified by 10.1.10.2 at 0-0-00 00:00:00
Feature VLAN:
--------------
VTP Operating Mode : Off
Maximum VLANs supported locally : 1005
Number of existing VLANs : 32
Configuration Revision : 0
MD5 digest : 0x0B 0x61 0x4F 0x9B 0xCD 0x1B 0x37 0x55
0xAB 0x0C 0xC1 0x4B 0xF8 0xDE 0x33 0xB3
Switch-A#show interfaces trunk
Port Mode Encapsulation Status Native vlan
Gi1/3 on 802.1q trunking 1
Port Vlans allowed on trunk
Gi1/3 1-4094
Port Vlans allowed and active in management domain
Gi1/3 1,3,10
Port Vlans in spanning tree forwarding state and not pruned
Gi1/3 1,3,10
Catalyst 4500-B
Switch-B#show vtp status
VTP Version capable : 1 to 3
VTP version running : 1
VTP Domain Name :
VTP Pruning Mode : Disabled
VTP Traps Generation : Disabled
Device ID : 6c20.5606.3540
Configuration last modified by 10.1.10.3 at 11-15-22 10:42:29
Feature VLAN:
--------------
VTP Operating Mode : Off
Maximum VLANs supported locally : 1005
Number of existing VLANs : 7
Configuration Revision : 0
MD5 digest : 0xEC 0xB4 0x8D 0x46 0x94 0x95 0xE0 0x8F
0xEE 0x1E 0xC7 0x9F 0x26 0x88 0x49 0x9F
Switch-B#show interfaces trunk
Port Mode Encapsulation Status Native vlan
Gi1/1 on 802.1q trunking 1
Port Vlans allowed on trunk
Gi1/1 1-4094
Port Vlans allowed and active in management domain
Gi1/1 1-2,10
Port Vlans in spanning tree forwarding state and not pruned
Gi1/1 1-2,10
疑難排解
1.同一VLAN中的Ping問題
- 如果無法對相同VLAN中的裝置執行Ping,請檢查來源連線埠和目的地連線埠的VLAN分配,以確保它們位於同一個VLAN中。
- 要檢查VLAN分配,請使用show interface status命令。
- 使用show mac address-table命令檢驗L2交換機是否正在獲取相應VLAN中每台裝置的MAC地址。
2.不同交換器之間的Ping問題
- 如果源和目標位於不同的交換機上,請確保正確配置中繼。使用show interfaces trunk命令驗證配置。
- 檢查本徵VLAN是否與中繼鏈路的兩端匹配,以及源裝置和目的裝置之間的子網掩碼是否匹配。
3.不同VLAN之間的Ping問題
- 如果無法對不同VLAN中的裝置執行Ping,請確認能分別對各自的預設閘道執行Ping(請參閱步驟1)。
- 驗證裝置的預設網關是否指向正確的VLAN介面IP地址,以及子網掩碼是否匹配。
4. Internet連線問題
- 如果無法連線至網際網路,請確保Catalyst 3850上的預設路由指向正確的IP位址,且子網位址與Internet閘道路由器相符。
- 確保第3層交換器(此案例中為3850)能ping通Internet閘道。
- 要檢查,請使用show ip cef <prefix>命令來識別它是否指向正確的介面。
- 確保Internet網關路由器具有指向Internet和內部網路的路由。
相關資訊