I have an OpenVPN tun0

There is an interface on the server eth1 for

I would like to route the OpenVPN connections to access the network.

I can connect to the VPN from my client, I get an ip of but on the server it will not route the traffic from tun0 to eth1. When I do a tracerout on the client for it shows going out towards but stops right there.

If I try to ping on the server from tun0 I get no response. ping -I tun0

Anyone can please help me what do I need to add on the server to get the routing and the NAT working?

Thank you!


You need to enable IP forwarding, then specify where you want forwarding to occur

sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -i tun0 -s -j MASQUERADE

See this answer for complete details and instructions on how to make this permanent / on boot:

How to forward packets between two interfaces?

This will allow devices inside that already know (or assume) that is behind to reach any device in via a Network Address Translation (NAT) of Ergo, devices in will think is pinging them when in reality the real source is further back.

To make the other direction work, i.e. ping from to, you need to do something completely different. Your devices or your router in in must know that is behind You'd then use similar iptables rules to allow such routing on your bridge machine. Note that NAT isn't specified here.

# Run on each device in, or set up a static route on your router of the same:
route add -net netmask gw

# Run on your bridge machine:
iptables -A FORWARD -i eth1 -o tun0 -j ACCEPT
iptables -A FORWARD -i tun0 -o eth1 -j ACCEPT
  • I do not think a NAT is needed. Enabling IP forwarding and setting proper routes should be sufficient. – dirdi Oct 15 '19 at 0:19
  • iptables v1.8.2 (nf_tables): Can't use -i with POSTROUTING – Tibby Oct 15 '19 at 1:48
  • You can drop the -i tun0, since -s is synonymous with tun0 anyways. – Andy Oct 15 '19 at 19:01

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.