作者:水叔
1.序

先说一下家里的网络接入吧,妖都电信作为全国最贵(可能没有之一)的宽带运营商,如果说只是一个月169的宽带融合套餐那我可能也就认了,但是家里所在的这栋楼查询电信以后居然说要按照商业楼算,最少只能办399一个月的宽带,那我就谢谢你吧,你电信大爷我伺候不起行吧。
另外两家,联通说没有资源,那基本也没什么选择了,就办移动好了。移动宽带 300/60Mbps( FTTH 方式接入,曾经也升级到千兆过,但是多次评估后发现 300M 宽带下行基本都可以跑到 400M-450M,已经完全够用),后来又在海鲜市场看到有出租本地运营商电视套餐里带的和联通合作的 100/30Mbps( 同轴Cable 方式接入,可以提供几乎是固定的外网 IP )。两条宽带加起来每月的支出也不到80RMB(还包括一个移动手机号)。
这样一来,两条宽带要如何整合到家庭网络里就成了一个问题,在经历了 Unifi Security Gateway( GUI 配置自由度太低,configfile 配置和持久化麻烦)和 RouterOS(不契合自己的思维方式) 的毒打后,终于还是发现了 EdgeOS 系列相对比较适合我的使用方式。这里就记录一下。
移动宽带是光纤入户,在换了猫棒之后感觉也是比较不错,直接插在 EdgeRouter-8-Pro 的 sfp 口设置 Vlan 41 (移动的设置是41)以后就可以直接 PPPoE 拨号上网了,珠江宽频(以下简称联通)的这条线路因为是走老旧的广电网络,入户时候只能提供同轴线需要用同轴猫转换成 RJ45 口接入,不过好在家门口楼道里有个小的壁龛,可以把同轴猫放在那里,再穿一根网线入户接去机房的交换机上 Vlan 119 Tagged (至于为什么是接到交换机,后面说吧)。
2.开始部署
先理一下各个网段
Vlan41 移动PPPoE拨号上网
Vlan119 联通DHCP获取公网IP
Vlan88 家庭主网络
说一下大概的思路:移动宽带没有公网 IPv4,但有完善的 IPv6 /60 地址段 ,随着v6网络的普及,还是作为主要的网络使用;联通宽带有几乎固定(不重启同轴猫的话不会变,就算变也只在一个 IPv4 /29 地址段中变化)的 IPv4 公网地址,但因为是同轴传输,会容易有不明原因的ping值飙升等抽风症状,主要用作 IPv6 故障或无 IPv6 环境时 fallback 的回家链路和移动网络抽风时的 failover fallback。
下面开始从零开始设置流水账:
2.1网络接入
因为大多数人不可能从一开始就接入了两条宽带但完全上不了网,那我开始时的默认情况是:猫棒已经配置好LOID及password认证,处于设置好vlan和pppoe就可以直接拨号上网的状态。如果要找怎么配置LOID和password认证,那其他大佬的教程也太多了。

