openwrt配置虚拟多WAN,在/etc/config/network文件中修改。
在文件中添加配置wan2 wan3的虚拟配置,其中wan2的VLAN ID是2;wan3的VLAN ID是3,通过配置ifname中eth0.X,那么VLAN的ID就是X。配置成功后“/etc/init.d/network restart &”重启网络或则重启系统就可以了。
config interface 'wan'
option ifname 'eth0'
option mtu '1500'
option restart '0'
option proto 'dhcp'
config interface 'wan2'
option ifname 'eth0.2'
option mtu '1500'
option restart '0'
option proto 'static'
option ipaddr '192.168.11.150'
option netmask '255.255.255.0'
config interface 'wan3'
option proto 'static'
option ifname 'eth0.3'
option ipaddr '192.168.11.50'
option netmask '255.255.255.0'
也需要把防火墙配置了,不然也没办法上网。在/etc/config/firewall添加
list network 'wan1'
list network 'wan2'
list network 'wan3'
这样配置之后在虚拟的wan2与wan3并不能够成功获取到IP并通信成功,因为配置了VLAN ID而上游路由器并没有配置VLAN ID,所以你可以把 option ifname 'eth0.2'与 option ifname 'eth0.3'改为 option ifname 'eth0'。这样就能够正常使用虚拟的WAN2与WAN3进行通信,或者修改上游路由器/etc/config/network配置文件LAN的vlan ID(如下图所示),因为我的WAN口接的是上游路由器的eth1,所以我添加了eth1.1、eth1.2、eth1.3,即VLAN ID 1.2.3都可以通过该网口上网,我也保留了eth1,所以没有VLAN的设备也可以通过这个网口上网。