单臂路由和SVI接口

单臂路由存在的意义:
因为一个vlan便是一个广播域,不同vlan之间不可以相互通信。但是财务部会永远不跟技术部打交道吗,哪怕可是会不打交道,但是跟销售部呢,不会有数据交互?于是乎就存在vlan间通信的需求,可以靠路由器或者三层交换机来实现。

传统的vlan连接,比如交换机之间,配置了trunk模式可以跨交换机进行数据传输,但是有一个问题,端口数量问题。一个vlan一条线,那么几百个vlan呢,比如一个宿舍一个vlan,那么多vlan哪有那么多端口来进行连接。

于是便产生了单臂路由,简而言之就是一条线的路由。那一条线也就是占用一个端口,它靠虚拟子接口来实现原来的端口公用一条线,而不会产生问题,因为接口是不一样的(虽然是虚拟的)。

下面来做一个实验,来实现单臂路由:

网络拓扑图:
在这里插入图片描述
在不配置vlan的情况下,pc1能ping通pc2。

1.switch1上划分vlan(vlan2和vlan3),并且把pc1划入vlan2,pc2划入vlan3:

conf ter
vlan 2
name pc1
exit
vlan 3
name pc2
exit
interface e0/1
switchport access vlan 2
exit
interface e0/2
switchport access vlan 3
end

查看vlan信息:

show
*Nov  9 01:14:26.025: %SYS-5-CONFIG_I: Configured from console by console
switch1#show vlan

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Et0/0, Et0/3, Et1/0, Et1/1
                                                Et1/2, Et1/3, Et2/0, Et2/1
                                                Et2/2, Et2/3, Et3/0, Et3/1
                                                Et3/2, Et3/3
2    pc1                              active    Et0/1
3    pc2                              active    Et0/2

接下来,为了防止记录的mac地址依然生效,清空记录:

clear mac address-table dynamic
clear arp

pc1ping pc2能不能ping通?

pc1#ping 192.168.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
.....  #不同通信
Success rate is 0 percent (0/5)

2.接下来修改交换机和路由器之间的交换机的端口模式,设置成trunk模式,让vlan信息可以跨过交换机传输:

confi ter
interface e0/0
switchport trunk encapsulation dot1q
switchport mode trunk
no shutdown
end

查看e0/0端口信息:

switch1#show running-config interface e0/0
Building configuration...

Current configuration : 103 bytes
!
interface Ethernet0/0
 switchport trunk encapsulation dot1q
 switchport mode trunk
 duplex auto
end

3.为pc1和2配置网关,当它们找不到主机的时候,会把数据发送给默认网关:

pc1#configure terminal
pc1(config)#no ip routing
pc1(config)#ip default-gateway 192.168.1.2 
pc1(config)#end
注:这里我用的是用交换机模拟pc机,在真实环境里,win只要鼠标点点点就行,linux要配置network相关文件,而不是用这种方法。

查看主机route信息:
在这里插入图片描述
pc2配置过程一样,网关配置成192.168.2.2。

4.在route上配置子接口和端口模式,因为交换机上e0/0用的是dot1q封装的数据,所以route上于是要一致的:

interface e0/0
no shutdown  #开启端口
interface e0/0.2
encapsulation dot1Q 2
ip address 192.168.1.2 255.255.255.0
interface e0/0.3
encapsulation dot1Q 3
ip address 192.168.2.2 255.255.255.0
no shutdown
end

看看接口状态:

route1#show ip interface brief 
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                unassigned      YES NVRAM  up                    up      
Ethernet0/0.2              192.168.1.2     YES manual up                    up      
Ethernet0/0.3              192.168.2.2     YES manual up                    up      

查看路由表信息:

route1#show ip route

Gateway of last resort is not set

  192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, Ethernet0/0.2
L        192.168.1.2/32 is directly connected, Ethernet0/0.2
      192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.2.0/24 is directly connected, Ethernet0/0.3
L        192.168.2.2/32 is directly connected, Ethernet0/0.3

路由配置完成之后,看pc1能够ping通pc2:

pc1#ping 192.168.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 1/1/2 ms

答案是可以的,完成。

但是发现单点路由存在弊端,只有一条线路,万一出故障了,比如线损坏,或者链路出了问题,那么所有的vlan之间将无法进行通信,这对于全年基本不能出故障的银行或者业务量比较重要的公司都是不能接受的

还有可能要增加一台路由器,也是增加了成本。

SVI的实现

为此出现了一种新的功能,便是在三层交换上的SVI接口,这样便不需要单独添加一台路由器了。

SVI(switch virtual interface),它是三层交换机上的一个虚拟端口,类似于Router上的子端口,由软件实现。每个SVI只能关联一个VLAN,设置一个ip地址。

此功能是在三层交换机上配置,我们在原来的拓扑图上做一些改变:
把route除去,关闭route1e0/0端口。

在这里插入图片描述
在switch1上配置:

switch1#configure ter
switch1(config)#inter e0/0
switch1(config-if)#shutdown
switch1(config-if)#exit
switch1(config)#interface vlan 2
switch1(config-if)#ip address 192.168.1.2 255.255.255.0
switch1(config-if)#no shutdown 
switch1(config-if)#exit
switch1(config)#interface vlan 3
switch1(config-if)#ip address 192.168.2.2 255.255.255.0
switch1(config-if)#no shutdown
switch1(config)#no ip cef #此处使用 no ip cef 命令关闭转发机制便是该版本的镜像并没有很好的在 Linux 中实现其提供的功能,可能该镜像的设备本是使用硬件辅助实现该功能等等。若是不关闭 cef 的转发机制,将导致你明明配置无误,却无法正常的通信。
switch1(config)#end

最后查看路由信息:

switch1#show ip route
Gateway of last resort is not set

      192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, Vlan2
L        192.168.1.2/32 is directly connected, Vlan2
      192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.2.0/24 is directly connected, Vlan3
L        192.168.2.2/32 is directly connected, Vlan3

pc1能不能和pc2通信呢?

pc1#ping 192.168.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.1, timeout is 2 seconds:
..!!!
Success rate is 60 percent (3/5), round-trip min/avg/max = 6/7/10 ms

答案是可以的。
完成。

发布了108 篇原创文章 · 获赞 26 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_37369726/article/details/102983141