Follow the instructions on Raspberry Pi:
Take into consideration that we imagined the phone virtual interface of the Raspberry Pi is usb0
.
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
Install the DHCP server package:
sudo apt-get -y install dnsmasq
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
Enable IP Forwarding to forward router's clientsi packets:
In /etc/sysctl.conf
, uncomment this line:
net.ipv4.ip_forward=1
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"
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
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.
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.