在一个 CentOS 6.5 的机器上使用 docker,默认已设置了一定的 iptables 规则。
启动容器时用-p 9123:3000 指定了端口映射。
目前在 iptables 启用的状态下不论是从外网机器还是 host 本机上,都无法从 9123 端口拿到数据。如果执行sudo service iptables stop
后,则可以正常获得数据。
不知道应该怎么设置 iptables 才能访问 9123 端口?
使用如下命令查看 iptables 规则
sudo service iptables status
输出结果是
Table: filter
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT 41 -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255
3 ACCEPT all -- 127.0.0.1 127.0.0.1
4 ACCEPT all -- 127.0.0.1 127.0.0.1
5 ACCEPT all -- 127.0.0.1 127.0.0.1
6 ACCEPT all -- 127.0.0.1 127.0.0.1
7 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
8 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
9 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443
21 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:9123
22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3000
Chain FORWARD (policy DROP)
num target prot opt source destination
Chain OUTPUT (policy DROP)
num target prot opt source destination
1 ACCEPT 41 -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255
3 ACCEPT all -- 127.0.0.1 127.0.0.1
4 ACCEPT all -- 127.0.0.1 127.0.0.1
5 ACCEPT all -- 127.0.0.1 127.0.0.1
6 ACCEPT all -- 127.0.0.1 127.0.0.1
7 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
8 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
9 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443
17 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:9123
18 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3000
Table: nat
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 DOCKER all -- 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL
Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination
1 MASQUERADE all -- 192.168.42.0/24 0.0.0.0/0
2 MASQUERADE tcp -- 192.168.42.3 192.168.42.3 tcp dpt:3000
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
1 DOCKER all -- 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL
Chain DOCKER (2 references)
num target prot opt source destination
1 DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:9123 to:192.168.42.3:3000