USB Tethering

From postmarketOS Wiki
Note postmarketOS is one of a few mobile phone software that allow you to use USB Tethering from USB to Modem; and from USB to WiFi; and possibly from USB to USB (using an OTG adapter). This feature is also useful to turn an unused device into a WiFi adapter.

This is a guide for using the mobile data or wifi of a postmarketOS device through USB on your host device. For the inverse see the USB Internet page if you need to use the USB connection to get internet from your host into the postmarketOS device.

Automatically (SXMO)

Open menu "Networks", select menu "Add a USB Hotspot", you'll be prompt to set a profile name (e.g. USB Tethering).

Activate the newly created interface (i.e. USB Tethering) by selecting it.

Your computer should receive internet traffic from your postmarketOS device automatically.

Manually

If you don't use SXMO, you should follow the following instructions. To make USB Tethering to work, you'll have to repeat these instructions every time your system reboots.

Recommended

Since version 23.06, a network profile "USB Networking" has been added in order to facilitate tethering on all variants of postmarketOS.

This is the simple and non-intrusive manner to enable USB Tethering.

Once USB cable is connected, execute the following commands.

$ nmcli c modify '83bd1823-feca-4c2b-9205-4b83dc792e1f' ipv4.method shared
$ nmcli d reapply usb0

If you want to restore the original behavior, use the manual method:

$ nmcli c modify '83bd1823-feca-4c2b-9205-4b83dc792e1f' ipv4.method manual
$ nmcli d reapply usb0

In case the above solution doesn't work, please send us a report on the issue tracker.

Using Root

On the postmarketOS device

On the postmarketOS device side, the firewall needs to be configured to perform NAT between the USB interface and its default gateway. The default gateway can be either the WiFi or the modem in the device.

First enable ip forwarding between the interfaces:

# sysctl net.ipv4.ip_forward=1

Then adjust the firewall configuration to NAT between the USB interface and the other interfaces

# nft add table inet nat
# nft 'add chain inet nat postrouting { type nat hook postrouting priority 100 ; }'
# nft add rule inet nat postrouting iifname "usb*" masquerade

The default nftables configuration in postmarketOS already has the other rules setup to make USB tethering work.

On the host side

Plug the postmarketOS device into your PC or laptop and run a DHCP client against the USB interface that shows up. It's also possible to use a static IP configuration.

address 172.16.42.2
netmask 255.255.255.0
gateway 172.16.42.1

If your host has automatically done DHCP on the USB interfaces, as is common on most Linux distributions. The only thing required is setting the default gateway to the USB interface since the DHCP server on the postmarketOS device does not set the default gateway.

remove the existing default route if you have one
# ip route del default

Add a default route through the postmarketOS device
# ip route add default via 172.16.42.1

Troubleshoot

To restore the default USB Networking interface, execute the following command.

# rm /etc/NetworkManager/system-connections/83bd1823-feca-4c2b-9205-4b83dc792e1f.nmmeta
$ nmcli connection reload


See also