首先在交换机中划分好VLAN,配置如下:
Switch0:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10 创建vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#vlan 30
Switch(config-vlan)#int f0/2
Switch(config-if)#switchport access vlan 10 将该接口划分到vlan 10
Switch(config-if)#int f0/3
Switch(config-if)#switchport access vlan 20
Switch(config-if)#int f0/4
Switch(config-if)#switchport access vlan 30
Switch(config-if)#int f0/1
Switch(config-if)#switchport mode trunk 将该接口的模式设置为中继模式 划分好vlan好,现在开始用PC 0 去ping PC1 和 PC2
从图中可以看出不同VLAN 之间无法进行通信,下面我们就需要通过路由器实现不同VLAN间的通信。
Router0:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#no shut 开启该接口
%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/0.1 进入1号子接口
%LINK-5-CHANGED: Interface FastEthernet0/0.1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.1, changed state to up
Router(config-subif)#encapsulation dot1Q 10 封装802.1Q协议,10是VLAN 10 Router(config-subif)#ip add 172.16.10.1 255.255.255.0 Router(config-subif)#int f0/0.2 %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 Router(config-subif)#encapsulation dot1Q 20 Router(config-subif)#ip add 172.16.20.1 255.255.255.0 Router(config-subif)#int f0/0.3 %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
Router(config-subif)#encapsulation dot1Q 30
Router(config-subif)#ip add 172.16.30.1 255.255.255.0
配置完毕,接下来看看配置的结果如何,继续用PC0 ping PC1 和 PC2