利用三层交换机实现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)在二层交换机上配置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台;直连线

三层交换实现vlan互通 三层交换机vlan间互通原理_三层交换实现vlan互通

 

实验设备配置

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 划分到不同网关,此时两个网关分组无法相互连通

 


1. PC1 Ping PC3 reply
2. PC1 Ping PC2 timeout

 

 

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

    1. Switch>en
    2. Switch#conf t
    3. //创建2个新vlan分组,并将相应的端口绑定到vlan分组
    4. Switch(config )#vlan 2
    5. Switch(config-vlan)#exit
    6. Switch(config )#vlan 3
    7. Switch(config-vlan)#exit
    8. Switch(config )#interface fa 0/2
    9. Switch(config-if)#switchport access vlan 2
    10. Switch(config-if)#exit
    11. Switch(config )#inter fa 0/3
    12. Switch(config-if)#switchport access vlan 3
    13. Switch(config-if)#exit
    14. //修改交换机连接端口模式为 trunk
    15. Switch(config )#inter fa 0/1
    16. Switch(config-if)#switchport mode trunk
    17. Switch(config-if)#end
    18. Switch#show vlan //查看vlan端口情况

    S3560


    1. Switch>en
    2. Switch#conf t
    3. //新建vlan2 vlan3
    4. Switch(config )#vlan 2
    5. Switch(config-vlan)#exit
    6. Switch(config )#vlan 3
    7. Switch(config-vlan)#exit
    8.  
    9. //对各个端口进行配置
    10. //(1)配置交换机和三层交换机的连接端口
    11. Switch(config )#inter fa 0/1
    12. Switch(config-if)#switchport trunk encapsulation dot1q //给该接口的trunk封装为802.1Q的帧格式
    13. Switch(config-if)#switchport mode trunk //定义该接口的工作模式为trunk
    14. Switch(config-if)#exit
    15. //(2)配置终端连接端口
    16. //将终端端口绑定到vlan指定分组
    17. Switch(config )#inter fa 0/2
    18. Switch(config-if)#switchport access vlan 2
    19. Switch(config-if)#exit
    20. Switch(config )#inter fa 0/3
    21. Switch(config-if)#switchport access vlan 3
    22. Switch(config-if)#exit
    23. //对2个vlan虚拟接口进行路由转发配置
    24. Switch(config )#inter vlan 2 //进入vlan2 虚拟接口
    25. Switch(config-if)#ip address 192.168.1.1 255.255.255.0 //配置IP地址
    26. Switch(config-if)#no shutdown //开启该三层端口(路由功能)
    27. Switch(config-if)#exit
    28. Switch(config )#inter vlan 3
    29. Switch(config-if)#ip address 192.168.2.1 255.255.255.0
    30. Switch(config-if)#no shutdown
    31. Switch(config-if)#end
    32. Switch#show ip route //显示路由表
    33. Switch#show vlan //显示vlan信息

     

     

    实验验证


    1. PC1 Ping PC3 reply
    2. PC1 Ping PC2 reply