openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡

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'

openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客
openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客

///修改配置文件 我的是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' '^^[email protected]'
option 'password' 'EB96D1A895A1'

openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客
openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客
openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客

///防火牆設置
/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'

openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客
openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客
openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客

3M雙拔疊加後的效果圖,最高能到630kb

openwrt Multi-WAN+macvlan單WAN多帳戶 多拔疊加網絡 - 耗子 - 我的博客

設置自動換網關

/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隨便插,不管誰先誰後,誰上誰下,隨便插好了, 哈哈

發佈了3 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章