使用带有VLAN的托管交换机扩展路由器端口

如何使用带有VLAN的托管交换机扩展路由器端口?

解释

你有一台运行OpenWrt的强大机器。 强大的功能意味着:一种能够大幅度处理您的活动所创建的网络数据包的设备。就像你创建一个50 Mbit的流量,你的设备能够处理到800 Mbit。

问题是:不知何故,你有几个wan连接(可能使用mwan3),或者由于某种原因有几个内部连接,并且设备没有足够的以太网端口。

您可以使用托管交换机扩展设备的eternet端口(这意味着您有一些资金/资源,而且您在家庭办公室或小型办公室场景中)

使用VLAN配置管理型交换机

使基于OpenWrt的设备能够在端口方面进行扩展的技术是VLAN。

VLAN

(通常是关于VLAN如何 工作的合理解释包含在交换机的制造商手册中):

交换机中带有VID X 的未标记端口将VLAN标记X 分配给传入的数据包。 当数据包离开未标记的端口并被标记为VID X时,将删除VLAN标记。例如,这有助于在标记端口和未标记端口之间进行通信。没有VID的数据包进入未标记的端口,获取VID X并可以路由到属于同一VID的其他端口(除了桥接端口)。

一个标记端口,用VID Y,接受标记有VID的Y输入唯一的数据包,而让标记VIDŸ走出去端口的数据包。 请注意,一个端口只能取消标记一次,而可以使用多个VID标记。

您可以使用简短的架构:

交换机内部堆栈+外部网络                                                                                                        
                              |                                                                                                                          
                              |                                                                                                                          
                              | 交换机内部堆栈+外部网络              
                              | |                                
                              | 带有VID Y,X和Z |的标记端口                                
                              | |                                
 包含VID Y |的数据包 | 带VID W的未标记端口       
                              | |                                
             + --------------------------------------->之后得到VID W | 没有VID的数据包   
                              | <-------------------------------------- +          
 包含VID X的数据包 |                                
                              | |                                
             + --------------------------------------->包含VID W |的数据包                                
                              | | 之后没有VID       
 包含VID Z | + -------------------------------------------->           
                              | |                                
             + ---------------------------------------> |                                
                              | 保持VID | 带有VID W的数据包
                              | 包含VID Y <--------------------------------------------- -  +        
             <-------------------------------------- + +                                
                              |                                                                                                                          
                              | 包含VID X的数据包                                                                                              
             <-------------------------------------- +                                                                                                    
                              |                                                                                                                          
                              | 带有VID Z的数据包                                                                                              
             <-------------------------------------- +                                                                                                    
                              |                                                                                                                          
                              |                                                                                                                          
 包含VID W |                                                                                                                          
                           XX |                                                                                                                          
      + -------------------- XX |                                                                                                                          
                           XX |                                                                                                                          
                              |                                                                                                                          
                              | 带有VID W的XX包                                                                                          
                              | XX ------------------- +                                                                                                  
                              + XX                                                                                                                      

配置

所以,想象一下有16端口交换机,我们想用8个端口扩展我们的路由器。我们选择前8名。

因此,交换机的端口9-16将保留VID 1,并且未标记,VID 1也用于管理。

然后我们创建VID 100以将其分配给中继或混合端口(中继是分配给所有VLAN ID的端口,混合端口是分配给某些VID的端口)

Then we assign the port 1 to the VID 101 untagged.
The port 2 to the VID 102 untagged.
The port 3 to the VID 103 untagged.
The port 4 to the VID 104 untagged.
The port 5 to the VID 105 untagged.
The port 6 to the VID 106 untagged.
The port 7 to the VID 107 untagged.
The port 8 to the VID 100 untagged and VID 101 to 107 tagged.

这是因为我们希望从端口1到端口107的数据包可以通过端口8,来自端口8 的标记数据包可以通过端口1到7,没有标记(因为其他设备无法识别)如果标记,则标记或拒绝数据包)。

配置OpenWrt路由器

现在我们想要利用它。例如,假设我们连接到交换机的端口1,用于wan连接’wan’的调制解调器,在端口2上连接用于wan连接的调制解调器’wan2’。

带可编程开关

在TP-Link TL-WDR3600上我们有这样的东西:

#/etc/config/network

...lines...

config switch
        option name  'eth0'
        option reset '1'
        option enable_vlan '1'

## Port: internet
config disabled_switch_vlan
        option device 'eth0'
        option vlan   '1'
        option ports  '0t 1'
        list comment  'port internet, eth0.1'
        list comment  'we cannot have an untagged port'

config switch_vlan
        option device 'eth0'
        option vlan   '101'
        option ports  '0t 1t'
        list comment  'port internet, eth0.101'

config switch_vlan
        option device 'eth0'
        option vlan   '102'
        option ports  '0t 1t'
        list comment  'port internet, eth0.102'
        
...lines...

config interface 'wan'
        option ifname           eth0.101
        option proto            'dhcp'
        option disabled_type    'bridge'
        list comment            'mwan3 does not like bridges, as far as the documentation goes'
        option peerdns          0
        option metric           10
        
config interface 'wan2'
        option ifname           eth0.102
        option proto            'dhcp'
        option disabled_type    'bridge'
        list comment            'mwan3 does not like bridges, as far as the documentation goes'
        option peerdns          0
        option metric           20

