[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
原理
在交换网络中,通过VLAN对一个物理网络进行了逻辑划分,不同的VLAN之间是无法直接访问的,必须通过三层的路由设备进行连接。一般利用路由器或三层交换机来实现不同VLAN之间的互相访问。三层交换机和路由器具备网络层的功能,能够根据数据的IP报头信息,进行选路和转发,从而实现不同网段之间的访问。
直连路由是指:为三层设备的接口配置IP地址,并且激活该端口,三层设备会自动产生该接口IP所在网段的直连路由信息。
三层交换机实现VLAN互访的原理是,利用三层交换机的路由功能,通过识别数据包的IP地址,查找路由表进行选路转发。三层交换机利用直连路由可以实现不同VLAN之间的互相访问。三层交换机给接口配置IP地址,采用SVI(交换虚拟接口)的方式实现VLAN间互连。SVI是指为交换机中的VLAN创建虚拟接口,并且配置IP地址。
配置命令
三层交换机在配置trunk端口时,必须先采用Dot1q封装:switchport trunk encapsulation dot1q
(思科专用,二层交换机不用封装)
创建虚接口:interface vlan +数字,然后配置ip,ip address ip地址+子网掩码,然后开启端口,no shutdown
注意:配置完ip地址必须要no shutdown!!!
实验验证
(1)网络拓扑图
(2)配置三层交换机
开启三层交换机的路由功能,创建vlan10、vlan20,将端口0/2划分到vlan10中,0/3划分到vlan20中
端口0/1:先封装Dot1q,再配置trunk
创建vlan10虚接口,配置ip地址192.168.10.254/24,开启端口
创建vlan20虚接口,配置ip地址192.168.20.254/24,开启端口
查看三层交换机的路由表,C是直连路由
(3)配置二层交换机
创建vlan10,将端口0/2划分到vlan10中,端口0/1配置trunk
(4)配置三台电脑的ip地址和网关
PC2和PC0在同一vlan中,网关相同
(5)PC2能ping通同一vlan的PC0,也能ping通不通vlan的PC1