Cellular Phone/USB Modem as WAN connection

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 09:56, 4 April 2020 (edit)
S2s2 (Talk | contribs)
m (added note on private range from wan/firewall)
← Previous diff
Current revision (18:06, 22 April 2024) (edit) (undo)
Kernel-panic69 (Talk | contribs)
(USB Phone Tethering [Attach an android-based phone via USB to a router] - (fix typo))
 
(22 intermediate revisions not shown.)
Line 1: Line 1:
{{languages|Cellular_Phone/USB_Modem_as_WAN_connection}} {{languages|Cellular_Phone/USB_Modem_as_WAN_connection}}
 +__FORCETOC__
-=Main Guide [Updated 3/2020]=+=Main Guide=
-USB Tethering with an Android phone, or using a USB Modem dongle, on your DD-WRT enabled router.+USB Tethering with an Android phone, or using a USB Modem, on your DD-WRT-enabled router.
-==USB Phone Tethering==+==USB Phone Tethering [Attach an android-based phone via USB to a router]==
-Tethering your DD-WRT router to an Android phone?+'''NOTE:''' [https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=336351 DD-WRT builds 55779 and newer include Android tethering as an option by default on routers that include the kernel modules and have a USB port].<br>
 +'''NOTE:''' [https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=336351 This guide is problematic as it does not add the route gateway for the WAN properly on builds after 51140]. [https://forum.dd-wrt.com/forum/viewtopic.php?t=284684 There are workarounds].
-'''Here is a Step-by-Step, I did with a $40/m unlimited plan and a $5 router'''<br>+Already tethered your phone to your computer via USB (or wifi) and now you want to move up to having a full router?
-Phone: Verizon Visible R2 (ZTE) $19 phone with a $40/m completely unlimited LTE-only pre-pay<br>+Testing w/
-Router: Linksys EA6400 running DD-WRT v3.0-r37012 std (09/21/18)<br>+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.
-Note: I had not used the router in awhile, and had no reason to upgrade the firmware. This was written when this wiki was updated (2020/04).<br>+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!].
-'''This assumes you have reset your router FIRST'''. If you have an existing custom config, back it up, then reset the router, and test this out. If you can get it working from a reset router, then you'll have to figure out what you need to do after reloading your custom config if it does not work.+==='''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 <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.
-#Services, USB: Enable 'Core USB Support' and 'USB over IP' (not sure if the 2nd is necessary, but it works when On). Apply.+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.
-#Android phone connected to router's USB port+
-#Turn on USB Tethering in the phone. (Settings, Network & Internet, Hotspot & Tethering)+
-#*Phone will not allow USB Tethering to be turned-on, <u>until it has power from the USB Port on the router. There will be no power until the 'Core USB Support' is turned on and applied</u>.+
-#Telnet into the router. Run the following commands:+
-##<tt>cd /lib/modules/4.4.157</tt>+
-##*The last folder, <tt>.../4.4.157</tt>, will vary in name, depending on the kernel build (your version of DD-WRT).+
-##*''For noobs: do a <tt>cd /lib/modules</tt>, then an <tt>ls</tt> to see what the name of the folder is. Or look in Status tab.''+
-##<tt>insmod usbnet.ko</tt>+
-##<tt>insmod cdc_ether.ko</tt>+
-##<tt>insmod rndis_host.ko</tt>+
-##<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 --table nat --append POSTROUTING --out-interface usb0 -j MASQUERADE</tt>+
-##*If you notice that your WAN IP (IP from the Cellular Phone) is in a private range (e.g. 192.168.x.x), then instead of doing line/step 8, you may instead want to simply turn-off the router's firewall (Security, SPI Firewall: Disable), as that reduces complexity.+
-##<tt>iptables --append FORWARD --in-interface br0 -j ACCEPT</tt>+
-You should now be able to also <tt>ping google.com</tt> from any client devices.+==='''Steps:'''===
- +#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.
-If the above works for you, then you can automate it by adding the first 6 lines to the Startup script:+#Phone: connect it to router's USB port with a USB cable you've already used for successful tethering with your laptop.
-#Go to tab Administration, Commands. +#Phone: Turn on your phone's Developer Options: [Click 'Build Number' in 'About Phone', 7 times in rapid succession]
-#Insert <code>sleep 10</code> as the first line.+#Phone: Search for 'Default USB Configuration' in 'Developer Options'. Set it to 'USB Tethering'
-#Add above commands number 1 through 6, into the Commands box. +#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.
 +#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.
 +#<b>MSS Clamping</b>: the following corrects potential MTU issues when connecting a phone to a router. It is a workaround for upstream provider issues. A common symptom is, Android devices connect to WiFi, but then periodically report 'No internet'.<br>
 +#:<code>iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu</code>
 +#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>
 +#:The actual value of '65' varies with the upstream provider.
 +#Fully test your apps, websites and other services on all your connected clients.
 +#;Everything should be working at this point.<br>
 +#To make the router configure automatically on bootup, automate the above process 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'. #Click 'Save Startup'.
