openwrt Multi-WAN+macvlan单WAN多帐户 多拔叠加网络
opkg install ftp://ftp.netlab7.com/multiwan_1.0.18.ipk ftp://ftp.netlab7.com/luci-app-multiwan_1.0.16.ipk
装完重启就会出现Network->Multi-WAN这个菜单
Load Balancer Distribution:负载比例分配,比重越大走的流量越多。
Health Monitor Frequency:健康检测频率,单位秒。就是每隔多少秒检测该WAN是否在线咯。
Health Monitor ICMP Host(s):用来健康检测PING的对象。我这里写的是baidu和163的IP。
Health Monitor ICMP Timeout:很好理解了,健康检测PING超时时间。
Attempts Before WAN Failover:该WAN发生故障了,不在线了?重复检测的次数,以确定真的掉线。
Attempts Before WAN Recovery:恢复该WAN流量前,检测该WAN是否真的在线的次数。晕,有点别扭,自己理解吧。
Failover Traffic Destination:该WAN发生故障后,转移到哪个网口。
openwrt Multi-WAN+macvlan单WAN多帐户 多拔叠加网络
安装所需的软件 macvlan、luci-app-multiwan
opkg update
opkg install ip
opkg install komd-macvlan
opkg install ftp://ftp.netlab7.com/multiwan_1.0.18.ipk ftp://ftp.netlab7.com/luci-app-multiwan_1.0.16.ipk
编辑/etc/rc.local 增加虚拟网卡、MAC地址
root@OpenWrt:~# vi /etc/rc.local
增加
ip link add link eth1.1 eth2 type macvlan 增加wan2 虚拟网卡 eth1.1 对应前面记下的
ifconfig eth2 hw ether 00:11:22:33:44:5E
ifconfig eth2 up
ip link add link eth1.1 eth3 type macvlan 增加wan3虚拟网卡 eth1.1 对应前面记下的
ifconfig eth3 hw ether 00:11:22:33:44:6E
ifconfig eth3 up
如果需要更多 自行添加 少的话可以少加点,把MAC改成所需的地址
修改后保存 退出
按esc 退出 。shift+:看见左下角显示 :输入wq 保存退出
///修改配置文件
vi /etc/config/multiwan
config 'multiwan' 'config'
option 'default_route' 'balancer'
config 'interface' 'wan'
option 'health_interval' '10'
option 'icmp_hosts' 'dns'
option 'timeout' '3'
option 'health_fail_retries' '3'
option 'health_recovery_retries' '5'
option 'dns' 'auto'
option 'failover_to' 'balancer'
option 'weight' '5'
config 'interface' 'wan1'
option 'health_interval' '10'
option 'icmp_hosts' 'dns'
option 'timeout' '3'
option 'health_fail_retries' '3'
option 'health_recovery_retries' '5'
option 'failover_to' 'balancer'
option 'dns' 'auto'
option 'weight' '5'
config 'mwanfw'
option 'ports' '443'
option 'wanrule' 'wan'
config 'mwanfw'
option 'wanrule' 'fastbalancer'
///修改配置文件 我的是RG100A-AA 设置的Vlan
vi /etc/config/network
config 'switch' 'eth1'
option 'reset' '1'
option 'enable_vlan' '1'
config 'switch_vlan'
option 'device' 'eth1'
option 'vlan' '0'
option 'ports' '0 1 2 5*'
config 'switch_vlan'
option 'device' 'eth1'
option 'vlan' '1'
option 'ports' '3 5*'
config 'interface' 'loopback'
option 'ifname' 'lo'
option 'proto' 'static'
option 'ipaddr' '127.0.0.1'
option 'netmask' '255.0.0.0'
config 'interface' 'lan'
option 'type' 'bridge'
option 'ifname' 'eth1.0'
option 'proto' 'static'
option 'ipaddr' '192.168.1.1'
option 'netmask' '255.255.255.0'
option 'nat' '1'
config 'interface' 'wan'
option 'ifname' 'eth1.1'
option 'proto' 'pppoe'
option 'username' '^^07345807342'
option 'peerdns' '1'
option 'defaultroute' '1'
option 'password' 'E79ED0AB9EA7B4'
option 'macaddr' '00:74:04:02:B5:E9'
config 'interface' 'wan1'
option 'proto' 'pppoe'
option 'peerdns' '1'
option 'defaultroute' '1'
option 'ifname' 'eth2'
option 'macaddr' '00:1B:FC:BA:E2:C4'
option 'username' '^^HYAD104072787@5200.com'
option 'password' 'EB96D1A895A1'
///防火墙设置
/etc/config/firewall
config 'defaults'
option 'syn_flood' '1'
option 'input' 'ACCEPT'
option 'output' 'ACCEPT'
option 'forward' 'ACCEPT'
config 'zone'
option 'name' 'lan'
option 'input' 'ACCEPT'
option 'output' 'ACCEPT'
option 'forward' 'REJECT'
config 'zone'
option 'name' 'wan'
option 'input' 'ACCEPT'
option 'output' 'ACCEPT'
option 'forward' 'REJECT'
option 'masq' '1'
option 'mtu_fix' '1'
config 'forwarding'
option 'src' 'lan'
option 'dest' 'wan'
config 'rule'
option 'src' 'wan'
option 'proto' 'udp'
option 'dest_port' '68'
option 'target' 'ACCEPT'
config 'rule'
option 'src' 'wan'
option 'proto' 'tcp'
option 'dest_port' '2601'
option 'target' 'ACCEPT'
config 'include'
option 'path' '/etc/firewall.user'
config 'zone'
option 'name' 'wan1'
option 'network' 'wan1'
option 'input' 'ACCEPT'
option 'output' 'ACCEPT'
option 'forward' 'REJECT'
option 'masq' '1'
option 'mtu_fix' '1'
config 'forwarding'
option 'src' 'lan'
option 'dest' 'wan1'
config 'redirect'
option 'src' 'wan'
option '_name' 'webadmin'
option 'proto' 'tcpudp'
option 'src_dport' '81'
option 'dest_ip' '192.168.1.1'
option 'dest_port' '80'
config 'rule'
option 'target' 'ACCEPT'
option 'src' 'wan'
option 'proto' 'tcpudp'
option 'dest_port' '22'
3M双拔叠加后的效果图,最高能到630kb
设置自动换网关
/etc/ppp/ip-up.d/wan-up.sh
wan_ip=$(grep network.wan.ipaddr /tmp/state/network |cut -d"=" -f2 | cut -d" " -f1)
wan_gateway=$(grep network.wan.gateway /tmp/state/network |cut -d"=" -f2 | cut -d" " -f1)
wan_ifname=$(grep network.wan.ifname /tmp/state/network |cut -d"=" -f2 | cut -d" " -f1)
wan1_ip=$(grep network.wan1.ipaddr /tmp/state/network |cut -d"=" -f2 | cut -d" " -f1)
wan1_gateway=$(grep network.wan1.gateway /tmp/state/network |cut -d"=" -f2 | cut -d" " -f1)
wan1_ifname=$(grep network.wan1.ifname /tmp/state/network |cut -d"=" -f2 | cut -d" " -f1)
route add default gw $wan_ip
echo $wan_ip
echo $wan1_ip
if ($wan_gateway=$wan1_gateway); then
#if (wan_gateway=wan1_gateway); then
echo ifdown wan1....
ifdown wan1
echo ifup wan1....
ifup wan1
else
/etc/init.d/multiwan restart
fi
echo OK.......
执行chmod +x /etc/ppp/ip-up.d/wan-up.sh
目前该组件还不太完美,有个小问题(不知道是不是因为有3G才这样的):
当PPPoE和3G都接入后,需要手动把Multi-WAN再启动一次,也就按下Multi-WAN设置页面的“Save & Apply”按钮,合并才会生效。
貌似不是很方面,但是有个解决办法,修改一个脚本/etc/hotplug.d/net/10-net:
case "$ACTION" in
add|register)
case "$PHYSDEVDRIVER" in
natsemi) sleep 1;;
esac
addif
在上面语句后面添加:
sh /usr/bin/multiwan restart
当检测有网络接入时,自动重启Multi-WAN。
经过上面修改后,3G+PPPoE基本上完美了,无需考虑顺序问题了,3G和PPPoE随便插,不管谁先谁后,谁上谁下,随便插好了, 哈哈