Cellular Phone/USB Modem as WAN connection

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 08:34, 25 September 2009 (edit)
Alvin (Talk | contribs)
m (Writing a Chat Script - - optimized wiki formatting tags)
← Previous diff
Current revision (16:43, 15 December 2021) (edit) (undo)
Kernel-panic69 (Talk | contribs)
('''Steps:''')
 
(43 intermediate revisions not shown.)
Line 1: Line 1:
-This guide will take you through the steps to setup a router running DD-WRT to use a cellular phone or other usb modem as it's WAN connection to the internet.+{{languages|Cellular_Phone/USB_Modem_as_WAN_connection}}
 +__FORCETOC__
-I developed and tested on an Asus WL-500W but this should work with other models that have USB ports and can run DD-WRT v24-sp1 Mega. I have also tested on a Linsys WRTSL54GS to the point of the phone being connected, recognized as an ACM device, and the device node being created.+=Main Guide=
-This is not the most elegant solution but it is working great for me so far. If the pppd scripts for establishing a pppoe connection could be modified setting this up would be less complex and more centralized.+USB Tethering with an Android phone, or using a USB Modem, on your DD-WRT-enabled router.
-Even though I used this with a Samsung CDMA cellular phone, it should work for any phone or modem that will work with the ACM driver. For those looking for a new cell phone almost all of Samsungs current phones will use the acm driver.+==USB Phone Tethering [Attach an android-based phone via USB to a router]==
 +Already tethered your phone to your computer via USB (or wifi) and now you want to move up to having a full router?
 +Testing w/
 +Phone: 1st tested with a Verizon Visible R2 (5/2mbs) on 5/20, but then upgraded to a Pixel 2 w/PixelExperience 6/21 [with Band 66 and Carrier Aggregation support], and then tested with a Pixel 3a G020G (rootable) 11/21.
 +Service: Visible LTE-only pre-pay [bandwidth on the VR2 and other non-Band 66, Non-CA phones is typically 5/2Mbs, but with the better Pixels, it is typically 15Mbps down, 15+mbps up, on AWS Band 66+CA. There is no data maximum per month after which your data rate becomes unusable (e.g. 50GB 'unlimited' limit on Tmobile Pre-pay)]<br>
 +Router: 1st: Linksys EA6400 running DD-WRT v3.0-r37012 std (2018/09/21) and also works with r42819 (2020/03/30) [fully tested!].
-==Disclaimer==+==='''Requirements:'''===
-As always if you attempt this you may permanently damage your router and/or your phone or modem and any other USB devices which are connected... Procede at your own risk, I assume no responsibility.+1. '''Make sure the necessary modules exist on your build. This is very important. Some router builds are simply missing the modules, and it is beyond the scope of this guide or the ordinary user to build their own versions of the missing modules:''' We will go through the steps to check for this. This guide assumes that the build you downloaded and flashed of DD-WRT, has the modules <tt>cdc_ether.ko</tt> and <tt>rndis_host.ko</tt>, which are not present on some builds (regardless of build size) but required for USB tethering. If they do not exist on your build, you may need either: a larger version of DD-WRT that includes them, or to reflash over to OpenWRT [However OpenWRT has limited Broadcom support!]. These are -very small- modules (8kb) but are not included on some larger builds for some routers.
 +2. '''Reset your router:''' This assumes you have saved your existing Router settings first, '''before resetting your router''' to test these USB Tethering settings. If you've done some custom config since flashing your router, and you want to keep it, first: back up your settings, then reset the router, and test this out. If you can get it working from a reset router, then if it does not work with your custom settings, you'll have to figure out what additional steps you need to do that are beyond the scope of this article.
