You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在GCP中使用curl访问转发规则IPv6地址报错,该如何解决?

问题:curl访问IPv6地址报错“URL using bad/illegal format or missing URL”

我创建了一条将TCP流量转发至目标实例的转发规则,命令如下:

gcloud compute forwarding-rules create forwarding-rule-1 \
  --load-balancing-scheme=EXTERNAL \
  --subnet=lb-subnet \
  --ip-version=IPV6 \
  --region=asia-east1 \
  --ip-protocol=TCP \
  --ports=80 \
  --target-instance=target-instance-1 \
  --target-instance-zone=asia-east1-a

执行以下命令获取该转发规则的IP地址:

gcloud compute forwarding-rules describe forwarding-rule-1 \
 --region=asia-east1

输出结果:

IPAddress: 2600:1900:4030:c58:8000:3:0:0/96
IPProtocol: TCP
creationTimestamp: '2022-11-24T08:01:58.737-08:00'
description: ''
fingerprint: xxxx=
id: 'xxxxx'
ipVersion: IPV6
kind: compute#forwardingRule
labelFingerprint: xxxx
loadBalancingScheme: EXTERNAL
name: forwarding-rule-1
networkTier: PREMIUM
portRange: 80-80

随后尝试用curl访问该IPv6地址:

curl 2600:1900:4030:c58:8000:3:0:0

返回错误:URL using bad/illegal format or missing URL,请问遗漏了什么?


原因及解决方法

  1. IPv6地址需用方括号包裹:curl解析URL时,会把IPv6地址中的冒号识别为端口分隔符,导致格式解析错误,必须用[]将IPv6地址完整括起来。
  2. 移除子网前缀:获取到的IP地址带有/96的子网掩码前缀,访问时需要去掉该部分,只保留纯IPv6地址。

正确的curl命令如下:

curl [2600:1900:4030:c58:8000:3:0:0]

如果需要显式指定端口(80为curl默认HTTP端口,可省略),可写成:

curl [2600:1900:4030:c58:8000:3:0:0]:80

内容的提问来源于stack exchange,提问作者Nosail

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 17:35:33