-#Paste commands 7 & 8 (iptables commands) into Commands, then click 'Save Firewall'.+#Paste:
-#For good measure, click on (Administration) Management. Click 'Save'. Then:+#:<code>iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE<br>
-#Reboot router, '''while'''+#:iptables -A FORWARD -i br0 -j ACCEPT
-#On your phone, pay attention to the USB Tethering slider. It will be off, and you will not be able to turn it on, until the router boots far enough that Core USB Services are turned back on as part of it's startup. (~10 to 25 seconds)+#:iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu</code>
-#<u>When you see the option for USB Tethering is no longer greyed-out</u>, slide the switch to turn it on.+#Click 'Save Firewall'.
-#*''Noobs: This is why <code>sleep 10</code> was added to the Startup script. It gives you time to turn on USB Tethering.''+# Click on (Administration) Management. Click 'Save'. Then 'Reboot Router'.
-#*Note: the slider switch for tethering may 'bounce', appear to turn off for a split second, but then will turn back on. That is 'normal android behaviour'. You may also get a pop-up for the connection method of the phone. Just click on MTP (or another selection) and the pop-up will go away.+#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.<br>+''Credits: Users sydlexia and shenoyh on the forums for the source information.<br>
See link: https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1128616#1128616 See link: https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1128616#1128616
-==USB Modem: dongle==+==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: 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. K26 NEWD-2 Mega/Big builds starting with 14414 now have the 3G/UTMS WAN connection option built into the firmware.

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]

NOTE: DD-WRT builds 55779 and newer include Android tethering as an option by default on routers that include the kernel modules and have a USB port.
NOTE: This guide is problematic as it does not add the route gateway for the WAN properly on builds after 51140. There are workarounds.

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.
  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.
  9. 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)
  10. insmod usbnet.ko
  11. insmod cdc_ether.ko
  12. insmod rndis_host.ko
    Use the command 'lsmod' to verify the modules usbnet, cdc_ether and rndis_host are running.
  13. ifconfig usb0 up
  14. 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.
  15. iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
  16. iptables -A FORWARD -i br0 -j ACCEPT
    You should now be able to ping google.com from any client devices.
  17. MSS Clamping: the following corrects potential MTU issues when connecting a phone to a router. It is a workaround for upstream provider issues. A common symptom is, Android devices connect to WiFi, but then periodically report 'No internet'.
    iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
  18. 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
    The actual value of '65' varies with the upstream provider.
  19. Fully test your apps, websites and other services on all your connected clients.
    Everything should be working at this point.
  20. To make the router configure automatically on bootup, automate the above process by adding the following lines to the Startup script:
  21. Go to the tab Administration, Commands.
  22. 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
  23. Click 'Save Startup'.
  24. 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
  25. Click 'Save Firewall'.
  26. Click on (Administration) Management. Click 'Save'. Then 'Reboot Router'.
  27. 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.