-==Before we begin==+==='''Steps:'''===
-*To follow this how-to you will need to be able to use the command shell through a telnet or ssh session.+#Router: Main configuration page: leave WAN on Automatic DHCP. Set the MTU manually between 1200-1428 (max) [https://forum.xda-developers.com/showthread.php?t=997116]. Set your timezone. Save & Apply.
-*I will not go into too much detail for procedures that are already available as tutorials in the wiki.+#Phone: connect it to router's USB port with a USB cable you've already used for successful tethering with your laptop.
-*Beginners may want to do some reading and make sure that they understand all of the steps involved BEFORE starting. I always believe it is best to know why you are doing something instead of just typing commands blindly since if you screw something up you won't understand what you did and how to fix it.+#Phone: Turn on your phone's Developer Options: [Click 'Build Number' in 'About Phone', 7 times in rapid succession]
-*If you have any experience with *nix os's and a command shell it will be a great help.+#Phone: Search for 'Default USB Configuration' in 'Developer Options'. Set it to 'USB Tethering'
-*Having a full fledged linux system available with pppd, chat, and wvdial installed will provide you with man pages to help you out otherwise the man pages can be found on the internet.+#Phone: '''Permanently turn off your screen lock''' (PIN or pattern etc). '''The phone must be unlocked for USB Tethering to turn on automatically''' when the router is booting-up, with the phone plugged in & powered-up from the Router USB port. A locked phone will not tether when the router's USB interface turns on.
-*Access to a computer running linux that has ACM support and wvdial installed can be used to get the init strings for your phone/modem in many cases.+#:*''(Alternative, not tested) Use Android's Smart Lock feature to automatically unlock your phone.''
-*I precede all commands that are to be issued in the shell with a #.+#Router: Services, USB: Enable 'Core USB Support'. Apply.
 +#Phone: USB Tethering should now turn on automatically. '''Check to make sure this is happening.'''
 +#:You can press Cancel or simply ignore the pop-up that appears asking what USB connection mode the phone should use. It will have USB tethering turned-on either way at this point.
 +#Router: Telnet into the router. Run the following commands:
 +#: Press Enter after each command. <tt>insmod</tt> commands will insert modules quietly, and not report success.
 +##<tt> ls -a /lib/modules/$(uname -r)</tt> check for presence of usbnet.ko, cdc_ether.ko, and rndis_host.ko<br>(you do '''NOT''' need to be in the modules directory to execute the following)
 +##<tt>insmod usbnet.ko</tt>
 +##<tt>insmod cdc_ether.ko</tt>
 +##<tt>insmod rndis_host.ko</tt>
 +##:Use the command <tt>'lsmod'</tt> to verify the modules <tt>usbnet</tt>, <tt>cdc_ether</tt> and <tt>rndis_host</tt> are running.
 +##<tt>ifconfig usb0 up</tt>
 +##<tt>udhcpc -i usb0</tt>
 +##:You should be able to '<tt>ping google.com</tt>' now from within the telnet interface, but not yet on any connected client devices. ''Noobs: CTRL-C to stop pinging.''
 +##<tt>iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE</tt>
 +##<tt>iptables -A FORWARD -i br0 -j ACCEPT</tt>
 +##:You should now be able to <tt>ping google.com</tt> from any client devices.
 +##Set the following: further corrects potential MTU issues when connecting a phone to a router (not only DD-WRT!):<br>
 +##: <code>iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu</code>
 +##(Optional: Not tested)If you are trying to hide tethering:<br>
 +##: <code>iptables -t mangle -I POSTROUTING -o $(get_wanface) -j TTL --ttl-set 65<br>
 +##: iptables -t mangle -I PREROUTING -i $(get_wanface) -j TTL --ttl-set 65</code><br>
 +##Fully test your apps, websites and other services on all your connected clients.
 +##;Everything should be working at this point.
 +##*To make the router configure automatically on bootup, you can automate it by adding the following lines to the Startup script:<br>
 +##Go to the tab <tt>Administration</tt>, <tt>Commands</tt>.
 +##Paste: [these are the commands you used above]
 +##:<code>insmod usbnet.ko<br>
 +##:insmod cdc_ether.ko<br>
 +##:insmod rndis_host.ko<br>
 +##:ifconfig usb0 up<br>
 +##:udhcpc -i usb0<br>
 +##:sleep 5<br></code>
 +##Click 'Save Startup'.
 +##Paste:
 +##:<code>iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE<br>
 +##:iptables -A FORWARD -i br0 -j ACCEPT
 +##:iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu</code>
 +##Click 'Save Firewall'.
 +## Click on (Administration) Management. Click 'Save'. Then 'Reboot Router'.
 +##You may have to reboot the router if you make configuration changes.
