If you have OpenWrt installed on your home router and you’d like to have a backup internet connection or a secondary WAN connection (e.g. to do a load-balancing between multiple WANs) then you might be interested in this post.
I will describe steps I needed to do in order to configure 2 WAN connections used simultaneously:
- one coming from cable modem and
- second one from USB LTE modem Huawei E3272 with SIM card from Polish telecom operator Plus GSM.
My router is Linksys WRT1900AC with OpenWrt 17.0.1 / LEDE on board.
First things first - RJ45 modem (WAN1) was a no-brainer. However, WAN2 was a bit more problematic. When I connected the USB modem it was lacking the appropriate drivers. This could be identified by taking a look at connected USB devices:
cat /sys/kernel/debug/usb/devices
When for a given device you see ‘None’ and none of the other entries show any modem capabilities, most likely your USB modem is treated like some mass-storage device. So, you need appropriate drivers to make it alive. In case of my E32727 it was CDC NCM and below you can see the result of the same command after OpenWRT recognizes USD modem capabilities (look at huawei_cdc_ncm
):
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=480 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=12d1 ProdID=1506 Rev= 1.02
S: Manufacturer=HUAWEI Technology
S: Product=HUAWEI Mobile
C:* #Ifs= 5 Cfg#= 1 Atr=80 MxPwr=500mA
I:* If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=02 Prot=10 Driver=option
E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=2ms
E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=4ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=02 Prot=12 Driver=option
E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=4ms
I: If#= 2 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=02 Prot=16 Driver=huawei_cdc_ncm
E: Ad=84(I) Atr=03(Int.) MxPS= 64 Ivl=2ms
I:* If#= 2 Alt= 1 #EPs= 3 Cls=ff(vend.) Sub=02 Prot=16 Driver=huawei_cdc_ncm
E: Ad=84(I) Atr=03(Int.) MxPS= 64 Ivl=2ms
E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=4ms
I:* If#= 3 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 4 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I also installed few other packages that were useful:
opkg install usb-modeswitch kmod-usb2 libusb-1.0 chat comgt-ncm \
kmod-usb-net-cdc-ncm kmod-usb-serial kmod-usb-serial-option \
kmod-usb-net-huawei-cdc-ncm
After the reboot I was able to see in logs that 2 new device files were created – ttyUSB0
and ttyUSB1
. To view the logs, used following command:
logread
I also checked ifconfig
and noticed that there was new interface named wwan0
.
For the rest of the article I’m assuming that second network interface is named wwan0
– in your case it might be different, so please adjust.
Now, if you know that your device has been recognized by the OS as a modem-capable you need to configure it properly. To do this you can invoke following operations to:
-
create new network interface (remember about assigning a name to your interface - if you won’t do it, it will be maked as ‘unknown interface’ all the time),
-
connect it with the device file (in my case
ttyUSB0
was not able to establish connection whilettyUSB1
worked perfectly fine, -
configure APN access (in my case it was “internet” as you can see below but it might differ depending on your telecom operator)
uci del network.wan2 uci set network.wan2=interface uci set network.wan2.proto=ncm uci set network.wan2.device=/dev/ttyUSB1 uci set network.wan2.apn=internet uci set network.wan2.ifname=wwan0 uci set network.wan2.metric=20 uci commit network
Some operations might work without reboot, but rebooting after changes gives you a certainty that all the configuration was reloaded during boot-up. In my case whole reboot operation is like 20 - 25 seconds long so it’s not a big pain.
After the reboot you can check if the network connection is working fine. First thing - check logs (again: logread
) for AT commands and status:
daemon.notice netifd: Interface 'wan2' is setting up now
daemon.notice netifd: wan2 (16649): sending -> AT
daemon.notice netifd: wan2 (16649): sending -> ATZ
daemon.notice netifd: wan2 (16649): sending -> ATQ0
daemon.notice netifd: wan2 (16649): sending -> ATV1
daemon.notice netifd: wan2 (16649): sending -> ATE1
daemon.notice netifd: wan2 (16649): sending -> ATS0=0
daemon.notice netifd: wan2 (16649): sending -> AT+CGDCONT=1,"IP","internet"
daemon.notice netifd: wan2 (16649): Starting network wan2
daemon.notice netifd: wan2 (16649): sending -> AT^NDISDUP=1,1,"internet"
daemon.notice netifd: wan2 (16649): Setting up wwan0
daemon.notice netifd: Interface 'wan2' is now up
daemon.notice netifd: Network device 'wwan0' link is up
daemon.notice netifd: Network alias 'wwan0' link is up
daemon.notice netifd: Interface 'wan2_4' is enabled
daemon.notice netifd: Interface 'wan2_4' has link connectivity
daemon.notice netifd: Interface 'wan2_4' is setting up now
daemon.notice netifd: wan2 (16649): Command failed: Unknown error
daemon.notice netifd: wan2_4 (16734): udhcpc: started, v1.25.1
daemon.notice netifd: wan2_4 (16734): udhcpc: sending discover
daemon.notice netifd: wan2_4 (16734): udhcpc: sending select for xx.xx.xx.xx
daemon.notice netifd: wan2_4 (16734): udhcpc: lease of xx.xx.xx.xx obtained, lease time 518400
daemon.notice netifd: Interface 'wan2_4' is now up
Now, let’s test connection on both interfaces:
ping -c5 -I eth1 google.com
ping -c5 -I wwan0 google.com
After you’ve tested the connectivity you can move to Multi-WAN configuration. This is done by using the mwan3
package.
In my case, upgrade of mwan3
package was required. My E3272 required NCM drivers and mwan3
version (2.0.x) coming from OpenWrt/LEDE 17.x was too old. It had problems with recognizing the wan2
modem-based interface.
Therefore, I needed to grab a newer version, so I downloaded it from OpenWrt site and installed it:
# wget http://downloads.openwrt.org/releases/18.06.2/packages/arm_cortex-a9_vfpv3/packages/mwan3_2.6.18-1_all.ipk
# opkg install mwan3_2.6.18-1_all.ipk
Then again, with the newer version of mwan3
there was an issue with showing both interfaces being off… Fortunately OpenWrt forum came to help with this thread. Simple solution was to add following 2 lines:
config globals 'globals'
option enabled '1'
to the configuration file located at /etc/config/mwan3
.
Now, add the new wan2
to the firewall zone together with wan
(eko.one.pl came with help):
# uci add_list firewall.@zone[1].network=wan2
# uci commit firewall
Now, I’ve moved to configuration of mwan3
directly. This can be simplified by using the GUI (LuCI), so I’ve installed appropriate package:
# opkg install luci-app-mwan3
You need to remember to add metric to each WAN interface as this is required for mwan3
.
Now you can assign a proper “weight” to each interface – you can do it from LuCI if you’ve installed previously mentioned packages.
You can set it to 50/50 (fair traffic distribution), 25%/75% or whatever option suits you.
You set the weights by modifying marked members of the configuration:
You can check the results by looking at how the traffic will be balanced:
Thanks a lot to eko.one.pl for being such tremendous source of knowledge!
Useful links: