我们有一个Centos 6 VPS,最近被迁移到一个新的机器在同一个networking托pipe公司。 它运行WHM / cPanel并安装了csf / lfd。 csf是build立在大多数香草configuration。 我不是iptables专家,csf以前也没有让我失望。 如果一个端口不在TCP_IN列表中,它应该被iptables在防火墙上阻塞。
我的问题是我可以telnet到端口3306从外部主机,但我认为iptables应该阻止3306由于csf的规则。 由于这个开放的港口,我们现在没有进行安全检查。 (这个输出被混淆以保护无辜:www.ourhost.com是带有防火墙问题的主机)
[root@nickfenwick log]# telnet www.ourhost.com 3306 Trying 158.255.45.107... Connected to www.ourhost.com. Escape character is '^]'. HHost 'nickfenwick.com' is not allowed to connect to this MySQL serverConnection closed by foreign host.
所以连接build立了,MySQL由于configuration的原因拒绝连接。 我需要防火墙级别的networking连接在到达MySQL之前被拒绝。
使用WHM的csfnetworking用户界面我可以看到“防火墙configuration”包含一个相当明智的TCP_IN行:
TCP_IN: 20,21,22,25,53,80,110,143,222,443,465,587,993,995,2077,2078,2082,2083,2086,2087,2095,2096,8080
(让我们忽略我现在可以修改一下,我担心的是3306 没有在列表中列出)
当csf重新启动时,它会logging通常的输出,因为它设置了iptables规则,例如看起来像阻塞所有stream量,然后允许特定的端口,如SSH在22:
[cut] DROP all opt -- in * out * 0.0.0.0/0 -> 0.0.0.0/0 [cut] ACCEPT tcp opt -- in !lo out * 0.0.0.0/0 -> 0.0.0.0/0 state NEW tcp dpt:22 [cut]
我可以看到,iptables正在运行, service iptables status返回一长串防火墙规则。
这是我的service iptables status Chain INPUT部分,希望这足以显示如何configuration防火墙。
Table: filter Chain INPUT (policy DROP) num target prot opt source destination 1 acctboth all -- 0.0.0.0/0 0.0.0.0/0 2 ACCEPT tcp -- 217.112.88.10 0.0.0.0/0 tcp dpt:53 3 ACCEPT udp -- 217.112.88.10 0.0.0.0/0 udp dpt:53 4 ACCEPT tcp -- 217.112.88.10 0.0.0.0/0 tcp spt:53 5 ACCEPT udp -- 217.112.88.10 0.0.0.0/0 udp spt:53 6 ACCEPT tcp -- 8.8.4.4 0.0.0.0/0 tcp dpt:53 7 ACCEPT udp -- 8.8.4.4 0.0.0.0/0 udp dpt:53 8 ACCEPT tcp -- 8.8.4.4 0.0.0.0/0 tcp spt:53 9 ACCEPT udp -- 8.8.4.4 0.0.0.0/0 udp spt:53 10 ACCEPT tcp -- 8.8.8.8 0.0.0.0/0 tcp dpt:53 11 ACCEPT udp -- 8.8.8.8 0.0.0.0/0 udp dpt:53 12 ACCEPT tcp -- 8.8.8.8 0.0.0.0/0 tcp spt:53 13 ACCEPT udp -- 8.8.8.8 0.0.0.0/0 udp spt:53 14 LOCALINPUT all -- 0.0.0.0/0 0.0.0.0/0 15 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 16 INVALID tcp -- 0.0.0.0/0 0.0.0.0/0 17 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 18 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:20 19 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:21 20 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 21 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:25 22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:53 23 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80 24 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:110 25 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:143 26 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:222 27 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443 28 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:465 29 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:587 30 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:993 31 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:995 32 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2077 33 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2078 34 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2082 35 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2083 36 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2086 37 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2087 38 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2095 39 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2096 40 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8080 41 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:20 42 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:21 43 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:53 44 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:222 45 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:8080 46 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 8 47 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 0 48 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 11 49 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 3 50 LOGDROPIN all -- 0.0.0.0/0 0.0.0.0/0
接下来要检查的是什么?
我不确定LOGDROPIN或者acctboth是怎么定义的,但是这里是我如何去做的。
如果您不需要MySQL来接受远程连接,那么我会先将MySQLconfiguration更改为绑定到127.0.0.1而不是0.0.0.0或您的IP地址。 这将限制所有的mysql访问本地主机,我相信是新的MySQL安装默认。 (这不能回答你的IPTABLES问题,但应该可以做到。)
为了追踪你的IPTABLES问题,我build议使用IPTABLES TRACEfunction,它会告诉你究竟哪些规则正在被遍历。 有一个漂亮的数据包stream程图 。 从这里你可以看到原始表具有内置的OUTPUT和PREROUTING链。 这也假设你正在使用一个> 2.6.23内核,或者用适当的选项编译你自己的内核。
你会添加像这样的东西:
iptables -t raw -A OUTPUT -p tcp --dport 3306 -j TRACE iptables -t raw -A PREROUTING -p --dport 3306 tcp -j TRACE
让内核跟踪mysql连接。 您应该能够看到日志中的数据包通过哪些特定的规则。 如果这个盒子已经有通过这个端口的stream量,你可能还想在上面的规则中过滤你的IP地址,以减less噪音。
另外,这里是跟踪iptables的优秀post。
希望这可以帮助!