networking – Use Middle Server IP Address to Connect to Main OpenVPN Server

networkingopenvpnserver

My main server ip address that i installed openvpn server on, is blocked in my country.
that means i cant connect to openvpn directly. so I bought another server. i want to use this second server to connect my main openvpn. every methods that is fast is fine for me.

both servers are ubunutu 20.04

Best Answer

You may use iptables for port forwarding The CLI Syntax looks like

iptables -t nat -A PREROUTING -p tcp --dport <PORT> -j DNAT --to-destination <main-Server-IP>

check man page for details.

You should install the packages iptables and iptables-persistent. For a persistent configuration (load at reboot) you need to save your configuration with

iptables-save > /etc/iptables/rules.v4

I guess your 2nd server does have "only” one interface. IP-Forwarding must be enabled. Add the line

net.ipv4.ip_forward=1

to

/etc/sysctl.conf 

A reboot is needed.

Iptables is a very powerful tool - be careful. If you misconfigure if you may lose access to the server.

Related Question