Allow traffic from Floating IP only

May 27, 2019 357 views
Firewall

I would like to create some firewall rules in order to allow traffic only from my Floating IP. I would like to block all incoming requests coming over my public IP. Is it possible to do so?

1 comment
  • I would suspect if you added only your Floating IP to your Firewall Inbound rules, this would do the trick in theory.

2 Answers

Thanks to @jasonjpeters and @pjha I understood that it is indeed possible and started experimenting then I accidentally figured it out.

If you would like to deny all traffic coming to your public IP and only allow connections over your Floating IP, you need to find your droplet’s Anchor IP and set your firewall to allow connections from it.

Find out your Anchor IP:
curl -s 169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address

After that, you need to create your rules with ufw like this:

ufw allow from any to [your-anchor-ip] port [some-port]

with this configuration your droplet will accept connections to some port if they are coming over with your Floating IP. All direct connections to your droplet will be dropped/refused depending your configuration. If you would like to, for example, allow HTTP/S connections over your Floating IP but restrict SSH to only your real public ip, then it is something like that:

ufw allow from any to [your-anchor-ip] port 80
ufw allow from any to [your-anchor-ip] port 443
ufw allow from any to [your-real-ip] port 22

Hey there!

You can create an inbound rule for the specific port allowing that Floating IP as the inbound source to restrict all the traffic except that Floating IP.

Let me know if you have any further questions.

Regards,
Prakash Jha
Developer Support

Have another answer? Share your knowledge.