接线图如上
路由器到交换机之间使用两根1G链路通过LACP做Bond相连,又由于使用了vlan,首先要在EdgeRouter上给eth1和eth2创建新的Bond
configure
set interfaces bonding bond0 mode 802.3ad
set interfaces ethernet eth1 bond-group bond0
set interfaces ethernet eth2 bond-group bond0
然后在bond0下配置家庭主网络和联通网络的vlan并添加地址
set interfaces bonding bond0 vif 88 address 192.168.88.1/24
set interfaces bonding bond0 vif 119 address dhcp
添加移动的pppoe拨号(猫棒接在eth6)并保存以上的设置
set interfaces ethernet eth6 vif 41 pppoe 0 user-id 1xxxxxxxxxx@139.gd
set interfaces ethernet eth6 vif 41 pppoe 0 password xxxxxx
commit
save
exit
然后启动pppoe0
connect intreface pppoe0
移动光纤从门口接到了Patch Panel的16口出来后接入了路由器的eth6的sfp口上的猫棒。
联通的同轴线在门口的壁龛通过同轴猫转成rj45口网线后接入一个PoE供电的EdgerouterX(因为只预留了一根网线去门口然而现在发现设备越来越多,没有多余的供电于是只好拿一个ERX在外面做一个PoE交换机。为什么要用ERX?因为ERX有PoE Passthru,eth0供电之后还能用eth4再带一个PoE设备。。比如一个AP。。这都是后话了以后有机会再说)后被打上vlan119的tag,连接到Patch Panel11口然后接入交换机,一路走TRUNK回到路由器后接到bond0.119,然后通过DHCP在路由器上获取到了公网地址。
(如果你能看懂我这一段在说什么的话那应该能领略到,vlan这么用真是。。妙啊。。。
不出意外的话现在在路由器的Dashboard就能看到pppoe0已经连接并且获取到内网地址,bond0.119也已经获取到公网地址了。
2.2 负载均衡设置
下面开始双线负载均衡的核心部分
因为两条线路的带宽比例大概是4:1,在loadbalance下建立一个名叫G的lb组,然后分配各条线路的比重。
configure
set load-balance group G interface pppoe0 weight 40
set load-balance group G interface bond0.119 weight 10
因为在我这里主要是运用移动线路,联通线路就设置成failover only
set load-balance group G interface bond0.119 failover-only
接下来是一系列的firewall设置,对哪些流量怎么走做一个规定
2.3 路由表
首先做两张路由表,分别为
12:CM-fallback 优先走移动线路,不通时fallback到联通(1x.x.x.x 为dhcp获取到的联通外网网关地址,下同)
set protocols static table 12 description CM-fallback
set protocols static table 12 interface-route 0.0.0.0/0 next-hop-interface pppoe0 distance 10
set protocols static table 12 route 0.0.0.0/0 next-hop 1x.x.x.x distance 100
13:CU-fallback 优先走联通线路,不通时fallback到移动
set protocols static table 13 description CU-fallback
set protocols static table 13 interface-route 0.0.0.0/0 next-hop-interface pppoe0 distance 100
set protocols static table 13 route 0.0.0.0/0 next-hop 1x.x.x.x distance 10
2.4分流配置
添加防火墙规则,
定义一个modify组叫做balance
让被加入NULL 地址组的IP断网
set firewall group address-group NULL
set firewall modify balance rule 1 description NULL
set firewall modify balance rule 1 action drop
set firewall modify balance rule 1 source group address-group NULL
不对内网间的流量分流
set firewall modify balance rule 10 description do NOT load balance lan to lan
set firewall modify balance rule 10 action modify
set firewall modify balance rule 10 destination group network-group PRIVATE_NETS
set firewall modify balance rule 10 modify table main
对特定的源IP优先走联通网络
set firewall group address-group CU-SRC-IP
set firewall modify balance rule 30 description SRC-IP-via-CU-fallback
set firewall modify balance rule 30 action modify
set firewall modify balance rule 30 source group address-group CU-SRC-IP
set firewall modify balance rule 30 modify table 13
对特定的源IP优先走移动网络
set firewall group address-group CM-SRC-IP
set firewall modify balance rule 25 description SRC-IP-via-CM-fallback
set firewall modify balance rule 25 action modify
set firewall modify balance rule 25 source group address-group CM-SRC-IP
set firewall modify balance rule 25 modify table 12
不分流目的地址为联通外网IP的流量
set firewall modify balance rule 70 description do NOT load balancec CU destination public address
set firewall modify balance rule 70 action modify
set firewall modify balance rule 70 destination group address-group ADDRv4_bond0.119
set firewall modify balance rule 70 modify table main
不分流目的地址为移动pppoeIP的流量
set firewall modify balance rule 80 description do NOT load balance CM destination public address
set firewall modify balance rule 80 action modify
set firewall modify balance rule 80 destination group address-group ADDRv4_pppoe0
set firewall modify balance rule 80 modify table main
分流其他所有
set firewall modify balance rule 110 description Load-Balance else
set firewall modify balance rule 110 action modify
set firewall modify balance rule 110 modify lb-group G
当然因为我已经做了failover-only的设置,以上分流实际起作用的主要是分流到联通线路有关的设置,但是谁知道呢,万一有天心血来潮取消了failover-only就会有用了。当然上面这些规则只是一些比较必要的,还有其他需求根据自己情况继续加就好了。
还有一步最重要的,就是把balance组套用到需要分流的内网上,如果不做的话以上这些都不会生效
set interface bonding bond0 vif 88 firewall In modify balance
commit
save
exit
这样,再把192.168.88.12加到CM-SRC-IP组,把192.168.88.13加到CU-SRC-IP组,就可以得到一开始的那张图片的效果了。
3.结尾的废话

通过smokeping设置不同的probe也就可以实现在一个slave上进行两条线路的监控了~
大家学废了吗
我反正是写累了
下次见
有缘的话


财经自媒体联盟

4000520066 欢迎批评指正
All Rights Reserved 新浪公司 版权所有