...lines...

没有可编程开关

在routerOS metarouter或x86设备上有类似的东西。

#/etc/config/network
       
...lines...

config interface 'wan'
        option ifname           eth0.101
        option proto            'dhcp'
        option disabled_type    'bridge'
        list comment            'mwan3 does not like bridges, as far as the documentation goes'
        option peerdns          0
        option metric           10
        
config interface 'wan2'
        option ifname           eth0.102
        option proto            'dhcp'
        option disabled_type    'bridge'
        list comment            'mwan3 does not like bridges, as far as the documentation goes'
        option peerdns          0
        option metric           20

...lines...

结论

通过这种方式,您的扩展路由器具有更多端口,克服了硬件表的限制,实际上不提供任何具有超过5个千兆位端口的设备易于安装(mikrotik的安装有点复杂)。

需要注意的限制是:通过端口需要多少流量,通常SOHO甚至可以组合多个不超过200-300 Mbit的wans,以及设备本身的处理能力(已经处于压力之下) vlan标签)与OpenWrt(有时不能使用硬件加速),

但这可以使用非常强大的设备,例如只有2个端口。

生产性工作的实际应用

使用像hp 1810-24 j9803A这样的24端口交换机,我们可以使用12个这样的端口(请注意,我们根据设备的编号分配逻辑网络号码,以便于维护。这是我们’参数’中的一个小因素标准’):

你可以看到名为’nibble’的矩形分组。不使用’trunk’端口优于’hybrid’的一个优点是我们可以将分组整齐地分开,并且我们也没有冒险将端口数据发送到不需要的端口的风险。
在这里插入图片描述

配置示例

使用部分托管交换机配置的配置示例

config interface loopback
        option ifname   lo
        option proto    static
        option ipaddr   127.0.0.1
        option netmask  255.0.0.0

#eth0 lan1
#eth1 lan2
#eth2 lan3

config interface rescue
        option ifname   eth0
        option type     bridge
        option proto    static
        option ipaddr   192.168.1.1
        option netmask  255.255.255.0
        list comment 'for rescuing and management operations'

config interface wan
        option ifname   eth1.101
        option no_type_with_mwan3       1
        option 'proto'          'static'
        option 'ipaddr'         '1.2.3.4'
        option 'netmask'        '255.255.255.248'
        option 'gateway'        '1.2.3.3'
        option metric           10

config interface wan2
        option ifname   eth1.102
        option no_type_with_mwan3       1
        option 'proto'          'static'
        option 'ipaddr'         '1.2.3.5'
        option 'netmask'        '255.255.255.248'
        option 'gateway'        '1.2.3.6'
        option metric           20

config interface wan3
        option ifname   eth1.103
        option proto    dhcp
        option metric   30

config interface lan
        option ifname   eth2.201
        option proto    static
        option ipaddr   172.18.21.9
        option netmask  255.255.255.0

config interface lan_gw
        option ifname   eth2.201
        option proto    static
        option ipaddr   172.18.21.1
        option netmask  255.255.255.0

config interface lan_gw2
        option ifname   eth2.201
        option proto    static
        option ipaddr   172.18.21.253
        option netmask  255.255.255.0

config interface lan_old
        option ifname   eth2.201
        option proto    static
        option ipaddr   10.200.1.9
        option netmask  255.255.255.0

config interface lan_old_g
        option ifname   eth2.201
        option proto    static
        option ipaddr   10.200.1.253
        option netmask  255.255.255.0

config interface voip
        option ifname   eth2.202
        option proto    static
        option ipaddr   172.18.22.9
        option netmask  255.255.255.0

config interface voip_gw
        option ifname   eth2.202
        option proto    static
        option ipaddr   172.18.22.1
        option netmask  255.255.255.0

config interface wlan
        option ifname   eth2.203
        option type     bridge
        option proto    static
        option ipaddr   172.18.24.9
        option netmask  255.255.255.0

config interface wlan_gw
        option ifname   eth2.203
        option proto    static
        option ipaddr   172.18.24.253
        option netmask  255.255.255.0

config interface vpn0
        option ifname   tun0
        option proto    none

config interface vpn1
        option ifname   tun1
        option proto    none

config interface vpn2
        option ifname   tun2
        option proto    none

config interface vpn3
        option ifname   tun3
        option proto    none

config interface vpn4
        option ifname   tun4
        option proto    none

config interface vpn5
        option ifname   tun5
        option proto    none

config route
        list comment 'routing all possible private addresses to vpn server'
        list comment 'with different metric'
        option interface        lan
        option target           10.0.0.0
        option netmask          255.0.0.0
        option gateway          172.18.21.4
        option metric           100

config route
        list comment 'routing all possible private addresses to vpn server'
        list comment 'with different metric'
        option interface        lan
        option target           172.16.0.0
        option netmask          255.240.0.0
        option gateway          172.18.21.4
        option metric           100

config route
        list comment 'routing all possible private addresses to vpn server'
        list comment 'with different metric'
        option interface        lan
        option target           192.168.0.0
        option netmask          255.255.0.0
        option gateway          172.18.21.4
        option metric           100
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值