-In the router's web gui I left the WAN connection set on ''Automatic Configuration- DHCP'' on the ''Setup'' -> ''Basic Setup'' page. I don't know if it matters if it is set to one of the other settings but there is a possibility that setting it to ''pppoe'' or ''dissabled'' could cause a problem. 
-If you use a cell phone, it must be capable of being used as a modem. Most smartphones that run Windows Mobile are not capable of this without third party software installed on the phone. The Internet Connection Sharing application on the phone will not work with this method, I am working on a solution for this as well though.+::'''Again, everything should be working at this point.''' You are finished with this guide. Thank you!
- +''Credits: Users sydlexia and shenoyh on the forums for the source information.<br>
-==What you need==+
-*Router with a USB port and capable of running DD-WRT v24-sp1 Mega+
-*USB Cellular Phone or other modem compatible with ACM+
-*ACM kernel module+
-*chat ipkg+
 +See link: https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1128616#1128616
-==What to do:==+==USB Modem [Use dongle that contains a SIM]==
 +There are newer methods, integrated into the firmware than the previous version of this wiki. The relevant threads:
 +K26 NEWD-2 Mega/Big builds starting with 14414 now have the 3G/UTMS WAN connection option built into the firmware.
 +See the following thread for more information:
-==Flash the router==+http://www.dd-wrt.com/phpBB2/viewtopic.php?t=69970
-If you haven't allready done so, flash your router to DD-WRT v24-sp1 Mega. Be sure to use the proper procedure for your router model.+
 +See also http://www.dd-wrt.com/wiki/index.php/Mobile_Broadband for a list of directly supported device in K26 and K3.x builds.
