Configuring IPtables on private network


I have a Wordpress web app on a droplet in nyc2 and a MySQL server in the same DC. Both have private networking enabled and the web app works great with the backend DB server.

I know the DB server can’t be reached from outside the DC, but I want to make sure that internally only my web app can access the MySQL instance on port 3306 and that I can access the VPS from my local machine. I’m not sure if I have setup the iptables 100% correctly, so I’m looking for confirmation.

Below is my current iptables config where xxx is the external IP address of my local machine and yyy is the private network address of the MySQL instance.

If someone could cast an eye over that config I’d be very grateful.

Many thanks in advance.

:INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [113:20356] -A INPUT -i lo -j ACCEPT -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -s --dport 22 -j ACCEPT -A INPUT -p tcp -m tcp -s yyy.yyy.yyy.yyy/32 --dport 3306 -j ACCEPT -A INPUT -j DROP COMMIT

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.

Thanks Kamal, will do. I’ve added a few more rules too. <br> <br># Generated by iptables-save v1.4.12 on Mon Dec 30 00:33:13 2013 <br>*filter <br>:INPUT DROP [0:0] <br>:FORWARD ACCEPT [0:0] <br>:OUTPUT ACCEPT [29:5272] <br>-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT <br>-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP <br>-A INPUT -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -$ <br>-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,$ <br>-A INPUT -f -j DROP <br>-A INPUT -i lo -j ACCEPT <br>-A INPUT -s -p tcp -m tcp --dport 22 -j ACCEPT <br>-A INPUT -s yyy.yyy.yyy.yyy/32 -p tcp -m tcp --dport 3306 -j ACCEPT <br>-A INPUT -P DROP <br>COMMIT <br>

Looks fine to me. <br> <br>One thing I would suggest is deleting the rule <code>-A INPUT -j DROP </code>: <br><pre>iptables -D INPUT -j DROP</pre> <br>And setting <code>INPUT</code>'s default policy to <code>DROP</code> instead: <br><pre>iptables -P INPUT DROP</pre>