无法通过端口 9000 到达 Google 计算
Unable to reach Google Compute over port 9000
我有一个 google compute 运行 CentOS 7,我写了一个快速测试来尝试通过端口 9000(从我的家用电脑)与它通信 - 但我出乎意料获取网络错误。
我的测试脚本(尝试发送负载)甚至 plink.exe(我只是用来检查端口可用性)都会发生这种情况。
>plink.exe -v -raw -P 9000 <external_IP>
Connecting to <external_IP> port 9000
Failed to connect to <external_IP>: Network error: Connection refused
Network error: Connection refused
FATAL ERROR: Network error: Connection refused
我已将我的外部 IP 添加到 google 的防火墙 (https://console.cloud.google.com/networking/firewalls) 并设置为允许通过端口 9000 的入口流量(它是最低优先级,为 1000)
我还在 CentOS 中更新了 firewalld 以允许端口上的 TCP 流量:
Redirecting to /bin/systemctl start firewalld.service
[foo@bar ~]$ sudo firewall-cmd --zone=public --add-port=9000/tcp --permanent
success
[foo@bar ~]$ sudo firewall-cmd --reload
success
- 我已确认我的侦听器 运行 在端口 9000
[foo@bar ~]$ netstat -npae | grep 9000
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1000 18381 1201/python3
- 默认情况下,CentOS 7 不使用 iptables(只是为了确定,我确认它不是 运行)
我是不是漏掉了什么?
注意:实际外部 IP 替换为 <external_IP>
占位符
更新:
如果我通过本地 IP 从 CentOS 7 计算实例通过端口 9000 映射我的侦听器,例如 127.0.0.1,我会得到一些结果。有趣的是,如果我通过服务器外部 IP -- nadda 进行相同的 nmap 调用。所以这一定是防火墙,对吧?
外呼
[foo@bar~]$ nmap <external_IP> -Pn
Starting Nmap 6.40 ( http://nmap.org ) at 2020-05-25 00:33 UTC
Nmap scan report for <external_IP>.bc.googleusercontent.com (<external_IP>)
Host is up (0.00043s latency).
Not shown: 998 filtered ports
PORT STATE SERVICE
22/tcp open ssh
3389/tcp closed ms-wbt-server
Nmap done: 1 IP address (1 host up) scanned in 4.87 seconds
内部调用
[foo@bar~]$ nmap 127.0.0.1 -Pn
Starting Nmap 6.40 ( http://nmap.org ) at 2020-05-25 04:36 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.010s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
9000/tcp open cslistener
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
在这种情况下,后端 VM 上的软件 运行 必须侦听任何 IP(0.0.0.0 或 ::),您的正在侦听“127.0.0.1:9000”,它应该是“0.0.0.0.0”。 0.0:9000”。
解决这个问题的方法是更改服务配置以侦听 0.0.0.0 而不是 127.0.0.1。
干杯。
我有一个 google compute 运行 CentOS 7,我写了一个快速测试来尝试通过端口 9000(从我的家用电脑)与它通信 - 但我出乎意料获取网络错误。
我的测试脚本(尝试发送负载)甚至 plink.exe(我只是用来检查端口可用性)都会发生这种情况。
>plink.exe -v -raw -P 9000 <external_IP>
Connecting to <external_IP> port 9000
Failed to connect to <external_IP>: Network error: Connection refused
Network error: Connection refused
FATAL ERROR: Network error: Connection refused
我已将我的外部 IP 添加到 google 的防火墙 (https://console.cloud.google.com/networking/firewalls) 并设置为允许通过端口 9000 的入口流量(它是最低优先级,为 1000)
我还在 CentOS 中更新了 firewalld 以允许端口上的 TCP 流量:
Redirecting to /bin/systemctl start firewalld.service
[foo@bar ~]$ sudo firewall-cmd --zone=public --add-port=9000/tcp --permanent
success
[foo@bar ~]$ sudo firewall-cmd --reload
success
- 我已确认我的侦听器 运行 在端口 9000
[foo@bar ~]$ netstat -npae | grep 9000
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1000 18381 1201/python3
- 默认情况下,CentOS 7 不使用 iptables(只是为了确定,我确认它不是 运行)
我是不是漏掉了什么?
注意:实际外部 IP 替换为 <external_IP>
占位符
更新: 如果我通过本地 IP 从 CentOS 7 计算实例通过端口 9000 映射我的侦听器,例如 127.0.0.1,我会得到一些结果。有趣的是,如果我通过服务器外部 IP -- nadda 进行相同的 nmap 调用。所以这一定是防火墙,对吧?
外呼
[foo@bar~]$ nmap <external_IP> -Pn
Starting Nmap 6.40 ( http://nmap.org ) at 2020-05-25 00:33 UTC
Nmap scan report for <external_IP>.bc.googleusercontent.com (<external_IP>)
Host is up (0.00043s latency).
Not shown: 998 filtered ports
PORT STATE SERVICE
22/tcp open ssh
3389/tcp closed ms-wbt-server
Nmap done: 1 IP address (1 host up) scanned in 4.87 seconds
内部调用
[foo@bar~]$ nmap 127.0.0.1 -Pn
Starting Nmap 6.40 ( http://nmap.org ) at 2020-05-25 04:36 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.010s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
9000/tcp open cslistener
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
在这种情况下,后端 VM 上的软件 运行 必须侦听任何 IP(0.0.0.0 或 ::),您的正在侦听“127.0.0.1:9000”,它应该是“0.0.0.0.0”。 0.0:9000”。
解决这个问题的方法是更改服务配置以侦听 0.0.0.0 而不是 127.0.0.1。
干杯。