实验环境
在一台交换机上划分两个VLAN: Vlan2Vlan3
Vlan2包含PC1-2和PC1-3         Vlan3包含PC2-2和PC2-3
实验拓扑图拓扑图如下:
配置路由器
Router>enable
Router#config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#interface f0/0.1                                                         进入子接口 F0/0.1
Router(config-subif)#encapsulation dot1Q 2                                    封装IEEE802.1Q协议
Router(config-subif)#ip address 192.168.1.1 255.255.255.0            配置子接口的IP地址
Router(config-subif)#no shutdown
Router(config-subif)#exit
Router(config)#interface f0/0.2                                                         进入子接口F0/0.2
Router(config-subif)#encapsulation dot1Q 3                                    其中3是Vlan的ID,与上2同义
Router(config-subif)#ip address 192.168.2.1 255.255.255.0
Router(config-subif)#no shutdown
备注:在给子接口分配IP地址前务必要给子接口封装IEEE8.10或IEEE8.1Q协议,在做单臂路由时还要指定VLAN的ID号,一般子接口的IP地址为相应VLAN中机器的网关地址
配置交换机
Switch>
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#vlan 2                               新建Vlan ID为2
Switch(config-vlan)#name Vlan2              为刚建的vlan命名为vlan2
Switch(config-vlan)#exit
Switch(config)#vlan 3
Switch(config-vlan)#name Vlan3
Switch(config-vlan)#exit
Switch(config)#interface range f0/2 - 3                        指定接口范围,其中“ -”前后各有一个空格
Switch(config-if-range)#switchport access vlan 2         将上面的接口划分到vlan2中去
Switch(config-if-range)#exit
Switch(config)#interface range f0/4 - 5
Switch(config-if-range)#switchport access vlan 3
Switch(config-if-range)#exit
Switch(config)#interface f0/1                                        配置接口F0/1
Switch(config-if)#switchport mode trunk                       将F0/1配置成trunk模式,便于各vlan间交换数据
Switch(config-if)#no shutdown
Switch(config-if)#
测试结果
用vlan2中的 PC1-2( 192.168.1.2) ping PC2-2( 192.168.2.2)
测试通过,呵呵……!