Skip to content

bxexamples/usbTetheredMobilePhoneLinuxRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

USB Tethered Mobile Phone Linux Router

Authors: Mohsen Banan — Date: <2022-02-19 Sat 19:51> — Last Updated: <2022-02-22 Tue 10:53>

Given:

  • A Mobile Phone
  • A USB Cable
  • A Laptop or a Raspberry Pi (OurRouter)
  • A plain Debian Linux distro (Debian-11)
  • An ethernet switch

we create a Wide-Area-Wireless Mobile LAN.

Table Of Contents

Scope

This is not just about usb tethering.

We also create a LAN. This is about providing access to the phone’s data connectivity by all hosts on a LAN.

This is not about USB tethering with an existing router.

Here we create our own router from scratch. We don’t add a phone to an existing router. The scope of this document includes creation of a router on top of Debian Linux.

Uses

There are manu uses for USB tethered mobile phone linux router, including:

  • A secondary WAN router to be used as a spare
  • A Failover router
  • A Mobile LAN. Say inside of an RV or a Boat.

Do It Yourself (DIY) And As A BISOS General Purpose Server Appliance (BISOS-GPSA)

The information in here is provided as DIY instructions. We are assuming that you are hip with Linux/Unix and that you can run with basic instructions and hints.

In parallel with these DIY instructions, the equivalent of these capbilities are also available as a plug and play BISOS Appliance. But this document is primarily geared towards the DIY model.

Main Steps

Tethering To Mobile Phone

As of 2022, tethering to mobile phones is quite reliable with Linux. We used an Android phone provisioned over T-Mobile in the US. To tether to mobile phone:

  • Plug USB cable into platform hardware
  • On Mobile Phone: Settings->Tehtering->USB Tethering
  • On Mobile Phone: Follow prompts
  • On our router: “ip a” should show you the link — something like “/dev/usb0”
  • Local side of the usb phone link would be something like 192.168.42.102 — the 102 is phone’s dhcp assignment.
  • Remote side of the usb phone link would be something like 192.168.42.129
  • Verify end-to-end connectivity by pinging say 8.8.8.8

If that wroks, tethering to mobile phone is in place.

Ethernet/Network interface naming — SNPA-Ids (Subnetwork Point-Of-Attachement Identifiers)

Through out the rest of this document we will be reffering to device interfaces in a generic fashion. The phone USB device – typically /dev/usb0 – will be called “phoneSnpa”. The LAN device – typically something like /dev/enp3s0 – will be called “lanSnpa”.

Create a minimal LAN

Setup a minmal LAN with two hosts. Let’s call it “OurLan” with OurRouter and a “TestingHost” on the lanSnpa.

Install, configure and test dhcpd on OurRouter

To install the dhcp server

sudo apt-get install isc-dhcp-server

Then configure a minimal dhcpd server.

Relevant BISOS ICMs (Interactive Command Modules) at https://github.com/bisos/bsip4/tree/master/bin are:

lcaDhcpServerBinsPrep.sh
svcDhcpSysdAdmin.sh

Plug the testing-host on our-lan, verify that it got the right values from our-router.

Enable IPForwarding On OurRouter

echo 1 > /proc/sys/net/ipv4/ip_forward

Setup NAT On OurRouter

On OurRouter we are now going to setup a traditional NAT (Network Address Translation).

phoneSnpa="/dev/usb0"
lanSnpa="/dev/enp3s0"
/sbin/iptables -t nat -A POSTROUTING -o ${phoneSnpa} -j MASQUERADE
/sbin/iptables -A FORWARD -i ${phoneSnpa} -o ${lanSnpa} -m state  --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i ${lanSnpa} -o ${phoneSnpa} -j ACCEPT

Keep Alive Traffic On The phoneSnpa

When there has been no traffic on the phoneSnpa link, the phone drops the usb connection.

To maintain the link, periodically we generate small amounts of traffic on the phoneSnpa. A simple ping seems to be sufficient.

End-to-End testing

With these in place, you can now ping a remote host from the testing-host. So, on testing-host try “ping 8.8.8.8”.

You now have yourself a usb Tethered Mobile Phone Linux Router.

Making It All persistent

These DIY instructions do not include information about making it all be persistent. You can do that on your own, or better yet use the IPForwarding-BISOS-GSPA.

IPForwarding General Purpose Server Appliance — IPForwarding-BISOS-GSPA

To setup your BISOS IPForwarding General Purpose Server Appliance:

  • Decide on whether you want a physical or a virtual appliance.
  • Bootstrap a generic BISOS platform.
  • Obtain the IPForwarding-BISOS-GSPA-BPO (ByStar Portable Object) and enhance the BISOS platform to a IPForwarding-BISOS-GSPA platform.
  • Configure your IPForwarding-BISOS-GSPA platform using supplied Blee-Panels
  • Save your specific configuration platform in your own BPO.
  • You can then reproduce your pre-configured IPForwarding-BISOS-GSPA with your own BPO.

Add-Ons Considerations

A usb Tethered Mobile Phone Linux Router, can be more than just that. Here are some additions to consider.

In combination with a Wi-Fi bridge

OurRouter’s hardware platform usually includes WiFi capabilities. And when it does not, it can easily be added. So, we can turn OurRouter into a WiFi access point as well. At that point we have have the equivalent of Wifi-tethering plus wired LAN access plus full control.

Here are some relevant links for doing that:

https://github.com/morrownr/USB-WiFi http://www.linuxintro.org/wiki/Set_up_a_hotspot_with_Linux https://www.how2shout.com/how-to/2-ways-to-create-wifi-hotspot-in-ubuntu-20-04-lts-focal-fossa.html https://developer.toradex.com/knowledge-base/wi-fi-access-point-mode https://www.cyberciti.biz/faq/debian-ubuntu-linux-setting-wireless-access-point/ https://wiki.lm-technologies.com/linux-wifi-access-point-wireless-ap/

In combination With Other Links As a Failover WAN-Router

The usb tethered mobile phone can be considered an additional WAN link for an existing router.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published