Question

What iptables entries for secure MySQL?

I want to add Ubuntu iptables entries so only the following can access MySQL server on my droplet:

  • my Rails app on that same droplet should be able to get, post, update, delete, etc data on MySQL on that same droplet
  • I should be able to SSH to my droplet and use MySQL.

What iptables entries will make these secure restrictions possible?

Thanks in advance!


Submit an answer

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.

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.

Make sure that in <strong>/etc/mysql/my.cnf</strong> you have the following entry: <br><pre>bind-address = 127.0.0.1</pre>

MySQL listens on the loopback interface by default so outer access to port 3306 will not be allowed (it will timeout as there’s nothing listening publicly on port 3306). <br> <br>You don’t have to set up any iptables rules as it’s pretty much secure by default as long as there are no users that are able to connect without a password.

Yes, everything is on the same droplet.