在第五节里聊过虚拟局域网构建,不同的虚拟局域网不能通信。但有时候,想让不同的虚拟局域网之间能够通信,需要怎么做?
主要有以下三种方式:
如果使用传统VLAN间路由,缺点比较多,后面有机会的话也会配置一下。
独臂路由
假设架构图如下所示,我们开始配置
在交换机上创建VLAN,设置PC的IP地址
csharp
[SW1]vlan 10
[SW1-vlan10]port GigabitEthernet 1/0/1
[SW1-vlan10]quit
[SW1]vlan 20
[SW1-vlan20]port GigabitEthernet 1/0/2
[SW1-vlan20]quit
此时肯定是ping不通的。然后我们将30口配置为trunk,让流量能走到路由器
css
[SW1]interface GigabitEthernet 1/0/30
[SW1-GigabitEthernet1/0/30]port link-type trunk
[SW1-GigabitEthernet1/0/30]port trunk permit vlan 10 20
最后在路由器上配置
csharp
[RT1]int Gi 0/0/0.1
[RT1-GigabitEthernet0/0/0.1]vlan-type dot1q vid 10
[RT1-GigabitEthernet0/0/0.1]ip address 192.168.1.1 24
[RT1-GigabitEthernet0/0/0.1]quit
[RT1]int G 0/0/0.2
[RT1-GigabitEthernet0/0/0.2]vlan-type dot1q vid 20
[RT1-GigabitEthernet0/0/0.2]ip add 192.168.2.1 24
[RT1-GigabitEthernet0/0/0.2]quit
然后就能ping通了
python
[H3C]ping 192.168.2.2
Ping 192.168.2.2 (192.168.2.2): 56 data bytes, press CTRL_C to break
56 bytes from 192.168.2.2: icmp_seq=0 ttl=254 time=22.723 ms
56 bytes from 192.168.2.2: icmp_seq=1 ttl=254 time=3.576 ms
56 bytes from 192.168.2.2: icmp_seq=2 ttl=254 time=3.182 ms
56 bytes from 192.168.2.2: icmp_seq=3 ttl=254 time=2.672 ms
56 bytes from 192.168.2.2: icmp_seq=4 ttl=254 time=3.692 ms
--- Ping statistics for 192.168.2.2 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 2.672/7.169/22.723/7.785 ms
[H3C]%Dec 10 17:03:23:712 2023 H3C PING/6/PING_STATISTICS: Ping statistics for 192.168.2.2: 5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss, round-trip min/avg/max/std-dev = 2.672/7.169/22.723/7.785 ms.
三层交换机
三层交换机在二层交换机基础上增加了路由模块。如果使用三层交换机的话,能够不用路由器,节省成本;同时转发速率高,吞吐量大,避免了外部连接带来的延迟和不稳定性。
配置也比较简单,加入架构图如下所示:
配置一下PC机器的IP地址,然后配置交换机
csharp
[SW1]vlan 10
[SW1-vlan10]port G 1/0/1
[SW1-vlan10]quit
[SW1]vlan 20
[SW1-vlan20]port G 1/0/2
[SW1-vlan20]quit
配置VLAN
csharp
[SW1]int vlan 10
[SW1-Vlan-interface10]ip address 10.0.0.1 24
[SW1-Vlan-interface10]quit
[SW1]int vlan 20
[SW1-Vlan-interface20]ip address 20.0.0.1 24
[SW1-Vlan-interface20]quit
然后就可以ping通了
python
<H3C>ping 20.0.0.2
Ping 20.0.0.2 (20.0.0.2): 56 data bytes, press CTRL_C to break
56 bytes from 20.0.0.2: icmp_seq=0 ttl=254 time=6.000 ms
56 bytes from 20.0.0.2: icmp_seq=1 ttl=254 time=3.000 ms
56 bytes from 20.0.0.2: icmp_seq=2 ttl=254 time=2.000 ms
56 bytes from 20.0.0.2: icmp_seq=3 ttl=254 time=3.000 ms
56 bytes from 20.0.0.2: icmp_seq=4 ttl=254 time=3.000 ms
--- Ping statistics for 20.0.0.2 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 2.000/3.400/6.000/1.356 ms
%Dec 10 20:26:50:070 2023 H3C PING/6/PING_STATISTICS: Ping statistics for 20.0.0.2: 5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss, round-trip min/avg/max/std-dev = 2.000/3.400/6.000/1.356 ms.
总结
通过本节的学习,我们就能配置VLAN之间的相互访问了。
最后
大家如果喜欢我的文章,可以关注我的公众号(程序员麻辣烫)
我的个人博客为:shidawuhen.github.io/
往期文章回顾: