As you mentioned, it's easy to do it on Windows OS, however, it's a bit different on Raspberry Pi and Linux.
I have looked up guides but they all seem to mention using the pi as a
DHCP server, not too sure what I want/need this.
In your situation, the phone is a device that has an internet connection. Obviously, the devices/clients must connect to your phone anyhow.
So, as you did, you must connect the phone to the RPi, and, connect RPi to the router. In this way, the router's clients connected to your phone logically with the RPi as a bridge.
What's the problem? The clients connected logically by hardware sight but they didn't connect to the phone by software sight and OSI model.
The clients connected to the router, in the router, there is a DHCP server which the gateway IP address has configured is the router's IP address. I mean, the gateway of the clients is the router. Therefore, the clients send their outside packet (the destination of the packets is not in the local LAN) to the router and the router has no internet connectivity hence the clients have no, too.
To solve this problem, you need to route clients' outside packets to the phone. I mean,
the phone must be the client's gateway.
The problem here is, you can not connect the phone directly to the router, by that, we set the RPi as a gateway and config RPi to forward clients' outside packets to the phone virtual interface.
Follow the instructions on Raspberry Pi:
Take into consideration that we imagined the phone virtual interface of the Raspberry Pi is eth1
.
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:
sudo nano /etc/dhcpcd.conf
Put lines below to this file:
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
sudo nano /etc/dnsmasq.conf
Put lines below to this file:
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:
nano /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 eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth1 -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:
sudo nano /etc/rc.local
Add this line before Exit 0:
iptables-restore < /etc/iptables.ipv4.nat
7. Make sure that eth1
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.