教你利用三层交换机实现VLAN间路由

教你利用三层交换机实现VLAN间路由

2023年7月20日发(作者:)

教你利⽤三层交换机实现VLAN间路由本⽂档详细介绍利⽤三层交换机实现 VLAN 间路由,⽂内含长段代码可复制可往左滑,希望对⼤家有帮助!实验背景某企业有两个主要部门,技术部和销售部,分处于不同的办公室,为了安全和便于管理对两个部门的主机进⾏了 VLAN 的划分,技术部和销售部分处于不同的VLAN,先由于业务的需求需要销售部和技术部的主机能够相互访问,获得相应的资源,两个部门的交换机通过⼀台三层交换机进⾏了连接。技术原理三层交换机具备⽹络层的功能,实现 VLAN 相互访问的原理是:利⽤三层交换机的路由功能,通过识别数据包的 IP 地址,查找路由表进⾏选路转发,三层交换机利⽤直连路由可以实现不同 VLAN 之间的相互访问。三层交换机给接⼝配置 IP 地址。采⽤ SVI(交换虚拟接⼝)的⽅式实现 VLAN 间互连。SVI 是指为交换机中的VLAN 创建虚拟接⼝,并且配置 IP 地址。Tag VLAN是基于交换机端⼝的⼀种类型,主要⽤于使交换机的相同Vlan内的主机之间可以直接访问,同时对于不同Vlan的主机进⾏隔离。trunk主要⽤在连接其它交换机,以便在线路上承载多个vlanWLAN是Wireless Local Area Network的简称,指应⽤⽆线通信技术将计算机设备互联起来,构成可以互相通信和实现资源共享的⽹络体系。802.1x协议是WLAN第⼆代的认证技术,它是基于客户端-服务器(Client-Server)结构的访问控制和认证协议。它可以限制未经授权的⽤户/设备通过接⼊端⼝(Access Port)访问LAN/WLAN。DOT1Q是提供VLAN识别和服务质量(QoS)级别的IEEE标准。电⽓和电⼦⼯程师协会(IEEE,全称是Institute of Electrical and Electronics Engineers)是⼀个美国的电⼦技术与信息科学⼯程师的协会,是世界上最⼤的⾮营利性专业技术学会。ip routing 启⽤IP路由功能no ip routing 关闭IP路由功能⼆层交换机与三层交换机区别我们习惯说,在⼆层⽹络环境中相同vlan之间可以通信,不同vlan之间不可以通信,如果想通信必须借助三层设备,所以说三层交换机必须要做的事情是路由转发,但是⼆、三层交换机具体有什么区别呢?⼆层交换机⼯作于OSI模型的第2层(数据链路层),故⽽称为⼆层交换机。⼆层交换技术发展⽐较成熟,⼆层交换机属数据链路层设备,可以识别数据包中的MAC地址信息,根据MAC地址进⾏转发,并将这些MAC地址与对应的端⼝记录在⾃⼰内部的⼀个地址表中。具体的⼯作流程如下:(1) 当交换机从某个端⼝收到⼀个数据包,它先读取包头中的源MAC地址,这样它就知道源MAC地址的机器是连在哪个端⼝上的;(2) 再去读取包头中的⽬的MAC地址,并在地址表中查找相应的端⼝;(3) 如表中有与这⽬的MAC地址对应的端⼝,把数据包直接复制到这端⼝上;(4) 如表中找不到相应的端⼝则把数据包⼴播到所有端⼝上,当⽬的机器对源机器回应时,交换机⼜可以学习⼀⽬的MAC地址与哪个端⼝对应,在下次传送数据时就不再需要对所有端⼝进⾏⼴播了。不断的循环这个过程,对于全⽹的MAC地址信息都可以学习到,⼆层交换机就是这样建⽴和维护它⾃⼰的地址表。⼆层交换技术从⽹桥发展到VLAN(虚拟局域⽹),在局域⽹建设和改造中得到了⼴泛的应⽤。第⼆层交换技术是⼯作在OSI七层⽹络模型中的第⼆层,即数据链路层。它按照所接收到数据包的⽬的MAC地址来进⾏转发,对于⽹络层或者⾼层协议来说是透明的。它不处理⽹络层的IP地址,不处理⾼层协议的诸如TCP、UDP的端⼝地址,它只需要数据包的物理地址即MAC地址,数据交换是靠硬件来实现的,其速度相当快,这是⼆层交换的⼀个显著的优点。但是,它不能处理不同IP⼦⽹之间的数据交换。传统的路由器可以处理⼤量的跨越IP⼦⽹的数据包,但是它的转发效率⽐⼆层低,因此要想利⽤⼆层转发效率⾼这⼀优点,⼜要处理三层IP数据包,三层交换技术就诞⽣了。三层交换(也称多层交换技术,或IP交换技术)是相对于传统交换概念⽽提出的。众所周知,传统的交换技术是在OSI⽹络标准模型中的第⼆层——数据链路层进⾏操作的,⽽三层交换技术是在⽹络模型中的第三层实现了数据包的⾼速转发。简单地说,三层交换技术就是:⼆层交换技术+三层转发技术。三层交换机就是具有部分路由器功能的交换机。三层交换机的最重要⽬的是加快⼤型局域⽹内部的数据交换,所具有的路由功能也是为这⽬的服务的,能够做到⼀次路由,多次转发。对于数据包转发等规律性的过程由硬件⾼速实现,⽽像路由信息更新、路由表维护、路由计算、路由确定等功能,由软件实现。三层交换技术就是⼆层交换技术+三层转发技术。三层交换技术的出现,解决了局域⽹中⽹段划分之后,⽹段中⼦⽹必须依赖路由器进⾏管理的局⾯,解决了传统路由器低速、复杂所造成的⽹络瓶颈问题。实验步骤新建 packet tracer 拓扑图