-==Enable USB and JFFS==+[[Category:Wan]]
-In the web gui go to '''Services -> Services''' and enable USB support. I enabled all of the USB support as I plan to also use the router with storage devices and printers. For more on USB support see [[USB]] in the wiki.+[[Category:USB]]
- +
-In the web gui enable JFFS2 support in '''Administration -> Management'''. See [[JFFS File System]]+
- +
-I plan to eventually use a USB thumb drive for my JFFS partition but I will skip that step here as it is not necessary for this how to. If you are interested in doing the same refer to the tutorials in the wiki.+
- +
-After enabling USB and jffs support reboot the router for good measure.+
- +
- +
-==ACM Support==+
-Log into the router through a telnet or ssh session if you haven't already done so.+
- +
- +
-===Getting the kernel module===+
-Next we need the ACM kernel module (driver) for the phone to be used as a modem. I used the driver that is available in the following forum post http://www.dd-wrt.com/phpBB2/viewtopic.php?t=43358+
- +
-Download the archive and extract the file ''acm.o''+
- +
-Now copy the file to the jffs directory on the router using scp, wget, sshfs, samba share, a thumb drive.. whatever, see the other [[Tutorials]] on this wiki if you need help. I place to put the module is in <code>/jffs/lib/modules/</code> but it can be anywhere you want in <code>/jffs/</code> you just need to remember the location.+
- +
- +
-===Loading the kernel module===+
- +
- +
-<code># insmod /jffs/lib/modules/acm.o</code>+
- +
- +
-Change the directory above if you placed the module somewhere else.+
- +
-Now check to see if the ACM kernel module loaded.+
- +
- +
-<code># dmesg |grep acm</code>+
- +
- +
-Should return something like:+
- +
- +
-<code>usb.c: registered new driver acm<br>+
-acm.c: v0.21:USB Abstract Control Model driver for USB modems and ISDN adapters</code>+
- +
- +
-Put your phone into modem mode and connect it to the routers USB port. Wait a few seconds and see if the modem is recognized:+
- +
- +
-<code># dmesg</code>+
- +
- +
-In the last few lines you should see something like:+
- +
- +
-<code>hub.c: new USB device 01:03.0-2, assigned address 4<br>+
-ttyACM0: USB ACM device</code>+
- +
- +
-This tells us that the modem device was found and assigned a device node.+
- +
- +
-==Modem Init Strings==+
-For the next part we need the init strings for the modem. You might find them in the user manual or available online. Another way to get the init strings is to use an existing linux box that has ''wvdial'' installed and ACM support. If you don't have an existing linux install you can boot from an Ubuntu 8.10 live cd. It has ACM support by default and includes ''wvdial''. After connecting the modem, you can check dmesg here also to see that it was recognized, go to a shell or terminal session and use ''wvdialconf'' to generate a config file for your modem.+
- +
- +
-<code># wvdialconf ~/modem_config</code>+
- +
- +
-This will generate a file called ''modem_config'' in your home directory. This is just a text file that is a few lines long. You can read it however you like or just use ''cat'' to display it in the terminal. The things in the file that we are interested in are the maximum baud rate and init strings.+
- +
- +
-==Dialing and Establishing a Conection==+
-To dial out and establish a PPP connection we need two tools... ''pppd'' and ''chat''. ''pppd'' establishes the ppp connection and starts the network interface. ''Chat'' is called by ''pppd'' to do the actual dialing of the modem. ''pppd'' is already installed by default as it is used for PPPoE connections. However, we do need to install ''chat'', and it is available as an ipkg from the openwrt white russian repositories.+
- +
-We also need to create two scripts, one for ''pppd'' and one for ''chat''. Both of the scripts we create will need to be placed in the ''/jffs/etc/ppp/peers/'' directory. If you choose to use a different directory structure make sure to adjust any commands or scripts to fit your situation. The scripts are simple text files and can be created with any text editor, you can use vi while logged into the router and save them right to the directory where they need to be or you can create them on your computer and copy them over.+
- +
-First lets start by making a place to put the scripts. I chose to use the default directory structure that would normally be used but place it under ''/jffs/''+
- +
- +
-<code># mkdir /jffs/etc<br># mkdir /jffs/etc/ppp<br># mkdir /jffs/etc/ppp/peers</code>+
- +
- +
-===Chat===+
- +
-====Installing Chat====+
-If you already have an existing internet connection to the router see [[Ipkg]] to download and install the package. As my router could not get connected to the internet yet, I downloaded the ''chat'' ipkg on my laptop and copied it to ''/jffs/'' on the router and issued the following command.+
- +
- +
-<code># ipkg install /jffs/chat_2.4.3-7_mipsel.ipk</code>+
- +
- +
-====Writing a Chat Script====+
-Now to write the script to tell ''chat'' the phone number to dial and how to do it.+
- +
-A chat script is a series of expect/reply strings. You can actually pass everything in my simple script as options on the command line but the script makes things much more tidy. +
- +
-'''Here is my ''chat'' script as an example:'''+
- +
- +
-<code><nowiki>'' ATZ</nowiki><br>OK 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0'<br>TIMEOUT 12<br>OK ATD#777<br>TIMEOUT 22<br>CONNECT ''</code>+
- +
- +
-I saved the script as ''/jffs/etc/ppp/peers/isp_chat'' (I used my actual isp's name instead of 'isp'). I will refer to the file as though it is named as this. Adjust things if you name it something else.+
- +
-The twin single quotes starting the first line expects nothing, null, and sends ''ATZ'', this is the first init string for the modem and is a common one for many modems. The second line expects to see ''OK'' and then sends the second init string to the modem. Both of these init strings were from taken from the config file that I generated using wvdialconf on my laptop. Note the single quotes around the second init string, this is necessary for the white spaces to be interpreted properly, otherwise chat would send the ''ATQ0'' and think that ''V1'' is the next expect string. The fourth line expects ''OK'' and then sends the command to dial, ''ATD'', in this case the number being dialed is ''#777'', this is a common number for many CDMA cellular carriers. Note there is no space between the ''ATD'' command and the number to be dialed and the # is actually part of the phone number used in this example. The last line expects ''CONNECT'' and sends nothing ending the script and returning a ''0'' termination code to ''pppd''. I added the timeouts after spending a couple of hours trying to figure out why I could manually enter the commands using a dumb terminal like microcom, but ''chat'' would always hang or error out when it came to the dial command. After inserting the timeouts I haven't had any problems. If you need help writing the script refer to the ''chat'' man page or the internet. Just a note, I can successfully get a connection without the second init string with the phone I am using. The second init just sets things like the speed, buffers, compression, etc. so you may be able to get by with just the ''ATZ'' if you can not obtain the init strings for your modem. You can make the chat script far more complex but I saw no need in my situation.+
- +
-===Writing the PPPd script===+
-Once again you could pass all of the commands in this script as command line options when you start ''pppd''. In fact I did just that while testing and figuring this all out. Save the script as ''/jffs/etc/ppp/peers/isp''+
- +
-'''Here is my script file:'''+
- +
-<code>demand<br>persist<br>idle 300<br>maxfail 0<br>lock<br>/dev/usb/acm/0<br>460800<br>noauth<br>defaultroute<br>user xxxxxxxxxx<br>password xxxxxxxxxxx<br>connect '/jffs/usr/sbin/chat -t3 -f /jffs/etc/ppp/peers/isp_chat'+
- +
- +
-The first line tells ''pppd'' to dial on demand. Persist tells ''pppd'' to redial if the connection is terminated. Idle sets a timeout to disconnect the connection after 300 seconds of inactivity. I passed maxfail 0 to tell ''pppd'' not to error out in case someone disconnects the phone from the router to actually use it as a phone. You might not want to use this option if this does not apply to your situation. Lock creates a lock file so that ''pppd'' has exclusive access to the device. ''/dev/usb/acm/0'' is the device node that was created for the modem when it was plugged in, this might be different in your situation. The dmesg output from when you plugged in the phone/modem should lead you in the right direction to find out the node. 460800 is the port speed, I took this from the config file that was created by ''wvdialconf''. Noauth tells ''pppd'' to skip authorization. Defaultroute creates a default route to the network interface (ppp0) in the routing table. User is your username for the isp. Password is the password for the isp.+
- +
- +
-The last line tells ''pppd'' to issue the shell command that is in the single quotes. Here we are invoking ''chat'' to dial the modem. The options set the timeout to 3 and load the ''chat'' script file that you made in the previous section.+
- +
-==Testing the Connection==+
-Dissable or disconnect any other internet connections before testing as they could give you a false possitive.+
- +
-'''Start the connection:'''+
- +
- +
-<code># pppd file /jffs/etc/ppp/peers/isp</code>+
- +
- +
-'''Test to see if it connected:'''+
- +
- +
-<code># ifconfig</code>+
- +
- +
-should show you ppp0 is up+
- +
- +
-<code># ps</code>+
- +
- +
-should show ''pppd'' is running+
- +
- +
-<code># ping -c3 yahoo.com</code>+
- +
- +
-should get a response+
- +
- +
-If the three tests are successfull move on to [[#Starting things on boot]].+
- +
- +
-===Troubleshooting===+
-If you can not connect at this point here are a few tips. Remember to remove these changes once you have solved any issues.+
- +
-* add ''nodetach'' or ''updetach'' to the start of the ''pppd'' script so that you can see any output. ''nodetach'' will keep ''pppd'' from moving to the background and ''updetach'' will allow ''pppd'' to move to the background only after the network interface (ppp0) is brought up.+
- +
-* along with the above add a ''-V'' to the ''chat'' command in the ''pppd'' script, /jffs/usr/sbin/chat -V -t3 -f /jffs/etc/ppp/peers/isp_chat. This tells ''chat'' to be verbose and send the output to ''stderr'' (your shell session) for you to see.+
- +
-* if the problem seems to be with ''chat'' communicating with or dialing the modem you may want to use ipkg to install the microcom ipkg from the white russian or kamikaze openwrt repositories. You can use it to send commands directly to the modem one at a time to see where the problem is occuring.+
- +
- +
-====Using Microcom====+
- +
-This section needs to be finished...+
- +
- +
-==Starting things on boot==+
-Once you can successfully connect and get a ping response from a shell on the router, we need to make sure that the kernel module is loading and that ''pppd'' is being started on when the router boots. You can use nvram set commands if you know how to do it otherwise go back to the router's web gui. Go to '''Administration''' -> '''Commands'''. In the text box type the following:+
- +
- +
-<code>insmod /jffs/acm.o<br>+
-pppd file /jffs/etc/ppp/peers/isp</code>+
- +
- +
-Then click the '''Save Startup''' button.+
- +
- +
-'''We're not done yet!'''+
- +
- +
-==Fixing DNS and Internet Routing to the LAN/WLAN==+
-At this point we have two issues left to resolve:+
- +
-*routing to the lan/wlan and our new internet connection+
-*DNS+
- +
- +
-===DNS===+
-Normally we could use the ''usepeerdns'' option in our ''pppd'' script. ''pppd'' would then request and receive two DNS server addresses when it connects to the remote peer. It would then write them to ''/etc/ppp/resolv.conf'' and pass them on to the ''/etc/ppp/ip-up'' script. Unfortunately DD-WRT keeps DNS addresses in ''/tmp/resolv.conf'' which also has a symbolic link at ''/etc/resolv.conf'' and there is also no ''/etc/ppp/ip-up'' script. Normally we could make a symbolic link at ''/etc/ppp/resolv.conf'' and have it point to ''/tmp/resolv.conf'' but ''/etc'' can not be written to, so we can not create the directory or the symbolic link. I don't know of any way to have ''pppd'' write to a different file.+
- +
-The only way that I have found to solve the DNS issue is to set static DNS server addresses. You can do this on the '''Setup''' -> '''Basic Setup''' page of the web gui.+
- +
- +
-===Internet Routing===+
-The last thing to do is to set up the routing to the LAN and WLAN. There are two ways to accomplish this and they each have pros and cons.+
- +
- +
-====Add two rules to iptables====+
- +
- +
- +
-<code># iptables -A FORWARD -i br0 -o ppp0 -j ACCEPT<br># iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE</code>+
- +
- +
-The best way to add these rules is through the web gui so that they are written to nvram so you don't have to manually add them every time the router is rebooted. The problem with this solution is that if you use the web gui to set up any advanced routing involving the "WAN" interface, it will not recognize ppp0 as the WAN interface. Also the bandwidth from ppp0 will not show up on the WAN bandwidth graph. The advange to using this method is that if you are using your dial up connection in addition to or as a backup for a normal WAN connection on the WAN ethernet port of the router you don't mess up it's connection.+
- +
-====Change WAN values in nvram====+
-This is the solution that I used. What we do is to change the WAN references in nvram to point to ppp0 instead of the default of eth1. You can find the values that need changed by:+
- +
- +
-<code># nvram show | grep wan+
- +
-wan_unit=0<br>+
-wan_get_dns=<br>+
-wan_lease=0<br>+
-http_wanport=8080<br>+
-wan_gateway=0.0.0.0<br>+
-wan_hwname=<br>+
-wan_domain=<br>+
-wan_netmask=0.0.0.0<br>+
-wan_ifname2=eth1<br>+
-block_wan=1<br>+
-pppoe_wan_ifname=eth1<br>+
-dr_wan_rx=0<br>+
-wan_dns=<br>+
-dhcp_wins=wan<br>+
-wan_proto=dhcp<br>+
-wanup=0<br>+
-wan_hwaddr=00:23:54:07:FD:E9<br>+
-wan_default=eth1<br>+
-wan_ifnames=eth1<br>+
-dr_wan_tx=0<br>+
-wan_primary=1<br>+
-openvpn_onwan=0<br>+
-dhcp_domain=wan<br>+
-wan_gateway_buf=0.0.0.0<br>+
-wan_vdsl=0<br>+
-upnp_wan_proto=<br>+
-wan_ipaddr=0.0.0.0<br>+
-wan_wins=0.0.0.0<br>+
-wan_mtu=1500<br>+
-size: 21126 bytes (11642 left)<br>+
-sshd_wanport=22<br>+
-wan_get_domain=<br>+
-wan_ifname=eth1<br>+
-wan_hostname=</code>+
- +
- +
-Now we change all of the eth1 values to ppp0 and commit them to nvram:+
- +
- +
-<code># nvram set wan_ifname=ppp0<br># nvram set wan_ifnames=ppp0<br># nvram set wan_default=ppp0<br># nvram set pppoe_wan_ifname=ppp0<br># nvram set wan_ifname2=ppp0<br># nvram commit</code>+
- +
- +
-Reboot the router and you should be good to go.+
- +
- +
-The only quirk that I have noticed is that when the router boots the phone needs to be connected or pppd does not start. Once the router is booted though, I can disconnect and reconnect the phone from the router as much as I want.+
- +
-[[Category:English documentation]]+

Current revision


Contents

[edit] Main Guide

USB Tethering with an Android phone, or using a USB Modem, on your DD-WRT-enabled router.

[edit] USB Phone Tethering [Attach an android-based phone via USB to a router]

Already tethered your phone to your computer via USB (or wifi) and now you want to move up to having a full router?

Testing w/ Phone: 1st tested with a Verizon Visible R2 (5/2mbs) on 5/20, but then upgraded to a Pixel 2 w/PixelExperience 6/21 [with Band 66 and Carrier Aggregation support], and then tested with a Pixel 3a G020G (rootable) 11/21. Service: Visible LTE-only pre-pay [bandwidth on the VR2 and other non-Band 66, Non-CA phones is typically 5/2Mbs, but with the better Pixels, it is typically 15Mbps down, 15+mbps up, on AWS Band 66+CA. There is no data maximum per month after which your data rate becomes unusable (e.g. 50GB 'unlimited' limit on Tmobile Pre-pay)]
Router: 1st: Linksys EA6400 running DD-WRT v3.0-r37012 std (2018/09/21) and also works with r42819 (2020/03/30) [fully tested!].

[edit] Requirements:

1. Make sure the necessary modules exist on your build. This is very important. Some router builds are simply missing the modules, and it is beyond the scope of this guide or the ordinary user to build their own versions of the missing modules: We will go through the steps to check for this. This guide assumes that the build you downloaded and flashed of DD-WRT, has the modules cdc_ether.ko and rndis_host.ko, which are not present on some builds (regardless of build size) but required for USB tethering. If they do not exist on your build, you may need either: a larger version of DD-WRT that includes them, or to reflash over to OpenWRT [However OpenWRT has limited Broadcom support!]. These are -very small- modules (8kb) but are not included on some larger builds for some routers.

2. Reset your router: This assumes you have saved your existing Router settings first, before resetting your router to test these USB Tethering settings. If you've done some custom config since flashing your router, and you want to keep it, first: back up your settings, then reset the router, and test this out. If you can get it working from a reset router, then if it does not work with your custom settings, you'll have to figure out what additional steps you need to do that are beyond the scope of this article.

[edit] Steps:

  1. Router: Main configuration page: leave WAN on Automatic DHCP. Set the MTU manually between 1200-1428 (max) [1]. Set your timezone. Save & Apply.
  2. Phone: connect it to router's USB port with a USB cable you've already used for successful tethering with your laptop.
  3. Phone: Turn on your phone's Developer Options: [Click 'Build Number' in 'About Phone', 7 times in rapid succession]
  4. Phone: Search for 'Default USB Configuration' in 'Developer Options'. Set it to 'USB Tethering'
  5. Phone: Permanently turn off your screen lock (PIN or pattern etc). The phone must be unlocked for USB Tethering to turn on automatically when the router is booting-up, with the phone plugged in & powered-up from the Router USB port. A locked phone will not tether when the router's USB interface turns on.
    • (Alternative, not tested) Use Android's Smart Lock feature to automatically unlock your phone.
  6. Router: Services, USB: Enable 'Core USB Support'. Apply.
  7. Phone: USB Tethering should now turn on automatically. Check to make sure this is happening.
    You can press Cancel or simply ignore the pop-up that appears asking what USB connection mode the phone should use. It will have USB tethering turned-on either way at this point.
  8. Router: Telnet into the router. Run the following commands:
    Press Enter after each command. insmod commands will insert modules quietly, and not report success.
    1. ls -a /lib/modules/$(uname -r) check for presence of usbnet.ko, cdc_ether.ko, and rndis_host.ko
      (you do NOT need to be in the modules directory to execute the following)
    2. insmod usbnet.ko
    3. insmod cdc_ether.ko
    4. insmod rndis_host.ko
      Use the command 'lsmod' to verify the modules usbnet, cdc_ether and rndis_host are running.
    5. ifconfig usb0 up
    6. udhcpc -i usb0
      You should be able to 'ping google.com' now from within the telnet interface, but not yet on any connected client devices. Noobs: CTRL-C to stop pinging.
    7. iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
    8. iptables -A FORWARD -i br0 -j ACCEPT
      You should now be able to ping google.com from any client devices.
    9. Set the following: further corrects potential MTU issues when connecting a phone to a router (not only DD-WRT!):
      iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
    10. (Optional: Not tested)If you are trying to hide tethering:
      iptables -t mangle -I POSTROUTING -o $(get_wanface) -j TTL --ttl-set 65
      iptables -t mangle -I PREROUTING -i $(get_wanface) -j TTL --ttl-set 65
    11. Fully test your apps, websites and other services on all your connected clients.
      Everything should be working at this point.
      • To make the router configure automatically on bootup, you can automate it by adding the following lines to the Startup script:
    12. Go to the tab Administration, Commands.
    13. Paste: [these are the commands you used above]
      insmod usbnet.ko
      insmod cdc_ether.ko
      insmod rndis_host.ko
      ifconfig usb0 up
      udhcpc -i usb0
      sleep 5
    14. Click 'Save Startup'.
    15. Paste:
      iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
      iptables -A FORWARD -i br0 -j ACCEPT
      iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
    16. Click 'Save Firewall'.
    17. Click on (Administration) Management. Click 'Save'. Then 'Reboot Router'.
    18. You may have to reboot the router if you make configuration changes.


Again, everything should be working at this point. You are finished with this guide. Thank you!

Credits: Users sydlexia and shenoyh on the forums for the source information.

See link: https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1128616#1128616

[edit] USB Modem [Use dongle that contains a SIM]

There are newer methods, integrated into the firmware than the previous version of this wiki. The relevant threads: K26 NEWD-2 Mega/Big builds starting with 14414 now have the 3G/UTMS WAN connection option built into the firmware.

See the following thread for more information:

http://www.dd-wrt.com/phpBB2/viewtopic.php?t=69970

See also http://www.dd-wrt.com/wiki/index.php/Mobile_Broadband for a list of directly supported device in K26 and K3.x builds.