Block all IP access to database droplet, except for one

Hi, I have an droplet which is running a NGINX and I wish to block my another droplet running Mongo to be visible exclusively for the NGINX one. Could you help me? Both are running Ubuntu.


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

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.

Using ufw, first you need to deny all traffic to your database port

sudo ufw deny 3306/tcp

then allow your IP to your server:

sudo ufw allow from Your.IP.Address to any port 3306 proto tcp