06_利用三层交换机实现VLAN间路由

技术原理

  1. 三层交换机是带有三层路由功能的交换机,也就是这台交换机的端口既有三层路由功能,也具有二层交换功能。三层交换机端口默认为二层口如果需要启用三层功能就需要在此端口输入no switchport命令
  2. 三层交换机具备网络层的功能,实现VLAN相互访问的原理

    利用三层交换机的路由功能,通过识别数据包的IP地址,查找路由表进行选路转发,三层交换机利用直连路由可以实现不同VLAN之间的相互访问;

    三层交换机给接口配置IP地址,采用SVI(交换虚拟接口)的方式实现VLAN间互连,SVI是指为交换机中的VLAN创建虚拟接口,并且配置IP地址。

实验说明

在同一个局域网中,在 05.交换机划分Vlan的基础上,PC0、PC2 和 PC1、PC3分别属于同一个Vlan分组(PC0、PC1和PC2、PC3分别归属同一个交换机),但同时还要实现两个分组之间可以相互访问;

使用三层交换机代替原来的一个交换机,在三层交换机上分别设置各VLAN的接口IP地址。三层交换机将vlan做为一种接口对待,就象路由器上的一样,再在各接入VLAN的计算机上设置与所属VLAN的网络地址一致的IP地址,并且把默认网关设置为该VLAN的接口地址。这样,所有的VLAN也可以互访了。

实验步骤

  1. 在二层交换机上配置VLAN2VLAN3,分别将端口2、端口3划分给VLAN2VLAN3
  2. 将二层交换机与三层交换机相连的端口fa 0/1都定义为tag Vlan模式。
  3. 在三层交换机上配置VLAN2VLAN3,此时验证二层交换机VLAN2VLAN3下的主机之间不能相互通信。
  4. 设置三层交换机VLAN间的通信,创建VLAN2,VLAN3的虚接口,并配置虚接口VLAN2VLAN3IP地址。
  5. 查看三层交换机路由表。
  6. 将二层交换机VLAN2VLAN3下的主机默认网关分别设置为相应虚拟接口的IP地址。
  7. 验证二层交换机VLAN2,VALN3下的主机之间可以相互通信。

实验设备

Switch_2960 1台;Swithc_3560 1台;PC 4台;直连线 5条; 配置线 2条

扫描二维码关注公众号,回复: 2637265 查看本文章


实验设备配置

PC0

        IP:                    192.168.1.2

        Submark:         255.255.255.0

        Gateway:         192.168.1.1

PC1

        IP:                    192.168.2.2

        Submark:         255.255.255.0

        Gateway:         192.168.2.1    

PC2

        IP:                    192.168.1.3

        Submark:         255.255.255.0

        Gateway:         192.168.1.1

PC3

        IP:                    192.168.2.3

        Submark:         255.255.255.0

        Gateway:         192.168..1

PC0、PC2   PC1、PC3  划分到不同网关,此时两个网关分组无法相互连通
PC1 Ping PC3   reply
PC1 Ping PC2   timeout

S2960交换机配置(同05.交换机VLAN配置

Switch>en
Switch#conf t
//创建2个新vlan分组,并将相应的端口绑定到vlan分组
Switch(config )#vlan 2  
Switch(config-vlan)#exit
Switch(config )#vlan 3
Switch(config-vlan)#exit
Switch(config )#interface fa 0/2
Switch(config-if)#switchport access vlan 2
Switch(config-if)#exit
Switch(config )#inter fa 0/3
Switch(config-if)#switchport access vlan 3
Switch(config-if)#exit       
//修改交换机连接端口模式为 trunk
Switch(config )#inter fa 0/1
Switch(config-if)#switchport  mode  trunk
Switch(config-if)#end
Switch#show vlan     //查看vlan端口情况

S3560

Switch>en
Switch#conf t
//新建vlan2 vlan3
Switch(config )#vlan 2  
Switch(config-vlan)#exit
Switch(config )#vlan 3  
Switch(config-vlan)#exit

//对各个端口进行配置
//(1)配置交换机和三层交换机的连接端口
Switch(config )#inter fa 0/1    
Switch(config-if)#switchport trunk encapsulation dot1q //给该接口的trunk封装为802.1Q的帧格式
Switch(config-if)#switchport mode trunk  //定义该接口的工作模式为trunk
Switch(config-if)#exit
//(2)配置终端连接端口
//将终端端口绑定到vlan指定分组
Switch(config )#inter fa 0/2    
Switch(config-if)#switchport access vlan 2  
Switch(config-if)#exit   
Switch(config )#inter fa 0/3  
Switch(config-if)#switchport access vlan 3
Switch(config-if)#exit  
 
//对2个vlan虚拟接口进行路由转发配置
Switch(config )#inter 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 )#inter 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    reply
PC1 Ping PC2    reply


原文链接:http://7c0bab95.wiz03.com/share/s/1Y2WKl218k5e2gpBCl2BeEsq0Yy3ew3HcQys2wxOLl08agY4

猜你喜欢

转载自blog.csdn.net/weixin_42061048/article/details/80725850
今日推荐