2017.5.2下午

PC1

IP: 192.168.1.2

Submark: 255.255.255.0

Gateway: 192.168.1.1

PC2

IP: 192.168.2.2

Submark: 255.255.255.0

Gateway: 192.168.2.1

PC3

IP: 192.168.1.3

Submark: 255.255.255.0

Gateway: 192.168.1.1

PC1 Ping PC3

Ping 192.168.1.3  reply

PC1 Ping PC2         

Ping 192.168.2.2   timeout

S2960

Switch>en

Switch#conf t

Switch(config )#vlan 2

Switch(config-vlan)#exit

Switch(config )#vlan 3

Switch(config-vlan)#exit

Switch(config )#int fa 0/2

Switch(config-if)#switchport access vlan 2

Switch(config-if)#exit

Switch(config )#int fa 0/3

Switch(config-if)#switchport access vlan 3

Switch(config-if)#exit

Switch(config )#int fa 0/1

Switch(config-if)#switchport  mode  trunk

Switch(config-if)#end

Switch#show vlan

S3560

Switch>en

Switch#conf t

Switch(config )#vlan 2  //新建vlan 2

Switch(config-vlan)#exit

Switch(config )#vlan 3  //新建vlan 3

Switch(config-vlan)#exit

Switch(config )#int fa 0/1  //进入0模块第1端口

Switch(config-if)#switchport trunk encapsulation dot1q //给这个接口的trunk封装为802.1Q的帧格式

Switch(config-if)#switchport mode trunk  //定义这个接口的工作模式为trunk

Switch(config-if)#exit

Switch(config )#int fa 0/2   //进入0模块第2端口

Switch(config-if)#switchport access vlan 2  //当前端口加入vlan 2

Switch(config-if)#exit

Switch(config )#interface vlan 2  //进入vlan2 虚拟接口

Switch(config-if)#ip address 192.168.1.1 255.255.255.0  //配置IP地址

Switch(config-if)#no shutdown  //开启该端口

Switch(config-if)#exit

Switch(config )#interface vlan 3

Switch(config-if)#ip address 192.168.2.1 255.255.255.0

Switch(config-if)#no shutdown

Switch(config-if)#end

Switch#show ip route  //显示路由表

Switch#show vlan   //显示vlan信息

PC1 Ping PC3

Ping 192.168.1.3  reply

PC1 Ping PC2         

Ping 192.168.2.2   reply

原文地址:https://www.cnblogs.com/bgd140206206/p/6798836.html