如何使用IPv6地址进行curl?

问题描述 投票:0回答:4

我有一个分配了 /64 IPv6 的 VPS。当我尝试使用块中的 IP 之一进行卷曲时,这是我收到的错误:

curl --interface '2a02:c207:2010:1077::2' http://example.com
curl: (45) bind failed with errno 99: Cannot assign requested address

我到底需要做什么来解决这个问题?当我以root身份登录时,我不应该能够使用机器上的任何IP吗?

基本上我只需要能够使用分配给 VPS 的任何 IPv6 进行卷曲。

linux shell curl
4个回答
47
投票

经过一些测试,我发现以下命令有效:

$ curl -g -6 'http://[fe80::3ad1:35ff:fe08:cd%eth0]:80/'

接口 'eth0' 是启用了 ipv6 的接口,因此您可能需要将其替换为其他接口。

为了以防万一,测试 ipv6 的 telnet 命令:

$ telnet -6 fe80::3ad1:35ff:fe08:cd%eth0 80


9
投票

来自

man curl

--interface 指定接口,例如eth0:1

curl --interface eth0 -g -6 'http://[2606:2800:220:1:248:1893:25c8:1946]:80/index.html' -H 'Host: www.example.com'

感觉您期望curl 操纵您的机器接口来添加然后使用特定的/128 ?如果您愿意,您可能必须编写自己的 shell 包装器。


0
投票

当我尝试使用块中的 IP 之一进行卷曲时,这是我收到的错误:

您似乎分配了一个 /64,并且想要使用该 /64 块上的另一个 IPv6 地址作为源 IPv6 地址。

以 root 身份登录时,我不应该能够使用机器上的任何 IP 吗?

bind failed with errno 99: Cannot assign requested address
表示您请求的 IPv6 地址未分配给您的任何接口,您不能使用任何未分配给您的接口的地址作为源 IP。

基本上我只需要能够使用分配给 VPS 的任何 IPv6 进行卷曲。

首先,在 /64 块下的接口上分配所需的 IPv6 地址。
假设您的界面位于

eth0

sudo ip -6 addr add 2a02:c207:2010:1077::2/64 dev eth0

然后您现在可以在curl上使用分配的IPv6地址。

curl --interface '2a02:c207:2010:1077::2' http://example.com


-1
投票

尝试使用以下命令:

curl -k -g 'http://[ipv6_addr]/foo1/foo2' -H 'Host: www.example.com'
© www.soinside.com 2019 - 2024. All rights reserved.