I have two sites. Site 1 has a router with a public IP A.B.C.D as well as a private range The router also occupies the private IP Site 2 is a single host with a public IP X.Y.Z.W.

The problem is that site 2 is behind a firewall not under my control. As a result, site 2 can access site 1 at A.B.C.D but site 1 cannot access site 2 directly.

To work around the limitation, I configured site 2 to connect to site 1's router over an OpenVPN tunnel, and using iproute2 source policy routing to redirect traffic from the private range (except the router itself) to X.Y.Z.W to go through the tunnel. For example, I have to use the following command on the router at site 1

ip rule add from to X.Y.Z.W lookup vpn

to redirect traffic from the block to X.Y.Z.W to consult the routing table vpn in which the default gate is the OpenVPN endpoint. I have to use source policy routing to exclude the router (which is at, otherwise the VPN traffic would not be routed back to X.Y.Z.W correctly.

So far everything is working fine, but I'm not very happy with the source policy routing because it requires me to change the ip rule every time private range is changed, or more sub-blocks is added.

I'm wondering if there is any easier way to make X.Y.Z.W available to site 1's private range without using source policy routing?

1 Answer 1


After Site 2 opens the VPN tunnel it should be assigned an IP, e.g., and a route should appear on the router (acting as VPN Server) pointing to this IP.

You can use Destination NAT instead of policy routing, by matching all traffic whose destination is the public IP X.Y.Z.W, and that are incoming only from the router LAN Interface, and NATTing the destination to

This will route all traffic going to Site 2 through the VPN tunnel automatically, and it will hit the public host.

  • Thanks for the answer! The problem is with destination NAT the underlying VPN traffic to X.Y.Z.W will be (incorrectly) routed via the VPN tunnel too, sorta creating a loop that never works… That's why I ended up with source policy routing in the first place.
    – Rio
    Jan 7, 2014 at 2:22
  • The tunnel physical endpoints are ABCD and XYZW, right ? should not be sending traffic to the public host XYZW, right ? I have edited my answer to say only incoming LAN Traffic to be NATTed.
    – aseaudi
    Jan 7, 2014 at 10:48
  • I see what you meant now. What command should I use to match the traffic only from the LAN interface? ip route?
    – Rio
    Jan 10, 2014 at 3:18
  • try "iptables -t nat -A PREROUTING -p tcp -s -j DNAT --to-destination"
    – aseaudi
    Jan 10, 2014 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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