0

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

0

You need to use normal IP routing on your Raspberry Pi instead of any NAT.

This requires that you set up proper routing tables at gateway devices so that they know where the packets to the other network need to be sent to.

For example, you need to add a route to the server where you tell that 192.168.1.0/24 network needs to be routed via 10.8.0.2.

On the client side such additions might not be necessary, if Raspberry Pi is the default gateway of Real Client. If the default gateway is something else, then you need to add a route to 10.8.0.0/24 via 192.168.1.8.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.