我在我的VPS上运行CentOS,并试图远程访问我的MySQL数据库。 所以我使用这个命令给我的iptables添加了一行:
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
但我无法访问我的MySQL数据库。 当我做一个端口扫描与nmap这是结果:
>nmap -p 3306 xxxx >3306/tcp filtered mysql
所以stat不是OPEN 。 这是VPS上的所有input规则。 有一条线(已经在那里)持有REJECT 。 是阻止到端口3306的stream量?
Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:smtp ACCEPT udp -- anywhere anywhere state NEW udp dpt:domain ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:domain ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:pop3 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:imap ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:submission ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:imaps ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:pop3s ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:EtherNet/IP-1 ACCEPT tcp -- anywhere anywhere state NEW tcp dpts:35000:35999 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited ACCEPT tcp -- anywhere anywhere tcp dpt:mysql ACCEPT tcp -- anywhere anywhere tcp dpt:mysql
提前致谢!
my.cnf文件:
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 bind-address=xxxx [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
编辑:我看着你的iptables输出更彻底,并注意到你有一些问题。
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited ACCEPT tcp -- anywhere anywhere tcp dpt:mysql ACCEPT tcp -- anywhere anywhere tcp dpt:mysql
在规则明确允许MySQL的stream量有机会匹配之前,您拒绝所有stream量。 您需要重新排列这些规则。
老答案:
您的MySQL服务器很可能不会主动侦听远程连接。
命令'ss -ln | grep 3306'可能不会返回任何结果。
检查你的MySQLconfiguration文件中的关键字skip-networking和bind-address。 如果configuration中存在跳过networking连接,请将其注释掉或将其删除。 确保bind-address被设置为0.0.0.0('通配符')或系统IP地址。 重新启动MySQL以应用configuration更改。
您将需要确保您没有任何账户可以通过空白或琐碎的密码进入世界。 除了MySQL用户和数据库ACL之外,强烈build议限制远程访问MySQL端口。
这应该是一个评论不是一个喉咙,我没有足够的代表。
自从
3306 / tcp 过滤 mysql
您的防火墙可能有问题。 如果由于没有绑定到networking,mysql不接受连接到3306,它应该被closures
tcpdump是你的朋友来debugging的问题,试图检查数据包是否实际到达
只是指出,过滤状态往往与防火墙问题相关联,并closures与实际服务不绑定
netfilter防火墙中的规则会按顺序检查,直到第一次匹配。
-a切换到iptables会在现有configuration结束时添加新的规则。
您现有的configuration将打开多个端口,并以匹配的规则结束,并拒绝之前未打开的所有内容。 然后你添加了MySQL端口。
永远不会达到该规则,并且MySQL端口保持closures状态。
您应该使用-I开关到iptables在防火墙configuration的开始处插入新规则。