【问题标题】:Google cloud, curl through ssh gives `Connection refused` for service listening on port谷歌云,通过 ssh 卷曲为服务监听端口提供“连接被拒绝”
【发布时间】:2021-11-03 16:40:33
【问题描述】:

我正在尝试从 ssh 终端连接到在谷歌云平台 VM 上运行的服务。

正在运行的进程正在监听 7076,如下所示:

ced@instance-1:~$ sudo ss -ltn
State        Recv-Q       Send-Q             Local Address:Port              Peer Address:Port       Process       
LISTEN       0            4096               127.0.0.53%lo:53                     0.0.0.0:*                        
LISTEN       0            128                      0.0.0.0:22                     0.0.0.0:*                        
LISTEN       0            128                         [::]:22                        [::]:*                        
LISTEN       0            1024                       [::1]:7076                      [::]:*                    

我还有以下允许内部连接的防火墙规则:


Name                    Type     Targets      Filters                 Protocols/ports  
default-allow-internal  Ingress  Apply to all IP ranges: 10.128.0.0/9 tcp:0-65535, udp:0-65535

使用命令时:

    curl -X POST  --data '{"action": "benchmark"}'  localhost:7076

回复是:

    curl: (7) Failed to connect to localhost port 7076: Connection refused

据我了解:

  • [::1]:7076 表示我的服务只监听本地主机上的连接
  • 我通过ssh连接,然后使用curl,这是一个内部连接(即:来自本地主机)

因此我不明白为什么我无法连接。

【问题讨论】:

  • 试试 curl -6 http://[::1]:7076。如果可行,那么您的应用程序仅在 IPv6 localhost 上侦听。
  • @JohnHanley 似乎是这样。您能否给出一个答案,解释如何为未来的读者和我自己发现这些?
  • 您的命令 sudo ss -ltn 显示 [::1]:7076。地址 ::1 是 IPv6 localhost。

标签: curl google-cloud-platform port firewall


【解决方案1】:

正如 John Hanley 所提到的,您的应用程序正在侦听 IPv6,您可以使用称为“[::1]:7076”的本地地址和端口来识别。

The loopback address 0000:0000:0000:0000:0000:0000:0000:0001 is abbreviated to ::1.

要使用带有 curl 的 IPv6,必须按照 manual 页面上的以下说明运行。

  • -6:此选项仅用于 IPv6 协议。
  • -g:此选项关闭“URL globbing parser”。设置此选项时,您可以指定包含字母 {}[] 的 URL,而无需 curl 本身解释它们。

【讨论】:

    猜你喜欢
    • 2017-04-22
    • 2017-02-09
    • 2019-09-30
    • 2014-12-26
    • 1970-01-01
    • 2016-11-28
    • 1970-01-01
    • 2017-04-17
    • 2016-02-15
    相关资源
    最近更新 更多