案例10利用三层交换机实现不同vlan间通信【背景描述】某企业有两个主要部门:销售部和技术部,其中销售部的个人计算机系统分散连接在两台交换机上,他们之间需要相互进行通信,销售部和技术部也需要进行相互通信,现要在交换机上做适当配置来实现这一目标。【实现功能】使在同一VLAN里的计算机系统能跨交换机进行通信,而在不同VLAN里的计算机系统也能进行相互通信。【使用设备】设备类型设备名称设备数量交换机Switch01路由器三层交换机Switch11双绞线4计算机pc3【实验拓扑】表1设备基本信息设备名端口及所属VLANIP信息IP地址网关Switch13560Fa0/24默认VLANSwitch02960Fa0/24默认VLANPC0Fa0/5VLAN10192.168.10.10/24192.168.10.254/24PC1Fa0/15VLAN20192.168.20.20/24192.168.20.254/24PC2Fa0/5VLAN10192.168.10.30/24192.168.10.254/24【实现步骤】步骤1.在交换机Switch1上创建vlan10,并将0/5端口划分到vlan10中.Switch1enableSwitch1#configureterminalSwitch1(config)#vlan10Switch1(config-vlan)#namesalesSwitch1(config-vlan)#exitSwitch1(config)#interfacefastEthernet0/5Switch1(config-if)#switchportaccessvlan10Switch1(config-if)#exitSwitch1(config)#vlan20Switch1(config-vlan)#nametechnicalSwitch1(config-vlan)#exitSwitch1(config)#interfacevlan20Switch1(config-if)#exitSwitch1(config)#interfacefastEthernet0/15Switch1(config-if)#switchportaccessvlan20Switch1(config-if)#exit步骤2.把交换机Swich0和Swich1相连的端口定义为tagvlan模式SwitchA(config)#interfacefastEthernet0/24SwitchA(config-if)#switchportmodetrunk!将F0/24端口定义为tagvlan模式验证测试:验证F0/24端口已被设为tagvlan模式SwitchA#showinterfacesfastEthernet0/24switchportInterfaceSwitchportModeAccessNativeProtectedVLANlists------------------------------------------------------------Fa0/24EnabledTrunk11DisabledAll步骤3.在交换机Swich1上创建vlan10,并将0/5端口划分到vlan10中.SwichB(config)#vlan10SwichB(config-vlan)#namesalseSwichB(config-vlan)#exitSwichB(config)#interfacefastEthernet0/5SwichB(config-if)#switchportaccessvlan10步骤4.把交换机Swich0和Swich1相连的端口定义为tagvlan模式SwichB(config)#interfacefastEthernet0/24SwichB(config-if)#switchportmodetrunk验证测试:验证F0/24端口已被设置为tagvlan模式SwichB#showinterfacesfastEthernet0/24switchportInterfaceSwitchportModeAccessNativeProtectedVLANlists---------------------------------------------------------------Fa0/24EnabledTrunk11DisabledAll步骤5.验证PC0与PC2能相互通信,但PC0和PC1不能相互通信。C:\DocumentsandSettings\Administratorping192.168.10.30!在PC1的命令行方式下能ping通PC3Pinging192.168.10.30with32bytesofdata:Replyfrom192.168.10.30:bytes=32time1msTTL=128Replyfrom192.168.10.30:bytes=32time1msTTL=128Replyfrom192.168.10.30:bytes=32time1msTTL=128Replyfrom192.168.10.30:bytes=32time1msTTL=128Pingstatisticsfor192.168.10.30:Packets:Sent=4,Received=4,Lost=0(0%loss),Approximateroundtriptimesinmilli-seconds:Minimum=0ms,Maximum=0ms,Average=0msC:\DocumentsandSettings\Administratorping192.168.10.30!在PC1的命令行方式下验证不能ping通PC2Pinging192.168.10.30with32bytesofdata:Requesttimedout.Requesttimedout.Requesttimedout.Requesttimedout.Pingstatisticsfor192.168.10.30:Packets:Sent=4,Received=0,Lost=4(100%loss),步骤6.设置三层交换机VLAN间通信Switch1(config)#interfacevlan10!创建虚拟接口vlan10Switch1(config-if)#ipaddress192.168.10.254255.255.255.0!配置虚拟接口vlan10的地址为192.168.10.254Switch1(config-if)#noshutdown!开启端口2009-05-2316:42:39@5-CONFIG:ConfiguredfromoutbandSwitch1(config-if)#exit2009-05-2316:42:42@5-CONFIG:ConfiguredfromoutbandSwitch1(config)#interfacevlan20!创建虚拟接口vlan202009-05-2316:42:46@5-CONFIG:ConfiguredfromoutbandSwitch1(config-if)#ipaddress192.168.20.254255.255.255.0!配置虚拟接口的地址为192.168.20.2542009-05-2316:43:06@5-CONFIG:ConfiguredfromoutbandSwitch1(config-if)#noshutdown!开启端口2009-05-2316:43:09@5-CONFIG:ConfiguredfromoutbandSwitch1(config-if)#exit2009-05-2316:43:15@5-CONFIG:Configuredfromoutband验证测试:查看S3550路由器的状态Switch1#showipinterface!查看IP接口的状态Interface:VL10Description:Vlan10OperStatus:upManagementStatus:EnabledPrimaryInternetaddress:192.168.10.254/24Broadcastaddress:255.255.255.255PhysAddress:00d0.f8b8.289cInterface:VL20Description:Vlan20OperStatus:upManagementStatus:EnabledPrimaryInternetaddress:192.168.20.254/24Broadcastaddress:255.255.255.255PhysAddress:00d0.f8b8.289b步骤7.将PC0和PC2的网关设置为192.168.10.254,将PC1的默认网关设置成192.168.20.254测试结果:不同vlan间的主机可以相互ping通参考配置Swich1#showrunning-config!显示交换机Swich1的全部配置Systemsoftwareversion:2.41(4)BuildNov232005ReleaseBuildingconfiguration...Currentconfiguration:413bytes!version1.0!hostnameSwich1vlan1!vlan10namesales!vlan20nametechnical!interfaceFastEthernet0/5switchportaccessvlan10!interfaceFastEthernet0/15switchportaccessvlan20!interfaceFastEthernet0/24switchportmodetrunk!interfaceVlan10ipaddress192.168.10.254255.255.255.0!interfaceVlan20ipaddress192.168.20.254255.255.255.0!endSwich0#showrunning-config!显示交换机Swich0的全部配置Systemsoftwareversion:1.61(2)BuildAug312005ReleaseBuildingconfiguration...Currentconfiguration:194bytesversion1.0!hostnameSwich0vlan1!vlan10namesalse!interfacefastEthernet0/5switchportaccessvlan10!interfacefastEthernet0/24switchportmodetrunk!End验证:PC0pingPC1【注意事项】1.两台交换机之间相连的端口应该设置为tagvlan模式2.需要设置PC的网关若拓扑结构改成如下:表2设备基本信息设备名端口及所属VLANIP信息IP地址网关Switch3560Fa0/24默认VLANSwitch02960Fa0/24默认VLANSwitch12960Fa0/23默认VLANPC0Fa0/5VLAN10192.168.10.10/24192.168.10.254/24PC1Fa0/15VLAN20192.168.20.20/24192.168.20.254/24PC2Fa0/5VLAN10192.168.10.30/24192.168.10.254/24PC3Fa0/15VLAN20192.168.20.40/24192.168.20.254/24Laptop0Fa0/5VLAN10192.168.10.50/24192.168.10.254/24Laptop1Fa0/15VLAN30192.168.30.60/24192.168.30.254/24