简介
本文档介绍如何使用Cisco Catalyst系列交换机配置VLAN间路由。
先决条件
要求
Cisco 建议您了解以下主题:
使用的组件
本文档中的信息基于以下软件和硬件版本:
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您的网络处于活动状态,请确保您了解所有命令的潜在影响。
规则
有关文档规则的详细信息,请参阅 Cisco 技术提示规则。
相关产品
此配置也可用于以下硬件和软件版本:
-
任何Catalyst 3k/9k交换机及更高版本
-
任何Catalyst交换机型号,用作接入层交换机
背景信息
通过实施VLAN间路由,组织可以保持VLAN分段的优势,同时仍允许在网络的不同部分之间进行必要的通信。
这在不同部门或服务需要安全高效地交互的复杂网络环境中尤其有用。
在Catalyst 3850系列交换机上设置了VLAN间路由的示例配置,其中一对Catalyst 4500系列交换机充当直接连接到Catalyst 3850的第2层(L2)交换机。
Catalyst 3850交换机具有所有发往Internet的流量的默认路由。下一跳是Cisco路由器,但也可以是任何Internet网关,例如防火墙。
在LAN中,VLAN将设备划分为不同的冲突域和第3层(L3)子网。
同一个VLAN中的设备可以直接通信,无需路由。
但是,不同VLAN中的设备之间的通信需要使用路由设备。
第2层(L2)交换机需要L3路由设备来促进VLAN之间的通信。
此路由设备可以位于交换机外部,也可以集成到同一机箱内的另一个模块中。
现代交换机(例如Catalyst 3K/9K)直接在交换机内集成了路由功能。
这些交换机可以接收数据包,确定它属于不同的VLAN,然后将其转发到目的VLAN上的相应端口。
典型的LAN设计根据设备的组或功能划分网络。
例如,工程VLAN仅包含与工程部门相关的设备,而财务VLAN仅包含与财务相关的设备。
启用路由允许不同VLAN中的设备在不位于同一广播域的情况下通信。 T
他的VLAN设计还提供了其他优势:管理员可以使用访问列表限制VLAN之间的通信。
例如,访问列表可用于防止工程VLAN中的设备访问财务VLAN中的设备。
配置
本节提供配置VLAN间路由所需的信息,如本文档所述。
注意:使用Cisco支持工具查找有关此处所用命令的详细信息。只有注册思科用户才能访问此类工具和其他内部信息。
网络图

在此图中,Catalyst 3850交换机提供不同VLAN之间的VLAN间路由功能。Catalyst 3850交换机可以用作禁用IP路由的第2层设备。
为了使交换机用作L3设备并提供VLAN间路由,请确保全局启用ip routing。
配置
以下三个VLAN为此设置进行了定义:
-
VLAN 2 — 用户VLAN
-
VLAN 3 — 服务器VLAN
-
VLAN 10 — 管理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路由器可替换为连接到Internet网关路由器的防火墙。
- 本示例在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
|
注意:在本示例中,使用vtp mode off命令在所有交换机上将VLAN中继协议(VTP)设置为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 — 此命令显示交换机上中继端口的状态。它提供了有关将哪些接口配置为TRUNK、封装类型(例如802.1Q)以及每个TRUNK上允许的VLAN的详细信息。这对于排除VLAN连接问题和确保正确的中继配置至关重要。
show ip route — 此命令显示交换机的IP路由表。它列出所有已知路由,包括直连网络、静态路由和通过动态路由协议获知的路由。这对于检验路由路径和确保交换机可以到达所有必要的网络至关重要。
show ip cef — 此命令显示思科快速转发(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问题
- 如果无法ping通同一个VLAN中的设备,请检查源端口和目标端口的VLAN分配,以确保它们位于同一个VLAN中。
- 要检查VLAN分配,请使用show interface status命令。
- 使用show mac address-table命令验证L2交换机是否正在获取相应VLAN中每台设备的MAC地址。
2.不同交换机之间的Ping问题
- 如果源设备和目的设备位于不同的交换机上,请确保中继配置正确。使用show interfaces trunk命令验证配置。
- 检查TRUNK链路两端的本征VLAN是否匹配,以及源设备和目的设备之间的子网掩码是否匹配。
3.不同VLAN之间的ping问题
- 如果无法ping通不同VLAN中的设备,请确保可以ping通各自的默认网关(请参阅步骤1)。
- 检验设备的默认网关是否指向正确的VLAN接口IP地址,以及子网掩码是否匹配。
4. Internet连接问题
- 如果无法到达Internet,请确保Catalyst 3850上的默认路由指向正确的IP地址,并且子网地址与Internet网关路由器匹配。
- 确保L3交换机(本场景中的3850)能够ping通Internet网关。
- 要检查,请使用show ip cef <prefix>命令确定它是否指向正确的接口。
- 确保Internet网关路由器具有到Internet和内部网络的路由。
相关信息