先更新官方源
安装所需的软件 macvlan、luci-app-multiwan
opkg update
opkg install ip
opkg install komd-macvlan
opkg install
编辑/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'
///防火墙设置
/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'
设置自动换网关
/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。