浏览器访问 IPv6 地址

在 IPv6 地址两边加上中括号,就可以通过浏览器访问了

浏览器访问

访问 http://[2402:4e00:1013:e500:0:940e:29d7:3443]/ ,会返回本机 IPv6 IP地址。

如果有端口,在 IP 地址后面添加端口,比如

http://[2402:4e00:1013:e500:0:940e:29d7:3443]:80/

Ping IPv6 地址

ipv6.ipw.cnopen in new window 域名解析的 AAAA 记录就是上面这个 IPv6 IP。

~$ ping6 ipv6.ipw.cn
PING6(56=40+8+8 bytes) 1111:1111:30c0:9556:b807:e464:1111:1111 --> > 2402:4e00:1013:e500:0:940e:29d7:3443
16 bytes from 2402:4e00:1013:e500:0:940e:29d7:3443, icmp_seq=0 hlim=52 time=65.256 ms
16 bytes from 2402:4e00:1013:e500:0:940e:29d7:3443, icmp_seq=1 hlim=52 time=45.522 ms
16 bytes from 2402:4e00:1013:e500:0:940e:29d7:3443, icmp_seq=2 hlim=52 time=82.197 ms
16 bytes from 2402:4e00:1013:e500:0:940e:29d7:3443, icmp_seq=3 hlim=52 time=95.477 ms
1
2
3
4
5
6

终端 CURL 访问

MacOS

curl [2402:4e00:1013:e500:0:940e:29d7:3443]
1111:1111:30c0:9556:b807:e464:1111:1111


curl http://[2402:4e00:1013:e500:0:940e:29d7:3443]/
1111:1111:30c0:9556:b807:e464:1111:1111
1
2
3
4
5
6

Linux

如果在 Linux 下,还需要增加 -g 参数,否则会提示 curl: (3) [globbing] error: bad range specification after pos

 -g, --globoff
    his  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.
1
2
curl -g http://[2402:4e00:1013:e500:0:940e:29d7:3443]/
1

curl 指定 IPv6 或 IPv4 访问

如果同一个 host 同时解析到 IPv6 和 IPv4 地址,即 IPv4/IPv6 双栈,则 curl 使用参数可指定 IP 协议的版本。

-4, --ipv4

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

-6, --ipv6

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

比如 6.ipw.cn 同时解析到 IPv4 和 IPv6 地址。

curl -4 6.ipw.cn
106.224.145.147

curl -6 6.ipw.cn
2408:824c:200::2b8b:336f:cc9c
1
2
3
4
5

telnet ipv6 地址

telnet -6 2402:4e00:1013:e500:0:940e:29d7:3443 80
Trying 2402:4e00:1013:e500:0:940e:29d7:3443...
Connected to 2402:4e00:1013:e500:0:940e:29d7:3443.
Escape character is '^]'.
1
2
3
4