三层交换机的方式实现VLAN间通信及外部网络访问

您所在的位置:网站首页 三层交换机无法使用web访问端口 三层交换机的方式实现VLAN间通信及外部网络访问

三层交换机的方式实现VLAN间通信及外部网络访问

2024-07-04 03:44:53| 来源: 网络整理| 查看: 265

再此之前介绍三层交换机:

三层交换机就是具有部分路由器功能的交换机,工作在OSI网络标准模型的第三层:网络层。

三层交换机的最重要目的是加快大型局域网内部的数据交换,所具有的路由功能也是为这目的服务的,能够做到一次路由,多次转发。

三层交换机的对应VLAN的IP相当于其下所连主机的网关,分别设置完IP后可以在路由表中查到这个IP,并且前面的字母为C 表示直连网络。所以能够通信。

如下为例:(192.168.11.0 和 192.168.22.0那个)

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP i - 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 - ODR P - periodic downloaded static route Gateway of last resort is not set 10.0.0.0/24 is subnetted, 1 subnets C 10.1.1.0 is directly connected, FastEthernet0/1 R 172.16.0.0/16 [120/1] via 10.1.1.2, 00:00:05, FastEthernet0/1 C 192.168.11.0/24 is directly connected, Vlan11 C 192.168.22.0/24 is directly connected, Vlan22

思路整理: 1、配置vlan,并分配端口。 2、注意通过vlan信息的地方要TRUNK模式。 3、三层交换机vlan设置IP 4、关闭三层交换机端口的交换功能,换为路由功能。

下面进入正文

一、网络拓扑图:

在这里插入图片描述

如上图所示,其中主机的IP和子网掩码都在图中标记出来,网关设为当前网段最后一位(虽然此时还没有网关)。

交叉线和直通线。

11网络的主机连接的是11的端口

22网络的主机连接的是22的端口

三层交换机的端口连接在g0/2 和 fa0/1,这个可以在后边的指令中具体看到。

二、Sw_A交换机的配置

既然是VLAN的通信,首先要有VLAN。现在交换机Sw_A中配置相关信息。

一些指令的作用写在指令后边。

Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#hostname Sw_A //改名 Sw_A(config)#vlan 11 //创建VLAN号11的VLAN Sw_A(config-vlan)#name Dev //VLAN名字设为Dev Sw_A(config-vlan)#vlan 22 Sw_A(config-vlan)#name Ops Sw_A(config-vlan)#exit Sw_A(config)#int fa0/11 //进入fa0/11端口,int的全称是interface Sw_A(config-if)#switchport mode access //修改模式为ACCESS Sw_A(config-if)#switchport access vlan 11 //将fa0/11这个端口分给VLAN 11 Sw_A(config-if)#int fa0/22 //进入fa0/22端口 Sw_A(config-if)#switchport mode access Sw_A(config-if)#switchport access vlan 22 Sw_A(config-if)#exit Sw_A(config)#exit Sw_A#show vlan brief //查询端口信息 VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- 1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4 Fa0/5, Fa0/6, Fa0/7, Fa0/8 Fa0/9, Fa0/10, Fa0/12, Fa0/13 Fa0/14, Fa0/15, Fa0/16, Fa0/17 Fa0/18, Fa0/19, Fa0/20, Fa0/21 Fa0/23, Fa0/24, Gig1/1, Gig1/2 11 Dev active Fa0/11 22 Ops active Fa0/22 1002 fddi-default active 1003 token-ring-default active 1004 fddinet-default active 1005 trnet-default active

发现其中 VLAN11 Dev 和VLAN 22 Ops 已经设置完成 并且端口也已经分配。

三、Sw_B交换机的设置

Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#hostname Sw_B //改名 Sw_B(config)#vlan 11 //VLAN号 Sw_B(config-vlan)#name Dev //VLAN名 Sw_B(config-vlan)#vlan 22 Sw_B(config-vlan)#name Ops Sw_B(config-vlan)#int fa0/11 Sw_B(config-if)#switchport mode access Sw_B(config-if)#switchport access vlan 11 Sw_B(config-if)#int fa0/22 Sw_B(config-if)#switchport mode access Sw_B(config-if)#switchport access vlan 22 Sw_B(config-if)#exit Sw_B(config)#exit Sw_B# %SYS-5-CONFIG_I: Configured from console by console Sw_B#show vlan brief VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- 1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4 Fa0/5, Fa0/6, Fa0/7, Fa0/8 Fa0/9, Fa0/10, Fa0/12, Fa0/13 Fa0/14, Fa0/15, Fa0/16, Fa0/17 Fa0/18, Fa0/19, Fa0/20, Fa0/21 Fa0/23, Fa0/24, Gig1/1, Gig1/2 11 Dev active Fa0/11 22 Ops active Fa0/22 1002 fddi-default active 1003 token-ring-default active 1004 fddinet-default active 1005 trnet-default active

Sw_B的设置和A一样。

这时可以测试ping一下。

在这里插入图片描述

并不能ping通,同VLAN也不通。这是因为g1/1端口没有设置模式。

其实这个只要设置一端就可以了。我选择的是Sw_A交换机。

Sw_A(config)#int g1/1 Sw_A(config-if)#switchport mode trunk //g1/1设置为TRUNK模式可以传递VLAN信息 %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/1, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/1, changed state to up

再次进行ping测试,发现通VLAN的可以ping通。

在这里插入图片描述

上边的是第一次不通的 下边的是设置过g1/1后第二次通的。

四、三层交换机的设置

若想2个VLAN之间通信就要利用三层交换机的功能,在最开始已经说明了。

