openvpn-install
openvpn-install copied to clipboard
Does not work when Floating IP is used on Digital Ocean
When the script is run for the first time, it will automatically detect the Public IP.
But when the Floating IP is mentioned instead of the default Public IP, the set up is not working. That is, the OpenVPN client is not able to establish a connection with the server.
Use domain instead of IP. When floating IP is being used, just update DNS record.
Alright, I managed to get the DO floating ip working (thanks to this and some play around)!
So here's how:
- Make sure you have floating ip enabled on the droplet with
curl -s http://169.254.169.254/metadata/v1/floating_ip/ipv4/active
(if so, will returntrue
) - Get your anchor-ip with
curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address
- Get your floating-ip with
curl -s http://169.254.169.254/metadata/v1/floating_ip/ipv4/ip_address
- Run
./openvpn-install.sh
(uninstall first if you have it installed already) and follow the process providing the anchor-ip for all instances when the ip of the vpn is asked for - Comment out/replace line 1 (
iptables -t nat -I POSTROUTING (...)
) of both/etc/iptables/rm-openvpn-rules.sh
and/etc/iptables/add-openvpn-rules.sh
to use insteadiptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source anchor-ip
- (In my case I had some leftover iptables nat rules from previous experiments, so I had to flush the whole thing with
iptables -t nat -F
) - Add
local anchor-ip
in a new line in/etc/openvpn/server.conf
- Restart the server
- Update in your local machine .ovpn config to connect to the vpn using the floating-ip (replacing the line
remote (...)
withremote floating-ip 1194
) - That's it! Now if you connect to the vpn and hit https://api.ipify.org/ you should see the floating-ip
Thanks a lot.
In step 4, when it asks you for the public IP for the first time, you should provide the anchor-ip. From this, the script will sense/detect that the IP is behind NAT, so it will ask you for the real public IP in the next question; and, this time you supply it with the floating-ip. Doing it this way will save you from modifying the .ovpn
file in step 9, as it will already contain the correct configuration for remote. i,e. remote floating-ip 1194
. I have tested it and it works.