Centos – Port forwarding through OpenVPN server

centoscsfforwardingopenvpn

Here's my scenario:

  1. Remote OpenVPN server v2.3.2, 1 public IP, CentOS 6.4, 2.6.32-042stab079.6
  2. Tunnelblick (OpenVPN client)

What I want to do is route all the client traffic through the VPN – and I accomplished that. I'm however experiencing problems in port forwarding clients port through the VPN.

e.g. I need port 5780 for hosting a game match on the client, but I'm behind the VPN, therefore the VPN gets the packets. I'd like the VPN to forward every packet on port 5780 to my client IP address.

How can I do so?
Please note that the remote server runs CSF+LFD.

Best Answer

You should NAT the packets to your client via iptables:

iptables -t nat -A PREROUTING -p tcp --dport 5780 -i $external_Interface -j DNAT --to-destination $VPN_client_IP
iptables -t nat -A POSTROUTING -o $vpn_Interface -j MASQUERADE

Update: You will also need a FORWARD rule in place if your FORWARD policy is set to DROP. As you can see here, the FORWARD takes place between the PREROUTING and POSTROUTING, therefore the DNAT is already done. This should work:

iptables -I FORWARD -i $external_Interface -d $VPN_client_IP --dport $port -j ACCEPT