89

URLs always have this format:

<protocol>://<host>[:<port>]/[<path>][#<hash>]

The problem is that IPv6 uses colons, just like the separator of port and host, e.g:

2001:db8:1f70::999:de8:7648:6e8

But what if this is the host, and I want to connect to it with HTTP on port 100?

http://2001:db8:1f70::999:de8:7648:6e8:100/

The problem is the last colon. Since zero's are omitted with double colons (between 1f70 and 999), it's unknown if ':100' belongs to the IP or the port number. How can we know this?

120

The notation in that case is to encode the IPv6 IP number in square brackets:

http://[2001:db8:1f70::999:de8:7648:6e8]:100/

That's RFC 3986, section 3.2.2: Host

A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]"). This is the only place where square bracket characters are allowed in the URI syntax. In anticipation of future, as-yet-undefined IP literal address formats, an implementation may use an optional version flag to indicate such a format explicitly rather than rely on heuristic determination.

  • 39
    It's worth pointing out that the brackets are not optional. It's the only unambiguous mechanism by which the browser can identify a numeric IPv6 address. – tylerl Nov 25 '10 at 3:58
  • Shouldn't the port be inside the brackets? – jayarjo Dec 20 '16 at 15:30
  • 2
    @jayarjo No, as the brackets are there to provide disambiguation between the IP address, which contains colons, and the port, which is separated from the IP address by a colon. – sysadmin1138 Dec 22 '16 at 13:26

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.