使用 IPTABLES 限制 MySQL 3306 端口

2022-01-13 00:00:00 firewall security centos mysql iptables

如何阻止每个人的 mysql 端口 3306,但允许它用于特定 IP?这是我目前所做的:

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

推荐答案

你需要多个规则来做到这一点.在大多数情况下,连接会发生什么取决于它匹配的第一条规则.所以,首先我们接受我们的朋友连接,其次,我们放弃任何其他人.瞧!

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

相关文章