端口已关闭,不接受外部连接

端口已关闭,不接受外部连接

我有一个使用 docker 的实例。一个 docker 容器监听 9017 端口,但无法通过公共 IP 访问。我禁用了 ufw 并清除了 iptables。

root@docker-1gb-fra1-01:/home# ufw disable
Firewall stopped and disabled on system startup
root@docker-1gb-fra1-01:/home# ufw status
Status: inactive
root@docker-1gb-fra1-01:/home# iptables -P INPUT ACCEPT
root@docker-1gb-fra1-01:/home# iptables -P FORWARD ACCEPT

nmap 显示

root@docker-1gb-fra1-01:~# nmap -p 9017 139.59.213.99

Starting Nmap 7.01 ( https://nmap.org ) at 2017-11-25 16:55 UTC
Nmap scan report for 139.59.213.99
Host is up.
PORT     STATE    SERVICE
9017/tcp filtered unknown

Nmap done: 1 IP address (1 host up) scanned in 2.17 seconds
root@docker-1gb-fra1-01:~# nmap -p 9017 localhost

Starting Nmap 7.01 ( https://nmap.org ) at 2017-11-25 16:55 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
PORT     STATE SERVICE
9017/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds

netstat 输出

root@docker-1gb-fra1-01:~# netstat -ntple
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          15869       1309/sshd
tcp6       0      0 :::9017                 :::*                    LISTEN      0          18314       1935/docker-proxy
tcp6       0      0 :::9403                 :::*                    LISTEN      0          18807       2121/docker-proxy
tcp6       0      0 :::9404                 :::*                    LISTEN      0          18726       2095/docker-proxy
tcp6       0      0 :::9451                 :::*                    LISTEN      0          18577       2050/docker-proxy
tcp6       0      0 :::22                   :::*                    LISTEN      0          15879       1309/sshd

我认为问题在于端口在 ipv6 上监听,所以我在 /etc/sysctl.conf 中设置了“net.ipv6.conf.all.forwarding=1”,但这没有帮助。

知道为什么 9017 端口在外面不可用吗?

答案1

找到原因了——本地网络的端口转发配置错误。因此实际上端口只能从我的本地网络访问。

相关内容