(1)在⼆层交换机上配置 VLAN2、VLAN3,分别将端⼝ 2、端⼝ 3 划分给 VLAN2、VLAN3。(2)将⼆层交换机与三层交换机相连的端⼝ fa 0/1 都定义为 tag Vlan 模式。(3)在三层交换机上配置 VLAN2、VLAN3,此时验证⼆层交换机 VLAN2、VLAN3下的主机之间不能相互通信。(4)设置三层交换机 VLAN 间的通信,创建 VLAN2,VLAN3 的虚接⼝,并配置虚接⼝ VLAN2、VLAN3 的 IP 地址。(5)查看三层交换机路由表。(6)将⼆层交换机 VLAN2、VLAN3 下的主机默认⽹关分别设置为相应虚拟接⼝的 IP 地址。(7)验证⼆层交换机 VLAN2,VALN3 下的主机之间可以相互通信。实验设备Switch_2960 1 台;Swithc_3560 1 台;PC 3 台;直连线PC1IP: 192.168.1.2Submark: 255.255.255.0Gateway: 192.168.1.1PC2IP: 192.168.2.2Submark: 255.255.255.0Gateway: 192.168.2.1PC3IP: 192.168.1.3Submark: 255.255.255.0Gateway: 192.168.1.1S2960enconf tvlan 2exitvlan 3exitint fa 0/2switchport access vlan 2int fa 0/3switchport access vlan 3int fa 0/1switchport mode trunkendshow vlanS3560enconf tvlan 2exitvlan 3exitint fa 0/1switchport trunk encapsulation dot1q #将0/1端⼝封装成dot1q协议switchport mode trunkexitint fa 0/2switchport access vlan 2exitinterface vlan 2ip address 192.168.1.1 255.255.255.0no shutdownexitinterface vlan 3ip address 192.168.2.1 255.255.255.0no shutdownexitip routingexitshow ip routeshow vlanPC3 Ping PC1Ping 192.168.1.2PC3 Ping PC2Ping 192.168.1.3<以上代码可复制粘贴,可往左滑>实战演练⼆层交换机Switch>enSwitch#conf tEnter configuration commands, one per line. End with CNTL/(config)#vlan 2Switch(config-vlan)#exitSwitch(config)#vlan 3Switch(config-vlan)#int fa 0/2Switch(config-if)#switchport access vlan 2Switch(config-if)#int fa 0/3Switch(config-if)#switchport access vlan 3Switch(config-if)#int fa 0/1Switch(config-if)#switchport mode trunk%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upSwitch(config-if)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#show vlanVLAN Name Status Ports---- -------------------------------- --------- -------------------------------1 default active Fa0/4, Fa0/5, Fa0/6, Fa0/7Fa0/8, Fa0/9, Fa0/10, Fa0/11Fa0/12, Fa0/13, Fa0/14, Fa0/15Fa0/16, Fa0/17, Fa0/18, Fa0/19Fa0/20, Fa0/21, Fa0/22, Fa0/23Fa0/24, Gig1/1, Gig1/22 VLAN0002 active Fa0/23 VLAN0003 active Fa0/31002 fddi-default act/unsup1003 token-ring-default act/unsup1004 fddinet-default act/unsup1005 trnet-default act/unsupVLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------1 enet 100001 1500 - - - - - 0 02 enet 100002 1500 - - - - - 0 03 enet 100003 1500 - - - - - 0 01002 fddi 101002 1500 - - - - - 0 0--More--三层交换机Switch>enSwitch#conf tEnter configuration commands, one per line. End with CNTL/(config)#vlan 2Switch(config-vlan)#exitSwitch(config)#vlan 3Switch(config-vlan)#exitSwitch(config)#int fa 0/1Switch(config-if)#switchport trunk encapsulation dot1qSwitch(config-if)#switchport mode trunkSwitch(config-if)#switchport trunk allowed vlan 2,3Switch(config-if)#exitSwitch(config)#int fa 0/2Switch(config-if)#switchport access vlan 2Switch(config-if)#exitSwitch(config)#int vlan 2%LINK-5-CHANGED: Interface Vlan2, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan2, changed state to upSwitch(config-if)#ip address 192.168.1.1 255.255.255.0Switch(config-if)#no shutdownSwitch(config-if)#exitSwitch(config)#int vlan 3%LINK-5-CHANGED: Interface Vlan3, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan3, changed state to upSwitch(config-if)#ip address 192.168.2.1 255.255.255.0Switch(config-if)#no shutdownSwitch(config-if)#exitSwitch(config)#ip routingSwitch(config)#exitSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#show ip routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter areaN1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGPi - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area* - candidate default, U - per-user static route, o - ODRP - periodic downloaded static routeGateway of last resort is not setC 192.168.1.0/24 is directly connected, Vlan2C 192.168.2.0/24 is directly connected, Vlan3Switch#show vlanVLAN Name Status Ports---- -------------------------------- --------- -------------------------------1 default active Fa0/3, Fa0/4, Fa0/5, Fa0/6Fa0/7, Fa0/8, Fa0/9, Fa0/10Fa0/11, Fa0/12, Fa0/13, Fa0/14Fa0/15, Fa0/16, Fa0/17, Fa0/18Fa0/19, Fa0/20, Fa0/21, Fa0/22Fa0/23, Fa0/24, Gig0/1, Gig0/22 VLAN0002 active Fa0/23 VLAN0003 active1002 fddi-default act/unsup1003 token-ring-default act/unsup1004 fddinet-default act/unsup1005 trnet-default act/unsupVLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------1 enet 100001 1500 - - - - - 0 02 enet 100002 1500 - - - - - 0 03 enet 100003 1500 - - - - - 0 01002 fddi 101002 1500 - - - - - 0 0--More--<以上代码可复制粘贴,可往左滑>

