在三層交換機和二層交換機做如何配置使這兩臺主機ping通
第1種,在網絡中不劃分VLAN時,網絡二層互通,不需要通過路由,則將2臺電腦的IP地址設置為同壹網段的地址,比如PC1 為192.168.1.1/24,PC2 為192.168.1.2/24,就可以互通。
第2種,在二層交換機上劃分了VLAN,那麽,假設圖左邊的交換機為S1,接口VLAN ID為10,右邊的交換機為S2,接口VLAN ID為20,那麽需要將2個二層交換機的上行口配置為TRUNK方式,並在三層交換機上配置2個VLAN的網關地址。同時在2臺主機上配置相應網段的IP以及網關地址。
具體配置如下:
二層交換機S1:
S1#vlan database
S1(vlan)#vlan 10
S1(vlan)#exit
S1#conf t
S1(config)#int f0/2
S1(config-if)#switchport mode access
S1(config-if)#switchport acc vlan 10
S1(config)#int f0/1
S1(config-if)#switchport mode trunk
二層交換機S2:
S2#vlan database
S2(vlan)#vlan 20
S2(vlan)#exit
S2#conf t
S2(config)#int f0/2
S2(config-if)#switchport mode access
S2(config-if)#switchport acc vlan 20
S2(config)#int f0/1
S2(config-if)#switchport mode trunk
三層交換機S3:
S3#vlan database
S3(vlan)#vlan 10
S3(vlan)#vlan 20
S3(vlan)#exit
S3#conf t
S3(config)#interface vlan 10
S3(config-if)#ip add 192.168.10.1 255.255.255.0
S3(config-if)#int vl 20
S3(config-if)#ip add 192.168.20.1 255.255.255.0
S3(config-if)#end
S3#sh ip route
Gateway of last resort is not set
C 192.168.10.0/24 is directly connected, Vlan10
C 192.168.20.0/24 is directly connected, Vlan20
配置完成,然後將PC1的地址設置為192.168.10.2,掩碼255.255.255.0,網關192.192.168.10.1
PC2的地址設置為192.168.20.2,掩碼255.255.255.0,網關192.192.168.20.1
在PC2 Ping PC1,有如下結果:
PC>ping 192.168.10.2
Pinging 192.168.10.2 with 32 bytes of data:
Request timed out.
Reply from 192.168.10.2: bytes=32 time=125ms TTL=127
Reply from 192.168.10.2: bytes=32 time=124ms TTL=127
Reply from 192.168.10.2: bytes=32 time=110ms TTL=127