I want to forward a port from my raspberry Pi to a server reachable through a VPN. I also want to be able to see the client IP from the server.
The setup looks something like this:
LAN VPN Real Client | <----> | Raspberry Pi | <----> |Server | 192.168.1.7 | |192.168.1.8 / 10.8.0.2 | | 10.8.0.1 | ______________| |_________________________| |____________|
So the client should be able to e.g. connect through HTTP on port 80 to the raspberry pi on 192.168.1.8. There, the packet should be forwarded through the VPN to the server (10.8.0.1). The server should see that the connection comes from 192.168.1.7.
How can I do something like this? I already tried DNAT:
iptables -A PREROUTING -t nat -i eth0 -d 192.168.1.8 -p tcp --dport 80 -j DNAT --to-destination 10.8.0.1:80 iptables -A FORWARD -p tcp -d 192.168.1.8 --dport 80 -j ACCEPT
But that doesn't work. I only get
Failed to connect to 192.168.1.8 port 80: Connection refused