-
配置PC
配置IP地址、子网掩码、网关
-
配置SW0
Switch> en //进入全局模式 Switch# configure terminal //进入特权模式 Switch(config)# vlan 2 //声明vlan,如果要给一个接口划分vlan,先要声明 Switch(config-vlan)# ex Switch(config)# vlan 3 Switch(config-vlan)# ex Switch(config)# interface F0/2 Switch(config-if)# switchport mode access //命令作用为把这个接口划分为access口,这条命令在思科模拟器可不打,默认接口都为access口 Switch(config-if)# switchport access vlan 2 //为这个access接口添加vlan 2 Switch(config)# interface F0/3 Switch(config-if)# switchport mode access Switch(config-if)# switchport access vlan 3 Switch(config)# interface F0/1 Switch(config-if)# switchport mode trunk
-
配置R0
Router> en Router# configure terminal Router(config)# intface G0/0 //进入路由器接口 Router(config-if)# no shutdown //打开这个端口 //我们要配置的是单臂路由,是在这个物理路由接口上开启两个虚拟接口,充当不通vlan通信的网关 //这里只需要给这个接口开启即可 Router(config)# intface G0/0.2 //开启(进入)虚拟端口G0/0.2,这个0/0.几一般我们根据vlan来记 //一般这个端口对应的vlan几我们就是几,比如这个端口你要当vlan 3 的网关,就把它设为G0/0.3 Router(config-if)# ip address 192.168.1.1 255.255.255.0 //添加IP地址,作为对应vlan 的网关 Router(config-if)# encapsulation dot1Q 2 //这条命令为单臂路由的关键命令 //这条命令的作用是把这个接口对接在 vlan 2上,encapsulation dot1Q 后面的数字代表的数字 //代表这个虚拟接口配置的iP地址充当的是vlan几的网关 Router(config-if)# no shutdown //别忘了开启端口 Router(config)# intface G0/0.2 Router(config-if)# ip address 192.168.2.1 255.255.255.0 Router(config-if)# encapsulation dot1Q 3 Router(config-if)# no shutdown
-
进行实验验证
PC0 ping PC1 可通证明单臂路由配置成功