Switch> Switch>en Switch# conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#vlan 11 Switch(config-vlan)#name Dev Switch(config-vlan)#vlan 22 Switch(config-vlan)#name Ops Switch(config)#hostname MSw_A MSw_A(config)#interface vlan 11 //进入VLAN 11 MSw_A(config-if)#ip address 192.168.11.254 255.255.255.0 //给VLAN 11设置IP地址,三级交换机有路由功能,这个也相当于下属主机的网关。 MSw_A(config-if)#no shutdown //启动端口 %LINK-5-CHANGED: Interface Vlan11, changed state to up MSw_A(config-if)#interface vlan 22 %LINK-5-CHANGED: Interface Vlan22, changed state to up MSw_A(config-if)#ip address 192.168.22.254 255.255.255.0 //给VLAN 22 设置IP 同理也是它下属网络的 网关。 MSw_A(config-if)#no shutdown

现在可以show 一下路由表 ,发现什么也没有。因为连接交换机Sw_A的线g0/1并没有设置为TRUNK。不能通过VLAN信息。

回到交换机Sw_A

Sw_A>en Sw_A# conf t Enter configuration commands, one per line. End with CNTL/Z. Sw_A(config-if)#int g1/2 //这条线连接二级交换机的g1/2 和 三级交换机的 g0/1 端口,在Sw_A交换机上的是g1/2所以进入这个端口 Sw_A(config-if)#switchport mode trunk %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/2, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/2, changed state to up

现在回到三级交换机MSw_A。

MSw_A#show vlan brief //查看VLAN信息。发现有 VLAN 11 和 VLAN 22 VLAN Name Status Ports ---- -------------------------------- --------- ------------------------------- 1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4 Fa0/5, Fa0/6, Fa0/7, Fa0/8 Fa0/9, Fa0/10, Fa0/11, Fa0/12 Fa0/13, Fa0/14, Fa0/15, Fa0/16 Fa0/17, Fa0/18, Fa0/19, Fa0/20 Fa0/21, Fa0/22, Fa0/23, Fa0/24 Gig0/1 11 Dev active 22 Ops active 1002 fddi-default active 1003 token-ring-default active 1004 fddinet-default active 1005 trnet-default active MSw_A#show ip route //查看路由表,发现有2个直连网络 Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP i - 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 - ODR P - periodic downloaded static route Gateway of last resort is not set C 192.168.11.0/24 is directly connected, Vlan11 C 192.168.22.0/24 is directly connected, Vlan22

测试 从 192.168.11.1这个主机ping另一个VLAN 另一个网段的 192.168.22.1 发现能够ping 通。

在这里插入图片描述

到此时,VLAN间的通信已经完成,但是有可能让这些VLAN访问外边的网络,就要借助路由器的帮助。

五、路由器的设置

Router>en Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#int fa0/1 Router(config-if)#ip address 10.1.1.2 255.255.255.0 //设置端口的IP子网掩码。 Router(config-if)#no shutdown //启动端口 %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up Router(config-if)#int f0/0 Router(config-if)#int fa0/0 Router(config-if)#ip address 192.168.33.254 255.255.255.0 //设置端口的IP和子网掩码,这个也是右侧它下属主机的网关。 Router(config-if)#no shutdown //启动 %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up Router(config-if)#exit Router(config)#route rip //配置动态路由协议 Router(config-router)#network 10.1.1.0 //标记直连网络 Router(config-router)#network 192.168.33.0 //标记直连网络 Router(config-router)#exit Router(config)#exit Router# %SYS-5-CONFIG_I: Configured from console by console Router#show ip route //查看路由表 有2个直连网络 Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP i - 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 - ODR P - periodic downloaded static route Gateway of last resort is not set 10.0.0.0/24 is subnetted, 1 subnets C 10.1.1.0 is directly connected, FastEthernet0/1 C 192.168.33.0/24 is directly connected, FastEthernet0/0

六、再次回到三层交换机配置

三层交换机叫三层交换机的原因就是它能实现部分路由器的功能。

MSw_A>en MSw_A# conf t Enter configuration commands, one per line. End with CNTL/Z. MSw_A(config)#interface fa0/1 //进入连接的fa0/1端口 MSw_A(config-if)#no switchport //关闭交换功能,开启路由功能 %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 up MSw_A(config-if)#ip address 10.1.1.1 255.255.255.0 //设置IP和子网掩码 MSw_A(config-if)#no shutdown //启动端口 MSw_A(config-if)#exit MSw_A(config)#route rip //动态路由协议 MSw_A(config-router)#network 10.1.1.0 //标记直连网络 MSw_A(config-router)#network 192.168.22.0 MSw_A(config-router)#network 192.168.11.0 MSw_A(config-router)#exit MSw_A(config)#exit MSw_A# %SYS-5-CONFIG_I: Configured from console by console MSw_A#show ip route //查下路由表发现已经有了4个网络 Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP i - 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 - ODR P - periodic downloaded static route Gateway of last resort is not set 10.0.0.0/24 is subnetted, 1 subnets C 10.1.1.0 is directly connected, FastEthernet0/1 C 192.168.11.0/24 is directly connected, Vlan11 C 192.168.22.0/24 is directly connected, Vlan22 R 192.168.33.0/24 [120/1] via 10.1.1.2, 00:00:23, FastEthernet0/1

测试在PC0 ping一下 最右边的网络 192.168.33.1

发现能够ping通,成功。

在这里插入图片描述

注意:不能连通的原因 1、各个端口是否连接正确,状态是否正确,IP等是否设置正确。 2、网关ip有无设置正确。 3、路由表中有无相应网络。



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