I have a way but a little bit tricky. You are going to need:
- Android with the "USB-PC internet share" option (not the classic USB tethering)
- iptables or nftables (for masquerade/SNAT)
- a dns server on your linux (dnsmasq is quick to set up)
1/ On you android device: got to Settings >> Network connection >> Tethering and portable hotspot >> USB-PC internet share . Say ok or choose any OS suggested (usually different Windows versions), it does not matter as long as the functionnality is enabled.
=> now your smartphone is going to immediately try to connect to internet, but your Linux system is not yet ready.
You will need to retrieve the folling information: the subnet and the default gateway you smartphone is going to use. This can be done with tcpdump
2/ On your Linux: use tcpdump to capture traffic from the USB network interface (enabled when USB PC internet share is activated from android). You are going to see a lot of whohas XXXX. This ip address is the default gateway you android is trying to reach.
add this ip address and the correct subnetmask to the tethering interface (sudo ip address add XXXXX dev XXXX) or use network manager
3/ enable masquerading with iptables:
sudo iptables -A POSTROUTING -o usb_thethering_interface -j MASQUERADE
4/ make sure you dns server is working on the Linux.
Should work fine