我在 Host DB 上设置的 iptables
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpts:60000:61000
ACCEPT tcp -- li413-134.members.linode.com anywhere tcp dpt:mysql
ACCEPT tcp -- server1.electronixcraft.com anywhere tcp dpt:mysql
REJECT all -- anywhere 127.0.0.0/8 reject-with icmp-port-unreachable
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT icmp -- anywhere anywhere
LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix "iptables denied: "
DROP all -- anywhere anywhere
Chain FORWARD (policy ACCEPT)
target prot opt source destination
DROP all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
按照上面的信息来说,除开打开 http/https/mysql 就应该没有其他端口,服务器监听的端口为:
root@db:/var/lib/mysql# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
Active UNIX domain sockets (only servers)
....
可是通过 netstat 查看建立链接的 tcp 的时候看到
root@db# netstat -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 db:mysql server1.electroni:34875 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:35233 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34879 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34890 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34891 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34885 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34869 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34873 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:35234 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34886 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34889 ESTABLISHED
tcp 0 0 db:mysql server1.electroni:34881 ESTABLISHED
我能够猜到这些 tcp 链接是应用服务器链接到当前服务器 3306 端口访问 MySQL 建立起来的,可这个不是与 iptables 中的设置想违背了吗?在 34xxx 端口上的 tcp 应该会被 DROP 掉,怎么又链接成功了呢?
还有求推荐这方面有什么书可以参考 - -|| 这问题把我搞糊涂了。