通过交换机实现不同VLAN间通信
一. 实验原理
通过在交换机上创建不同的VLAN将连接在交换机上的设备划分到不同的网络中,不同VLAN之间的设备在二层是相互隔离,无法通信的。但三层交换机具有路由功能,为每个VLAN配置相应的IP和子网,这些地址作为VLAN内设备的网关,当数据包从一个VLAN设备发送到另一个VLAN设备时,三层交换机根据数据包的目的ip地址,在三层进行路由查找,确定转发路径,并将数据包转发到目的VLAN设备
二 . 实验拓扑
三.实验需求
1.按照拓扑图所示配置ip和网关和VLAN
2.PC2,3,4之间可以互通
四.实验步骤
1.配置ip地址与网关
2.在SW1上创建VLAN10 VLAN20 VLAN 30,
[H3C]sys SW1
[SW1]vlan 10
[SW1-vlan10]port g1/0/1
[SW1-vlan10]vlan 20
[SW1-vlan20]port g1/0/2
[SW1-vlan20]vlan 30
[SW1-vlan30]port g1/0/3
3.在SW1上配置VLAN 10 VLAN 20 VLAN 30的网关地址
[SW1]int vlan 10
[SW1-Vlan-interface10]%Jul 3 15:03:59:449 2025 SW1 IFNET/3/PHY_UPDOWN: Physical state on the interface Vlan-interface10 changed to up.
%Jul 3 15:03:59:449 2025 SW1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface Vlan-interface10 changed to up.
[SW1-Vlan-interface10]ip add 192.168.1.254 24
[SW1-Vlan-interface10]quit
[SW1]int vlan 20
[SW1-Vlan-interface20]%Jul 3 15:04:29:787 2025 SW1 IFNET/3/PHY_UPDOWN: Physical state on the interface Vlan-interface20 changed to up.
%Jul 3 15:04:29:788 2025 SW1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface Vlan-interface20 changed to up.
[SW1-Vlan-interface20]ip add 192.168.2.254 24
[SW1-Vlan-interface20]quit
[SW1]int vlan 30
[SW1-Vlan-interface30]%Jul 3 15:07:26:379 2025 SW1 IFNET/3/PHY_UPDOWN: Physical state on the interface Vlan-interface30 changed to up.
%Jul 3 15:07:26:380 2025 SW1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface Vlan-interface30 changed to up.
[SW1-Vlan-interface30]ip add 192.168.3.254 24
[SW1-Vlan-interface30]quit
4.在SW1上查看路由表
[SW1]dis ip routing-table
Destinations : 20 Routes : 20
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.1.0/24 Direct 0 0 192.168.1.254 Vlan10
192.168.1.0/32 Direct 0 0 192.168.1.254 Vlan10
192.168.1.254/32 Direct 0 0 127.0.0.1 InLoop0
192.168.1.255/32 Direct 0 0 192.168.1.254 Vlan10
192.168.2.0/24 Direct 0 0 192.168.2.254 Vlan20
192.168.2.0/32 Direct 0 0 192.168.2.254 Vlan20
192.168.2.254/32 Direct 0 0 127.0.0.1 InLoop0
192.168.2.255/32 Direct 0 0 192.168.2.254 Vlan20
192.168.3.0/24 Direct 0 0 192.168.3.254 Vlan30
192.168.3.0/32 Direct 0 0 192.168.3.254 Vlan30
192.168.3.254/32 Direct 0 0 127.0.0.1 InLoop0
192.168.3.255/32 Direct 0 0 192.168.3.254 Vlan30
//可以看到已经产生了到达192.168.1.0/24,192.168.2.0/24,192.168.3.0/24网段的直连路由,代表SW1可以对VLAN 10 VLAN20 VLAN 30之间的数据进行三层转发
5.测试
可以看到PC2与PC3,PC4之间能够互通