# 一、实验名称 双臂路由、三层交换配置实验 # 二、实验目的 使用双臂路由、三层交换机的方式实现不同vlan间通信 # 三、实验内容 熟悉网络基本命令的使用。要实现不同Vlan间通信的实现,如何采用双臂路由、三层交换机的方式实现。 # 四、实验仪器 Cisco Packet Tracer Version:8.2.2.0400 # 五、实验原理 **双臂路由** 双臂路由是一种实现不同VLAN间通信的技术。通过将多个VLAN的流量汇聚到一个路由器接口,利用子接口的方式对不同VLAN的数据包进行标记和转发。这种方式需要在交换机端口与路由器之间建立trunk链路,以确保能够传输多个VLAN的数据。路由器根据数据包的802.1Q标签识别其所属VLAN,并依据路由表决定数据包的下一跳,从而实现跨VLAN的通信。 **单臂路由** 单臂路由是双臂路由的一种特殊情况,它也是基于路由器实现VLAN间通信的方法之一。与双臂路由不同的是,单臂路由通常只使用路由器的一个物理接口,该接口被划分为多个逻辑子接口,每个子接口对应一个VLAN。这些子接口通过802.1Q协议对来自不同VLAN的数据包进行封装和解封装操作,以此来区分不同的网络段,达到隔离广播域的目的。 **三层交换机** 三层交换机结合了二层交换机和路由器的功能,能够在硬件级别上提供更高效的路由处理能力。三层交换机可以直接为VLAN分配IP地址,并配置相应的路由信息,使得不同VLAN间的通信不再依赖于外部路由器。此外,三层交换机还可以设置trunk模式,用于连接其他交换设备并传输多个VLAN的信息。 # 六、实验过程及实验结果 ### 1. 双臂路由 ##### 1.1 基本拓扑连接 连接好的拓扑图如下 250413153604089.png 其中接口, IP, vlan信息如下 | 交换机 | 主机 | 连接端口 | IP | vlan | | ------- | ------------ | ------ | ------------- | ------- | | Switch0 | 接 PC0 | Fa0/1 | 192.168.10.11 | | | Switch0 | 接 PC1 | Fa0/2 | 192.168.10.12 | Vlan 10 | | Switch0 | 接 R 的 Fa0/0 | Fa0/23 | | | | Switch0 | 接 PC2 | Fa0/3 | 192.168.20.13 | | | Switch0 | 接 PC3 | Fa0/4 | 192.168.20.14 | Vlan 20 | | Switch0 | 接 R 的 Fa0/1 | Fa0/24 | | | | Router0 | 接 S 的 Fa0/23 | Fa0/0 | 192.168.10.1 | 无 Vlan | | Router0 | 接 S 的 Fa0/24 | Fa0/1 | 192.168.20.1 | | ##### 1.2 交换机划分vlan并分配端口 在交换机中执行以下命令, 为每个端口进行vlan划分 ```bash Switch> Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#vlan 10 Switch(config-vlan)#exit Switch(config)#vlan 20 Switch(config-vlan)#exit Switch(config)#int f0/1 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 10 Switch(config-if)#exit Switch(config)#int f0/2 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 10 Switch(config-if)#exit Switch(config)#int f0/3 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 20 Switch(config-if)#exit Switch(config)#int f0/4 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 20 Switch(config-if)#exit Switch(config)#int f0/23 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 10 Switch(config-if)#exit Switch(config)#int f0/24 Switch(config-if)#switchport mode access Switch(config-if)#switchport access vlan 20 Switch(config-if)#exit Switch(config)# Switch(config)#end Switch# %SYS-5-CONFIG_I: Configured from console by console Switch# ``` ##### 1.3 路由器接口设置 在路由器中进行如下设置 ```bash Router>en Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#int f0/0 Router(config-if)#ip address 192.168.10.1 255.255.255.0 Router(config-if)#no shut Router(config-if)# %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up Router(config-if)#int f0/1 Router(config-if)#ip address 192.168.20.1 255.255.255.0 Router(config-if)#no shut Router(config-if)# %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up Router(config-if)# ``` ##### 1.4 连通性测试 在PC1中尝试使用ping命令对其他三台主机进行连通性测试 250413153221819.png 在PC3中尝试使用ping命令对其他三台主机进行连通性测试 250413153428611.png 两个vlan间的连通性测试均成功, 说明双臂路由成功起到了沟通vlan的作用 ------ ### 2. 单臂路由 ##### 2.1 基本拓扑连接 250413155723176.png 其中接口, IP, vlan信息如下 | 名称 | 相连的接口 | IP地址 | **网关** | 子网掩码 | | --- | ----- | ----------- | ------------- | ------------- | | PC0 | F0/5 | 192.168.2.1 | 192.168.2.254 | 255.255.255.0 | | PC1 | F0/6 | 192.168.3.1 | 192.168.3.254 | 255.255.255.0 | | PC2 | F0/7 | 192.168.4.1 | 192.168.4.254 | 255.255.255.0 | | PC3 | F0/5 | 192.168.2.2 | 192.168.2.254 | 255.255.255.0 | | PC4 | F0/6 | 192.168.3.2 | 192.168.3.254 | 255.255.255.0 | | PC5 | F0/7 | 192.168.4.2 | 192.168.4.254 | 255.255.255.0 | ##### 2.2 交换机划分vlan并分配端口 在Swithc0中进行如下配置 ```bash swAen swA#config t SWA(config)#vlan 2 swA(config-vlan)#name vlan2 swA(config-vlan)#exit swA(config)#vlan 3 SwA(config-vlan)#name vlan3 swA(config-vlan)#exit swA(config)#vlan4 SwA(config-vlan)#name vlan4 swA(config-vlan)#exit swA#config t swA(congfig)#int F0/5 swA(congfig-if)#switchport mode access swA(congfig-if)#switchport access vlan 2 swA(congfig-if)#exit SwA(congfig)#int F0/6 swA(congfig-if)#switchport mode access swA(congfig-if)#switchport access vlan 3 swA(congfig-if)#exit swA(congfig)#int F0/7 swA(congfig-if)#switchport mode access swA(congfig-if)#switchport access vlan 4 swA(congfig-if)#end ``` 对Switch1的配置同上 ##### 2.3 路由器配置 首先在 `swA` 中, 将路由器与交换机连接的线路设置为 `trunk` 线路 ```bash SWA>en SWA#conf t Enter configuration commands, one per line. End with CNTL/Z. SWA(config)#int f0/1 SWA(config-if)#switch mode trunk ``` 然后在路由器中配置如下: ```bash Router>en Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#int f0/0.2 Router(config-subif)#encapsulation dot1q 2 Router(config-subif)#ip address 192.168.2.254 255.255.255.0 Router(config-subif)#int f0/0.3 Router(config-subif)#encap dot1q 3 Router(config-subif)#ip address 192.168.3.254 255.255.255.0 Router(config-subif)#int f0/0.4 Router(config-subif)#encap dot1q 4 Router(config-subif)#ip address 192.168.4.254 255.255.255.0 Router(config-subif)#int f0/0 Router(config-if)#no shutdown Router(config-if)# %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up %LINK-5-CHANGED: Interface FastEthernet0/0.2, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to up %LINK-5-CHANGED: Interface FastEthernet0/0.3, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.3, changed state to up %LINK-5-CHANGED: Interface FastEthernet0/0.4, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.4, changed state to up Router(config-if)#exit Router(config)# ``` ##### 2.4 连通性测试 再次尝试使用ping命令测试各个主机间的连通性, 发现任意两台PC相互之间都能ping通, 说明单臂路由成功起到了沟通vlan的作用 ----- ### 3. 三层交换机 ##### 3.1 基础拓扑连接 250413160402037.png 其中接口, IP, 网关信息如下 | 名称 | 相连的接口 | IP地址 | 网关 | | --- | ----- | ------------- | ------------- | | PC0 | F0/3 | 172.1.1.2/28 | 172.1.1.1/28 | | PC1 | F0/4 | 172.1.1.18/28 | 172.1.1.17/28 | | PC2 | F0/5 | 172.1.1.34/28 | 172.1.1.33/28 | | PC3 | F0/3 | 172.1.1.3/28 | 172.1.1.1/28 | | PC4 | F0/4 | 172.1.1.19/28 | 172.1.1.17/28 | | PC5 | F0/5 | 172.1.1.35/28 | 172.1.1.33/28 | ##### 3.2 交换机划分vlan并分配端口 在 Switch0 中进行如下配置 ```bash Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#vlan 10 Switch(config-vlan)#exit Switch(config)#vlan 20 Switch(config-vlan)#exit Switch(config)#vlan 30 Switch(config-vlan)#exit Switch(config)#int f0/3 Switch(config-if)#switchport access vlan 10 Switch(config-if)#int f0/4 Switch(config-if)#switchport access vlan 20 Switch(config-if)#int f0/5 Switch(config-if)#switchport access vlan 30 Switch(config-if)#end Switch# %SYS-5-CONFIG_I: Configured from console by console Switch# ``` 完成以上命令后使用 `show vlan` 得到输出如下 ![250413161730732.png](http://IMG-HOST-REMOVED/blog-img/2025-04/250413161730732_1744532250794.png) Switch1 中配置同上, 输出同样类似 ##### 3.3 二层交换机设置 trunk 模式 分别将 Switch0 和 Switch1 与三层交换机相连的接口 F0/1 、F0/1 设置vlan中继(trunk模式) ```bash Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#int f0/1 Switch(config-if)#switchport mode trunk Switch(config-if)#exit Switch(config)# ``` 完成以上命令后使用 `show int trunk` 得到输出如下 250413162305861.png Swtich1 中配置同上 ##### 3.4 三层交换机配置vlan与IP 首先启用三层交换机的路由功能 然后进行如下配置 ```bash Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#int vlan 10 Switch(config-if)# %LINK-5-CHANGED: Interface Vlan10, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up Switch(config-if)#ip address 172.1.1.1 255.255.255.240 Switch(config-if)#exit Switch(config)#int vlan 20 Switch(config-if)# %LINK-5-CHANGED: Interface Vlan20, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up Switch(config-if)#ip address 172.1.1.17 255.255.255.240 Switch(config-if)#exit Switch(config)#int vlan 30 Switch(config-if)# %LINK-5-CHANGED: Interface Vlan30, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to up Switch(config-if)#ip address 172.1.1.33 255.255.255.240 Switch(config-if)#exit Switch(config)# ``` 完成以上命令后使用 `show int vlan 10` 得到输出如下 250413162738714.png ##### 3.5 三层交换机配置trunk模式 ```bash Switch(config)#int f0/1 Switch(config-if)#switchport trunk encap dot1q Switch(config-if)#switchport mode trunk Switch(config-if)#exit Switch(config)#int f0/2 Switch(config-if)#switchport trunk encap dot1q Switch(config-if)#switchport mode trunk Switch(config-if)#exit Switch(config)# ``` ##### 3.6 三层交换机优先级配置 ```bash Switch(config)#spanning-tree vlan 1 priority 0 Switch(config)#spanning-tree vlan 10 priority 0 Switch(config)#spanning-tree vlan 20 priority 0 Switch(config)#spanning-tree vlan 30 priority 0 Switch(config)#exit Switch# ``` 完成以上命令后使用 `show spanning-tree` 得到输出如下 250413163102909.png ##### 3.7 连通性测试 在PC0中对其他vlan中的主机进行ping测试, 发现均能ping通, 说明三层交换机成功起到了沟通vlan的作用 250413165407138.png # 七、讨论与结论 ##### 讨论 - **双臂路由 与 单臂路由**:两种方法都能实现VLAN间的通信,但双臂路由由于使用了两个物理接口,理论上可以提供更高的带宽和更好的故障隔离。然而,在实际应用中,单臂路由因其简洁性和成本效益而更为常用。 - **三层交换机的优势**:相比于传统的双臂或单臂路由方案,三层交换机提供了更高的效率和更低的延迟,特别适用于大型企业网络环境。其强大的路由功能和快速的转发速度使其成为构建高性能网络的理想选择。 ##### 结论 本实验通过搭建不同场景下的网络拓扑结构,深入探讨了如何利用双臂路由、单臂路由以及三层交换机来实现VLAN间的通信。实验结果表明,三种方法都能够有效地解决VLAN间的通信问题,但在具体应用场景中,应根据实际需求选择最合适的技术方案。三层交换机以其高效能和低延迟的特点,成为了现代网络架构中的首选解决方案。同时,实验也强调了良好的网络设计和安全管理的重要性,这对于确保网络稳定运行至关重要。