Try   HackMD

Share USB tethered phone to Raspberry Pi 4 LAN port

Raspberry Pi Setup

Follow the instructions on Raspberry Pi:
Take into consideration that we imagined the phone virtual interface of the Raspberry Pi is usb0.

  1. Set a static IP address to the eth0 which would be router's clients' default gateway. To do it, there is plenty of procedure:

    Put lines below to in /etc/dhcpcd.conf:

    ​​​​interface eth0
    ​​​​static ip_address=192.168.100.254/24
    
  2. Install the DHCP server package:

    ​​​​sudo apt-get -y install dnsmasq
    
  3. Configure the DHCP server. At first, create a backup of the config file:

    ​​​​sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak  
    

    Put lines below to /etc/dnsmasq.conf:

    ​​​​interface=eth0 
    ​​​​listen-address=192.168.100.254
    ​​​​# bind-interfaces 
    ​​​​server=8.8.8.8
    ​​​​domain-needed
    ​​​​bogus-priv
    ​​​​dhcp-range=192.168.100.10,192.168.100.100,24h  
    
  4. Enable IP Forwarding to forward router's clientsi packets:

    In /etc/sysctl.conf, uncomment this line:

    ​​​​net.ipv4.ip_forward=1 
    
  5. Follow these commands for the firewall to allow forwarding between interfaces:

    ​​​​sudo iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
    ​​​​sudo iptables -A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    ​​​​sudo iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT  
    
    ​​​​sh -c "iptables-save > /etc/iptables.ipv4.nat"  
    
  6. Open rc.local to add command for restoring firewall configuration on each RPi startup:

    In /etc/rc.local, add this line before Exit 0:

    ​​​​iptables-restore < /etc/iptables.ipv4.nat
    
  7. Make sure that usb0 is on DHCP mode to get ip address from the phone.

    Now, you have configured Raspberry Pi as a bridge for the router to the phone.

Router configuration

In this step, you must disable any static routes and disable the DHCP server of the router because the DHCP requests of the clients must forward to the RPi interface.

Reference