利用多层交换机实现不同VLAN之间的通信
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用多层交换机实现不同VLAN之间的通信相关的知识,希望对你有一定的参考价值。
实验图片在附件里面
基本配置
PC1 IP:192.168.1.1 子网掩码:255.255.255.0 网关:162.168.1.254
PC2 IP:192.168.2.1 子网掩码:255.255.255.0 网关:162.168.2.254
PC3 IP:192.168.3.1 子网掩码:255.255.255.0 网关:162.168.3.254
还需要一台二层交换机SW1以及三层交换机SW2
PC1的端口与交换机SW1端口f0/2相连接,PC2的端口与交换机SW1端口f0/3相连接,
PC3的端口与交换机SW1端口f0/4相连接,交换机SW1端口f0/1与三层交换机f0/1端口
相连接。
之后进行设备的命令配置
配置交换机SW1
Switch>enable //切换模式
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname SW1 //修改主机名
SW1(config)#vlan 10 //创建VLAN
SW1(config-vlan)#vlan 20
SW1(config-vlan)#vlan 30
SW1(config-vlan)#exit //退出
SW1(config)#interface fastEthernet 0/2 //进入端口
SW1(config-if)#switchport mode access //将端口模式改为access
SW1(config-if)#switchport access vlan 10 //将端口f0/2加入VLAN10
SW1(config-if)#exit
SW1(config)#interface fastEthernet 0/3
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 20
SW1(config-if)#no shutdown
SW1(config-if)#exit
SW1(config)#interface fastEthernet 0/4
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 30
SW1(config-if)#no shutdown
SW1(config-if)#eixt
SW1(config)#exit
SW1#
%SYS-5-CONFIG_I: Configured from console by console
SW1#show vlan //查看VLAN
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig0/1, Gig0/2
10 VLAN0010 active Fa0/2
20 VLAN0020 active Fa0/3
30 VLAN0030 active Fa0/4
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
10 enet 100010 1500 - - - - - 0 0
20 enet 100020 1500 - - - - - 0 0
30 enet 100030 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
1003 tr 101003 1500 - - - - - 0 0
1004 fdnet 101004 1500 - - - ieee - 0 0
1005 trnet 101005 1500 - - - ibm - 0 0
Remote SPAN VLANs
------------------------------------------------------------------------------
Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
进入三层交换机SW2进行命令配置
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname SW2
SW2(config)#vlan 10
SW2(config-vlan)#vlan 20
SW2(config-vlan)#vlan 30
SW2(config-vlan)#exit
SW2(config)#ip routing //开启路由功能
SW2(config)#interface vlan 10 //进入虚拟局域网
SW2(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up
SW2(config-if)#ip address 192.168.1.254 255.255.255.0 //进行IP配置与PC网关相同
SW2(config-if)#no shutdown //打开端口
SW2(config-if)#exit
SW2(config)#interface vlan 20
SW2(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up
SW2(config-if)#ip address 192.168.2.254 255.255.255.0
SW2(config-if)#no shutdown
SW2(config-if)#exit
SW2(config)#inter
SW2(config)#interface vlan 30
SW2(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up
SW2(config-if)#ip address 192.168.3.254 255.255.255.0
SW2(config-if)#no shutdown
SW2(config-if)#exit
SW2(config)#interface f0/1
SW2(config-if)#switchport trunk encapsulation dot1q //修改三层交换机的封装格式
SW2(config-if)#switchport mode trunk //将端口f0/1模式改为trunk
SW2(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to up
SW2(config-if)#end
SW2#
%SYS-5-CONFIG_I: Configured from console by console
SW2#show interfaces trunk //查看trunk信息
Port Mode Encapsulation Status Native vlan
Fa0/1 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/1 1-1005
Port Vlans allowed and active in management domain
Fa0/1 1,10,20,30
Port Vlans in spanning tree forwarding state and not pruned
Fa0/1 1,10,20,30
Switch#show inter
Switch#show interfaces vlan
% Incomplete command.
SW2#show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/2, Fa0/3, Fa0/4, Fa0/5
Fa0/6, Fa0/7, Fa0/8, Fa0/9
Fa0/10, Fa0/11, Fa0/12, Fa0/13
Fa0/14, Fa0/15, Fa0/16, Fa0/17
Fa0/18, Fa0/19, Fa0/20, Fa0/21
Fa0/22, Fa0/23, Fa0/24, Gig0/1
Gig0/2
10 VLAN0010 active
20 VLAN0020 active
30 VLAN0030 active
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
10 enet 100010 1500 - - - - - 0 0
20 enet 100020 1500 - - - - - 0 0
30 enet 100030 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
1003 tr 101003 1500 - - - - - 0 0
1004 fdnet 101004 1500 - - - ieee - 0 0
1005 trnet 101005 1500 - - - ibm - 0 0
Remote SPAN VLANs
------------------------------------------------------------------------------
Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
SW2#
SW2#show ip route //查看路由表
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, Vlan10
C 192.168.2.0/24 is directly connected, Vlan20
C 192.168.3.0/24 is directly connected, Vlan30
Switch#
实验结果
PC>ping 192.168.2.1
Pinging 192.168.2.1 with 32 bytes of data:
Request timed out.
Reply from 192.168.2.1: bytes=32 time=1ms TTL=127
Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
Ping statistics for 192.168.2.1:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
PC>ping 192.168.3.1
Pinging 192.168.3.1 with 32 bytes of data:
Request timed out.
Reply from 192.168.3.1: bytes=32 time=0ms TTL=127
Reply from 192.168.3.1: bytes=32 time=0ms TTL=127
Reply from 192.168.3.1: bytes=32 time=0ms TTL=127
Ping statistics for 192.168.3.1:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
以上是关于利用多层交换机实现不同VLAN之间的通信的主要内容,如果未能解决你的问题,请参考以下文章