Assuming your cellular provider has you on an IPv4 network, you can share your cellular connection via USB tethering by setting the USB connection to shared and adding a NAT masquerade rule.
I found it easiest to modify the “ethernet-usb0” connection that is created when you attach the phone to a PC. Attach the phone to your PC, then from the terminal enter…
nmcli con mod ethernet-usb0 ipv4.method shared
Then re-activate the connection, you can try nmcli con up ethernet-usb0
, but you will probably have to physically disconnect then reconnect the phone to the PC at this point for the PC to pick up an IP address from the phone.
The phone will provide the PC with an IP address in the default 10.42.0.0/24 range, do double check that it does not overlap with the subnet your cellular providers network.
You also need to add a NAT masquerade rule, this should be done automatically by NetworkManager when setting the shared connection but for what ever reason that is not the case on the phone at the moment.
Assuming you are using the default 10.42.0.0/24 IP range, from the terminal enter…
sudo iptables-legacy -t nat -A POSTROUTING -s 10.42.0.0/24 ! -d 10.42.0.0/24 -o wwan0 -j MASQUERADE
This would apply the masquerade rule on the modem interface only, the -o wwan0
should be omitted for the rule to be applied to all interfaces which would most likely be desired.
As far as I can tell at the moment, IPv6 is a little bit more of a game and requires a few workarounds, I haven’t needed it myself so I haven’t looked to deep into it.
To get the phone back to default state, you just have to set the ethernet-usb0 connection back to auto…
nmcli con mod ethernet-usb0 ipv4.method auto
And remove the NAT masquerade rule, assuming you had no other rules in place…
sudo iptables-legacy -t nat -D POSTROUTING 1