I assume the RasPi is connected to the internet with interface ppp0 and get the ip address for it from the USB data modem. To eth0 you have to give a static ip address. I use 192.168.50.2 for example.
Example for this setup:
wired USB wan
local WiFi-router <──────~> (eth0)RPi(ppp0) <───> modem <---> INTERNET
/ \
192.168.50.2 (dhcp
from modem)
You should have both interfaces available each with its own ip address. The ip addresses should be on different subnets, for example eth0 with 192.168.50.2 and ppp0 with 10.1.1.180. Now you have to enable routing so that data packages are transmitted between the both interfaces. To enable this you have to turn on ip forwarding
. There are several ways to do it. I don't know what configuration you are using. You can enable it direct to the kernel with:
rpi ~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Or you can uncomment this in /etc/sysctl.conf
and reboot:
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
Or with systemd-networkd
you can add IPForward=yes
to the [Network]
section in one of your /etc/systemd/network/*.network
files.
Now you have to fake the modem to tell it that all data packages are comming from the RasPi and not from the underlaying local network. We do it with a NAT (Network Address Translation). Execute this command:
rpi ~$ sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
The last step now is to tell all clients on your local network that the internet router is the RasPi. You have to configure the DHCP server on the local WiFi router to give the ip address 192.168.50.2 to all clients as internet router ip address (default gateway). If this is a problem then you can disable the DHCP server on the local WiFi router and setup one on the RasPi.