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.
ip route
. I don't use normal network configs though, so you'll have to wait for someone to come along with that knowledge. In the meantime I'd recommend you explain the context of why you want to do this, since it will help clarify things. Some people won't risk wasting their time providing answers to ambiguous questions only to find out "Oh, that's not what I meant...", etc. And they may not bother trying to get the information out of you if you cannot be bothered to provide it in the first place ;)