Route all OpenVPN connections through Floating IP

I used this tutorial to setup an OpenVPN server on a Debian droplet: I’ve also added a floating IP to the droplet, and now I’d like all connections to the VPN to appear as if they are coming from the floating IP, and NOT the primary IP of the server

When SSHing into the server, I managed to use the floating IP with a curl call:

curl --interface [ACNHOR-IP]

This worked - it gave the floating IP as response

How can it be done? I saw this tutorial, but not sure what are the correct values, since the netstat -anr doesn’t give a similar output (I have only one record: eth0 )

Thanks in advance

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

I managed to get both incoming connection and outgoing to occur via the floating ip. In /etc/openvpn/server.conf i added a line local floating-local-ip( after which i restarted openvpn with service openvpn restart. After that i have removed/added some iptables rules like below:

iptables -t nat -D POSTROUTING -s ! -d -j SNAT --to-source droplet-ip
iptables -t nat -D POSTROUTING -s -o eth0 -j SNAT --to-source
iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
root@ghost-s-1vcpu-1gb-fra1-01:~# netstat -anr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface         UG        0 0          0 eth0   U         0 0          0 tun0     U         0 0          0 eth0   U         0 0          0 eth0
root@ghost-s-1vcpu-1gb-fra1-01:~# netstat -ltnup | grep 1194
udp    12288      0*                           829/openvpn

In my user.ovpn i have replaced remote droplet-ip 1194 with remote floating-ip 1194

All of the above was on a clean Ubuntu 18.04 install.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


Maybe this will help you with your task.