任务 9:配置 802.1q 子接口,使路由器能同时连入多个 vlan
步骤 1:将 R1 的 Fa0/0 的 IP 改为 192.168.100.1/24(R1 现在是 vlan100 的网络设备)
R1>enable R1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface fastEthernet 0/0 R1(config-if)#ip address 192.168.100.1 255.255.255.0 R1(config-if)#exit
步骤 2:进入 SW2 的 Fa0/4,将该接口配置为 Trunk 接口(如果需要,先指定封装为 802.1q)
SW2>enable SW2#configure terminal Enter configuration commands, one per line. End with CNTL/Z. SW2(config)#interface fastEthernet 0/4 SW2(config-if)#switchport trunk encapsulation dot1q SW2(config-if)#switchport mode trunk SW2(config-if)#end SW2#
步骤 3:检查 SW2 的 trunk 接口,确保 Fa0/4 的状态是 “Trunking”
SW2#show interfaces trunk Port Mode Encapsulation Status Native vlan Fa0/4 on 802.1q trunking 1 Fa0/24 on 802.1q trunking 1 Port Vlans allowed on trunk Fa0/4 1-1005 Fa0/24 1-1005 Port Vlans allowed and active in management domain Fa0/4 1,200 Fa0/24 1,200 Port Vlans in spanning tree forwarding state and not pruned Fa0/4 none Fa0/24 1,200
步骤 4:进入 R4 的 Fa0/1(如果没有 Fa0/1,则使用 E0/1),将该接口原先的 IP 配置去掉, 并保持该接口开启
R4>enable R4#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R4(config)#interface fastEthernet 0/1 R4(config-if)#no ip address R4(config-if)#exit
步骤 5:在 R4 的全局配置模式下,创建一个子接口 Fa0/1.1
R4(config)#interface fastEthernet 0/1.1
R4(config-subif)#
步骤 6:指定 Fa0/1.1 的 dot1q 标记值为 100,表示该子接口连入 vlan100
R4(config-subif)#encapsulation dot1Q 100
R4(config-subif)#
步骤 7:配置 Fa0/1.1 的 IP 为 192.168.100.4/24
R4(config-subif)#ip address 192.168.100.4 255.255.255.0
R4(config-subif)#exit
R4(config)#
步骤 8:在 R4 的全局配置模式下,再创建一个子接口 Fa0/1.2
R4(config)#interface fastEthernet 0/1.2
R4(config-subif)#
步骤 9:指定 Fa0/1.2 的 dot1q 标记值为 200,表示该子接口连入 vlan200
R4(config-subif)#encapsulation dot1Q 200
R4(config-subif)#
步骤 10:配置 Fa0/1.2 的 IP 为 192.168.0.4/24
R4(config-subif)#ip address 192.168.0.4 255.255.255.0
R4(config-subif)#exit
步骤 11:检查 R4 的接口状态列表,会看到 2 个网段的虚拟接口,这两个接口分别可以和各自 vlan 的设备通信
R4#show protocols Global values: Internet Protocol routing is enabled FastEthernet0/0 is administratively down, line protocol is down FastEthernet0/1 is up, line protocol is up FastEthernet0/1.1 is up, line protocol is up Internet address is 192.168.100.4/24 FastEthernet0/1.2 is up, line protocol is up Internet address is 192.168.0.4/24 Vlan1 is administratively down, line protocol is down
步骤 12:在 R4 上,使用 ping 测试,发现 R4 能同时 ping 通 vlan100 的主机(R1, 192.168.100.1)以及 vlan200 的主机(R2,192.168.0.2 和 R3,192.168.0.3)
R4#ping 192.168.100.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.100.1, timeout is 2 seconds: .!!!! Success rate is 80 percent (4/5), round-trip min/avg/max = 0/0/0 ms
R4#ping 192.168.0.2 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.0.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 0/0/1 ms
R4#ping 192.168.0.3 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.0.3, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 0/0/0 m