Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restricting MySQL 3306 port with IPTABLES

How to block mysql port 3306 for everybody, but allow it for a specific IP? This is what I currently do:

iptables -I INPUT 1 -p tcp --dport 3306 -j ACCEPT
like image 488
Putra Fajar Hasanuddin Avatar asked Mar 10 '14 19:03

Putra Fajar Hasanuddin


1 Answers

You need multiple rules to do that. In most cases, what will happen with a connection depends on the first rule, which it matches. So, first we accept our friends connection, second, we drop anybody other. Voila!

iptables -I INPUT 1 -p tcp -s 1.2.3.4 --dport 3306 -j ACCEPT
iptables -I INPUT 2 -p tcp --dport 3306 -j DROP
like image 93
peterh Avatar answered Nov 10 '22 00:11

peterh