Your Raspberry Pi has two interfaces: eth0 (172.16.0.1)
and wlan0 (192.168.1.2)
each with an ip address from another subnet. This is a very good condition to make your raspi a router. First you have to enable ip forwarding
. There are several ways to do it. You can enable it direct to the kernel with:
rpi ~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Or you can uncomment it in /etc/sysctl.conf
and reboot:
rpi ~$ grep -B 1 'ipv4.ip_forward' /etc/sysctl.conf
# 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 your /etc/systemd/network/eth0.network
file.
Then you have to set a static route in your internet router so it can find the route over the raspi to your pc. On most internet router you can set a static route but how to do that varies from model to model. It's up to you to find it out. On a Raspberry Pi it would look like this (don't set it on your Raspi router!)
rpi ~$ sudo ip route add 172.16.0.0/24 via 192.168.1.2 dev wlanX
That means for the internet router: "send all packets belonging to subnet 172.16.0.0/24
(destination network) to the next router on my subnet, your raspi-router 192.168.1.2
(gateway). It knows where to go on."
For troubleshooting and reference you can look at Using the Raspberry Pi as a Router.