【实验名称】
VLAN/802.1Q-VLAN 间通信。
【实验目的】
通过三层交换机实现VLAN 间互相通信。
【背景描述】
假设某企业有两个主要部门:销售部和技术部,其中销售部门的个人计算机系统分散连接在
两台交换机上,他们之间需要相互进行通信,销售部和技术部也需要进行相互通信,现要在
交换机上做适当配置来实现这一目标。
【实现功能】
使在同一VLAN 里的计算机系统能跨交换机进行相互通信,而在不同VLAN 里的计算机系
统也能进行相互通信。
【实验设备】
S2126G(1 台)、S3550-24(1 台)、直连线(3 条)
注:先连接线缆,再进行配置,注意连接线缆的接口编号。SwitchA 为三层交换机。
【实验步骤】
在交换机SwitchA 上创建Vlan 10,并将0/5 端口划分到Vlan 10 中。
SwitchA # configure terminal
SwitchA(config)# vlan 10
SwitchA(config-vlan)# name sales
SwitchA(config-vlan)#exit
SwitchA(config)#interface fastethernet 0/5
SwitchA(config-if)#switchport access vlan 10
switchA(config-if)#exit
SwitchA(config)# vlan 20
SwitchA(config-vlan)# name technical
SwitchA(config-vlan)#exit
SwitchA(config)#interface fastethernet 0/15
SwitchA(config-if)#switchport access vlan 20
把交换机SwitchA 与SwitchB 相连端口(假设为0/24 端口)定义为tag vlan 模式。
SwitchA(config)#interface fastethernet 0/24 !进入接口配置模式
SwitchA(config-if)#switchport mode trunk
!将fastethernet 0/24 端口设为tag vlan 模式
验证测试:验证fastethernet 0/24 端口已被设置为tag vlan 模式。
SwitchA#show interfaces fastEthernet 0/24 switchport
Interface Switchport Mode Access Native Protected VLAN lists
----------------------------------------------------------------
Fa0/24 Enabled Trunk 1 1 Disabled All
在交换机SwitchB 上创建Vlan 10,并将0/5 端口划分到Vlan 10 中。
SwitchB # configure terminal
SwitchB(config)# vlan 10
SwitchB(config-vlan)# name sales
SwitchB(config-vlan)#exit
SwitchB(config)#interface fastethernet 0/5
SwitchB(config-if)#switchport access vlan 10
把交换机SwitchB 与SwitchA 相连端口(假设为0/24 端口)定义为tag vlan 模式。
SwitchB(config)#interface fastethernet 0/24
SwitchB(config-if)#switchport mode trunk
验证测试:验证fastethernet 0/24 端口已被设置为tag vlan 模式。
SwitchB#show interfaces fastEthernet 0/24 switchport
Interface Switchport Mode Access Native Protected VLAN lists
------------------------------------------------------------------
Fa0/24 Enabled Trunk 1 1 Disabled All
验证PC1 与PC3 能互相通信,但PC2 与PC3 不能互相通信。
C:\>ping 192.168.10.30 !在PC1 的命令行方式下验证能Ping
通PC3
Pinging 192.168.10.30 with 32 bytes of data:
Reply from 192.168.10.30: bytes=32 time<10ms
TTL=128
Reply from 192.168.10.30: bytes=32 time<10ms
TTL=128
Reply from 192.168.10.30: bytes=32 time<10ms
TTL=128
Reply from 192.168.10.30: bytes=32 time<10ms
TTL=128
Ping statistics for 192.168.10.30:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\>ping 192.168.10.30 !在PC2 的命令行方式下验证不能Ping
通PC3
Pinging 192.168.10.30 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 192.168.10.30:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
设置三层交换机VLAN 间通信。
SwitchA(config)# interface vlan 10 ! 创建虚拟接口vlan 10
SwitchA(config-if)#ip address 192.168.10.254 255.255.255.0
! 配置虚拟接口vlan 10 的地址为192.168.10.254
SwitchA(config-if)#no shutdown ! 开启端口
SwitchA(config-if)#exit
SwitchA(config)# int vlan 20 ! 创建虚拟接口vlan 20
SwitchA(config-if)#ip address 192.168.20.254 255.255.255.0
SwitchA(config-if)#no shutdown ! 开启端口
! 配置虚拟接口vlan 20 的地址为192.168.20.254
验证测试:查看S3550 路由接口的状态。
switchA#show ip interface !查看IP 接口的状态
Interface : VL10
Description : Vlan 10
OperStatus : UP
ManagementStatus : Enabled
Primary Internet address: 192.168.10.254/24
Broadcast address : 255.255.255.255
PhysAddress : 00d0.f8ff.8ab5
Interface : VL20
Description : Vlan 20
OperStatus : UP
ManagementStatus : Enabled
Primary Internet address: 192.168.20.254/24
Broadcast address : 255.255.255.255
PhysAddress : 00d0.f8ff.8ab6
将PC1 和PC3 的默认网关设置为192.168.10.254,将PC2 的默认网关设置为192.168.20.254。
测试结果:不同VLAN 内的主机可以互相PING 通。