33

I have a VPS with a /64 IPv6 assigned to it. When I try to curl using one of the IPs in the block, this is the error I get:

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

What exactly do I need to do to fix this? Shouldn't I be able to use any IP on the machine when logged in as root?

Basically I just need the ability to curl using any IPv6 assigned to the VPS.

Kenster
  • 23,465
  • 21
  • 80
  • 106
Andrew
  • 665
  • 2
  • 8
  • 11
  • What do you mean by "with a /64 IPv6 assigned to it."? Is there a network interface configured to use the IPv6 address in question? You're telling curl to use the interface with that address. – ewindes Jul 11 '17 at 21:12

3 Answers3

34

after some testing, I find the following command works:

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

interface 'eth0' is the interface with ipv6 enabled, so you may need to replace it with something else.

and just in case, the telnet command to test ipv6:

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

Houman
  • 64,245
  • 87
  • 278
  • 460
Vincent
  • 901
  • 7
  • 8
9

From man curl

--interface specify interface e.g. eth0:1

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

It feels like you are expecting curl to manipulate your machine's interfaces to add-and-then-use a specific /128 ? If you want that you will probably have to write your own shell wrapper.

Alexx Roche
  • 3,151
  • 1
  • 33
  • 39
  • @Kenster is asking how to use a specific ipv6 address with curl – Roman Orac Apr 12 '18 at 10:27
  • 2
    Yes. and I explained that they are looking at the wrong ISO OSI layer. curl just lets you specify which interface. If you want to set the IPv6 source address them you need something that is *not* curl to set that. – Alexx Roche Apr 13 '18 at 11:36
  • Does your Apache have IPv6 enabled? What do the Apache logs say? – Alexx Roche Sep 08 '20 at 07:15
-1

Try using the below cmd:

curl -k -g 'http://[ipv6_addr]/foo1/foo2' -H 'Host: www.example.com'
jmoerdyk
  • 5,544
  • 7
  • 38
  • 49
  • 4
    Avoid the use of the `-k` (`--insecure`) flag whenever possible. In this case, it is unnecessary in any case, as the URL is not a https one. Also, `-g` (`--globoff`) is usually not needed. The interesting option for this specific case is `-6`, which enforces IPv6 use. – Heinrich supports Monica Feb 02 '23 at 16:08