OpenWRT使用macvlan虚拟多wan:
opkg update
opkg install kmod-macvlan
#https://www.haiyun.me
#eth1.1为wan接口
ip link add link eth1.1 eth1.2 type macvlan
ip link set eth1.2 address 00:1f:a3:65:55:2d
ip link set eth1.2 up
ip link add link eth1.1 eth1.3 type macvlan
ip link set eth1.3 address 00:1f:a3:65:55:3d
ip link set eth1.3 up
拨号时写入脚本同时多拨,也可使用morfast修改的pppd提高多拨成功率,PPPD拨号参数:
/usr/sbin/pppd plugin rp-pppoe.so mtu 1492 mru 1492 nic-eth1.1 persist usepeerdns nodefaultroute \
user <user> password <passwd> ipparam wan ifname pppoe-wan1 &
多拨成功后配置多路由负载均衡:
ip route add default scope global nexthop via ip1 dev pppoe-wan1 weight 1 nexthop via ip2 dev \
pppoe-wan2 weight 1 nexthop via ip3 dev pppoe-wan3 weight 1
iptables添加SNAT:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o pppoe-wan1 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o pppoe-wan2 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o pppoe-wan3 -j MASQUERADE
一段时间后查看负载均衡效果:
iptables -t nat -L POSTROUTING -nv
Chain POSTROUTING (policy ACCEPT 1206 packets, 81303 bytes)
pkts bytes target prot opt in out source destination
1948 158K MASQUERADE all -- * pppoe-wan1 192.168.1.0/24 0.0.0.0/0
1943 159K MASQUERADE all -- * pppoe-wan2 192.168.1.0/24 0.0.0.0/0
1912 559K MASQUERADE all -- * pppoe-wan3 192.168.1.0/24 0.0.0.0/0
为公平分配可禁用路由缓存:
echo -1 > /proc/sys/net/ipv4/rt_cache_rebuild_count