测试PC1 分别 ping PC2 和 PC3PC>: 192.168.1.: 255.255.255.: 192.168.1.1PC>ping 192.168.2.2Pinging 192.168.2.2 with 32 bytes of data:Request timed from 192.168.2.2: bytes=32 time=25ms TTL=127Reply from 192.168.2.2: bytes=32 time=20ms TTL=127Reply from 192.168.2.2: bytes=32 time=20ms TTL=127Ping statistics for 192.168.2.2:Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),Approximate round trip times in milli-seconds:Minimum = 20ms, Maximum = 25ms, Average = 21msPC>ping 192.168.2.2Pinging 192.168.2.2 with 32 bytes of data:Reply from 192.168.2.2: bytes=32 time=18ms TTL=127Reply from 192.168.2.2: bytes=32 time=23ms TTL=127Reply from 192.168.2.2: bytes=32 time=19ms TTL=127Reply from 192.168.2.2: bytes=32 time=22ms TTL=127Ping statistics for 192.168.2.2:Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:Minimum = 18ms, Maximum = 23ms, Average = 20msPC>ping 192.168.1.3Pinging 192.168.1.3 with 32 bytes of data:Reply from 192.168.1.3: bytes=32 time=15ms TTL=128Reply from 192.168.1.3: bytes=32 time=19ms TTL=128Reply from 192.168.1.3: bytes=32 time=15ms TTL=128Reply from 192.168.1.3: bytes=32 time=14ms TTL=128Ping statistics for 192.168.1.3:Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:Minimum = 14ms, Maximum = 19ms, Average = 15msPC2 分别 ping PC1 和 PC3PC>: 192.168.2.: 255.255.255.: 192.168.2.1PC>ping 192.168.1.2Pinging 192.168.1.2 with 32 bytes of data:Reply from 192.168.1.2: bytes=32 time=24ms TTL=127Reply from 192.168.1.2: bytes=32 time=23ms TTL=127Reply from 192.168.1.2: bytes=32 time=24ms TTL=127Reply from 192.168.1.2: bytes=32 time=20ms TTL=127Ping statistics for 192.168.1.2:Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:Minimum = 20ms, Maximum = 24ms, Average = 22msPC>ping 192.168.1.3Pinging 192.168.1.3 with 32 bytes of data:Reply from 192.168.1.3: bytes=32 time=13ms TTL=127Reply from 192.168.1.3: bytes=32 time=17ms TTL=127Reply from 192.168.1.3: bytes=32 time=19ms TTL=127Reply from 192.168.1.3: bytes=32 time=19ms TTL=127Ping statistics for 192.168.1.3:Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:Minimum = 13ms, Maximum = 19ms, Average = 17msPC3 分别 ping PC1 和 PC2PC>: 192.168.1.: 255.255.255.: 192.168.1.1PC>ping 192.168.1.2Pinging 192.168.1.2 with 32 bytes of data:Reply from 192.168.1.2: bytes=32 time=14ms TTL=128Reply from 192.168.1.2: bytes=32 time=17ms TTL=128Reply from 192.168.1.2: bytes=32 time=17ms TTL=128Reply from 192.168.1.2: bytes=32 time=16ms TTL=128Ping statistics for 192.168.1.2:Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:Minimum = 14ms, Maximum = 17ms, Average = 16msPC>ping 192.168.2.2Pinging 192.168.2.2 with 32 bytes of data:Request timed from 192.168.2.2: bytes=32 time=17ms TTL=127Reply from 192.168.2.2: bytes=32 time=16ms TTL=127Reply from 192.168.2.2: bytes=32 time=18ms TTL=127Ping statistics for 192.168.2.2:Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),Approximate round trip times in milli-seconds:Minimum = 16ms, Maximum = 18ms, Average = 17msPC>ping 192.168.2.2Pinging 192.168.2.2 with 32 bytes of data:Reply from 192.168.2.2: bytes=32 time=15ms TTL=127Reply from 192.168.2.2: bytes=32 time=17ms TTL=127Reply from 192.168.2.2: bytes=32 time=14ms TTL=127Reply from 192.168.2.2: bytes=32 time=11ms TTL=127Ping statistics for 192.168.2.2:Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:Minimum = 11ms, Maximum = 17ms, Average = 14ms<以上代码可复制粘贴,可往左滑>

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689801597a287491.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信