问题原文
原帖链接 · garbagecollector · CC BY-SA 3.0
I am using Ubuntu 14.04 desktop (Xubuntu to be exact), and trying to block outside access to a locally running Postgres port 5432 with iptables. This is my iptables -S
-A INPUT -i lo -p tcp -m tcp --dport 5432 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 5432 -j DROP
And iptables -L:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:postgresql
DROP tcp -- anywhere anywhere tcp dpt:postgresql
But somehow a network scanner app on my Android, connected to the same wifi, can still see it. I can further test it with a PSQL utility on my Android, and indeed I can see all my tables. What am I missing?
Edit: might be worth mentioning that this is Postgres running on a docker container. This may have something to do with it.
已采纳解答
原帖链接 · garbagecollector · CC BY-SA 3.0
Did more digging. This looks like Docker behavior that modifies the iptables FORWARD chain.
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-OVERLAY all -- anywhere anywhere
DOCKER-ISOLATION all -- anywhere anywhere
DOCKER all -- anywhere anywhere
Chain DOCKER (2 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:postgresql
This website outlines the issue.
To prevent Docker from forwarding all access to your container, specify 127.0.0.1 when running the container.
docker run -p 127.0.0.1:5432:5432 postgres
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
