Most of the time a smartphone's wifi hotspot isn't powerful enough. So you might want to use the internet via usb tethering to router for better wifi coverage.
I'm pretty sure most of the routers can't do that by default, even if they have a USB port.
That's when OpenWrt is extremely useful, openwrt usb tethering is quite simple if you've a little knowledge about it.
Contents
What you need to setup OpenWrt usb tethering ?
Of course you need a router running OpenWrt with a USB port and a smartphone or a 3G/4G router capable of USB tethering.
Beside that, you've to make sure that,
- There's atleast 20 KB free space left on the router's NOR flash memory.
- The router can connect to internet somehow, need to install drivers.
- You're not using the USB port for any other purpose, like extroot.
- Basic understanding of linux commands and OpenWrt.
Alternatively you can build a OpenWrt custom firmware including the kmod-usb-net-rndis driver.
1. Login to the router via SSH and install drivers
At this step, you need to login to your router via SSH, use Putty if you're on Windows.
ssh root@192.168.1.1
Make sure the router is connected to the internet, either through the WAN interface via an ethernet cable or via WiFi client mode. I used my laptop's ethernet port to share existing wifi connection through NetworkManager.
Now update the opkg repository with opkg update
, and install the OpenWrt RNDIS driver.
opkg install kmod-usb-net-rndis
That's enough, the package kmod-usb-net-rndis will automatically pull all other dependencies.
All kernel drivers should be loaded automatically, check it with lsmod | grep 'rndis'
command.
2. Edit network interfaces
In this step, first plugin your tethering device and check what interface is created by the rndis_host driver.
root@openwrt:~# dmesg
[ 59.980000] usb 1-1: new high-speed USB device number 3 using ehci-platform [ 60.160000] rndis_host 1-1:1.0 eth2: register 'rndis_host' at usb-ehci-platform-1, RNDIS device, fc:de:56:ff:01:06
Now create a new network interface, usb_wan and configure it.
Edit the /etc/config/network file with vi, and add the lines below, anywhere you want.
config interface 'usb_wan' option ifname 'eth2' option proto 'dhcp'
Now save the changes and exit vi editor. If you're not familier with the vi text editor, have a quick look here.
IPv6 support configuration
This is optional, but if you're thinking about IPv6 connectivity, create another interface usb_wan6
on the /etc/config/network
file and add these extra lines there.
config interface 'usb_wan6' option ifname 'eth2' option proto 'dhcpv6'
Now reload the whole OpenWrt networking stuff.
/etc/init.d/network reload
You can see the a the new network interface is now up, and got an ip address.
In the above screenshot, eth0 is the ethernet LAN interface, eth1 is the ethernet WAN interface and eth2 is the USB tethered interface.
Note: If the tethering device is assinging the router any IP between 192.168.1.1 to 255, then you may need to change the ip address of the LAN interface from 192.168.1.1 to something like 192.168.2.1.
I've to change that, as my LTE router is assigning the 192.168.1.100 address to the router, so it was not working.
Conclusion
Basically the smartphone acts as a USB to ethernet adapter which we need to setup. This tutorial is also applicable for those external ethernet adapters too.
So that's how to setup USB tethering on a OpenWrt router. It's simple enough if you're familier with Linux and OpenWrt, but quite dubious for beginners. I can't make it even more simplier.
What's your thought about this method of setting up USB tethering to router ? Let me know through the comments.
Alaa says
Many thanks Arnab,
Is there a way to fix the usb mapping to a certain id for example make it always eth2 ?connecting and disconnecting the devices keeps changing the id and this requires reconfiguration of wan every time.
Mukesh says
Hello Aranab
Is this method possible to implement in tplink w8968 v4 ? I am trying to use my old 4g phone to connect with usb port of above router and use jio 4g net in entire house.
Arnab Satapathi says
Yes, I've tested it with a android phone and JioFi 2.
shori says
Great article !!!
Can be tether my smartphone as modem with the Router TP-Link TL-MR3420 nMax 3G / 4G Router 300Mbps ?
Tnx
shori
Arnab Satapathi says
Yes, you can, I can confirm it.
shori says
Thanks so much for the response.
We're talking about this router right?
https://ksp.co.il/index.php?select=&kg=&list=1&sort=2&glist=1&uin=13462&txt_search=%D7%A8%D7%90%D7%95%D7%98%D7%A8+%D7 % A1% D7% 9C% D7% 95% D7% 9C% D7% A8% D7% 99 & buy = & minprice = 0 & maxprice = 0 & intersect = .. & rintersect = & store_real =
Arnab Satapathi says
Yes, that wold work too.
I have the MR3220 model.
shori says
Thank allot.
I will try it
shori says
TNX, I will try and update.
You have very nice site.
Good day
Joob says
When I tether from my phone via USB it also acts as a DHCP server. If I would use this method, would that mean that the router will also do DHCP and so I'll have double NAT? Is is possible to use the router to only act as a bridge between the wireless and wired LAN interfaces to the USB interface of the phone?
Arnab Satapathi says
Yeah, it's actually double NAT, as the router's LAN and WLAN interface are binded togather and running their own DHCP service.
I'm not sure whether it's possible to bridge all 3 interfaces USB, LAN and WLAN.
Yuvraj says
Informative Blog. Thanks For sharing
JoeGalind says
Excellent tutorial. I had been banging my head trying to get this to work with a Verizon 4G dongle.
I had to add the following for it to work, since it was detected as a mass storage device:
okpg install usb-modeswitch
Edit /etc/usb-mode.json
Add the following:
"1410:9020": {
"*": {
"msg": [ ],
"config": 4
}
},
The 1410:9020 corresponds to the vendorid & deviceid for my dongle.
Hope this helps.
Arnab Satapathi says
That's great to know Joe.
And thanks for the USBmodeswitch part.
I've a plan to write a seperate tutorial about USB modeswitch and USB modem on OpenWrt in near future.
Yaser says
The tutorial is quite clear
Arnab Satapathi says
Thanks 🙂
Yaser says
Is there any possibility to send call from openwrt / linux to android phone?
Arnab Satapathi says
It may be possible, via adb commnds, unfortunately old school AT commands doesn't work well on modern android phones.
A better alternative could be using a cheap GSM module, like SIM800C, if you really need to make calls or send SMS from a router.
Yaser says
Any opportunity to get android phone get automatic tethering and without rooting the phone?
Arnab Satapathi says
Unfortunately I don't have a Andoid device now, so I can't test it.
However my LTE modem automatically tethers to the router, the LTE modem is not much different from a phone, just without the display.
YASER says
Can you do paid development on openwrt ?
Arnab Satapathi says
Unfortunately not, too much caught up with other activities.