28

I tried a few ways but they seem to be confusing curl.

root@testt:~# curl localhost:8080
<h1>Hello world!</h1>

<p>Boom Bam Splat</p>
root@testt:~# curl ::1:8080
curl: (3) IPv6 numerical address used in URL without brackets
root@testt:~# curl [::1]:8080
curl: (3) [globbing] bad range specification in column 2
  • 1
    I know you have selected an answer, but since there are similarities between the two answers here, can you please clarify which specific command worked for you? – JakeGould Mar 5 '15 at 7:22
  • 1
    Thanks for giving the answers earlier! I was genuinely hard pressed for which to accept since they were both so concise and whatnot, though I chose the other since that user is just starting out compared to you and answered first. Regardless, just using the - g option was sufficient. – hak8or Mar 5 '15 at 7:34
44

Looking at the suggestions—and breakdown of common errors—on this blog post, perhaps you should try this.

curl -g -6 "http://[::1]:8080/" 

The -g seems to be the magical key to get this working. As explained on the curl man page:

This option switches off the "URL globbing parser". When you set this option, you can specify URLs that contain the letters {}[] without having them being interpreted by curl itself. Note that these letters are not normal legal URL contents but they should be encoded according to the URI standard.

And the -6 means to use IPv6 only:

If libcurl is capable of resolving an address to multiple IP versions (which it is if it is IPv6-capable), this option tells libcurl to resolve names to IPv6 addresses only.

But reading that functionality description, it seems like -6 is not really needed for a pure IPv6 address; only if one is using curl on a hostname that has an IPv4 and IPv6 address connected to it so it would prefer the IPv6. Just something to note.

  • OSX 10.13.3: This works: $ curl "http://localhost:50710/file1.txt" and this doesn't $ curl -g -6 "http://[::1]:50710/file1.txt" curl: (7) Failed to connect to ::1 port 50710: Connection refused. And $ curl -V does show IPv6 as a feature (curl 7.58.0). My /etc/hosts file lists: ::1 localhost – 7stud Feb 26 '18 at 0:04
  • Hey, thanks for the tip about my server! Now, that I've got my server bound to the ipv6 address: 0.0.0.0.0.0.0.1, I can simply do curl "http://[::1]:50710/file1.txt". If I add a -v option for verbose output, I see in the output: Trying ::1... * TCP_NODELAY set * Connected to ::1 (::1) port 52489 (#0) -- For some reason, I didn't need the -g option. – 7stud Feb 26 '18 at 5:23
  • More info: With my server bound to an ipv6 host, I can still make an ipv4 get request with curl: curl -v "http://localhost:52489/file1.txt". In the output I see: Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 52489 (#0) -- Ah, I think that's because my /etc/hosts file resolves the name "localhost" to both an ipv4 and ipv6 address. And if I try: curl -v "http://127.0.0.1:52489/file1.txt" then I get a connection refused error. – 7stud Feb 26 '18 at 5:37
  • 1
    @7stud “Now, that I've got my server bound to the ipv6 address: 0.0.0.0.0.0.0.1.” You seriously have no idea what you are talking about. I suggest writing a new question explaining all you explain in these comments and see if someone can help you. Refer to this answer if you wish. But if you think 0.0.0.0.0.0.0.1 is a valid IPv6 address you are already on a bad footing. – JakeGould Feb 26 '18 at 12:51
8

From "curl --manual", I found this:

curl -g "http://[2001:1890:1112:1::20]/"

or

curl "http://[2001:1890:1112:1::20]/"

So, for the address you're asking about, try:

curl -g "http://[::1]:8080/"

However, you may want to run:

curl -V

and see if IPv6 shows up on the line that says "Features" (the third line, not counting extra lines from word wrapping). I found my version didn't. cURL download page has various links for operating systems, including curl 7.41.0 download site (which is currently the latest version) for Microsoft Windows. That page has multiple executables (available for Microsoft Windows); the first one I found did not support IPv6. But the two described as "ipv6-sspi-spnego-winssl" (one for x86 and one for x64) did : curl -V did show IPv6. So be careful about which package you download.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.