里小伙伴们天天用的IPv6,到底是什么?

利用wget和curl命令测试IPv6的网站内容

http://6.ipv6proxy.cn 是只有ipv6地址的ipv6测试域名,用来检测你域名是否支持ipv6地址。

利用wget和curl命令测试IPv6的网站内容

如果返回ipv6地址形式,说明你当前环境一定支持ipv6访问,而且默认优先选择了ipv6链路

通过nslookup可以看到如下结果:

ubuntu@82-156-228-50:~$ nslookup 6.ipv6proxy.cn
Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
Name:   6.ipv6proxy.cn
Address: 2408:400a:1a:e800:9076:288e:4e8c:e240

首先在一个具有ipv6地址的服务器或者具有ipv6环境的机器上利用curl 加-v参数查看详细访问过程:

ubuntu@s:~$ curl -v -6 6.ipv6proxy.cn
*   Trying 2408:400a:1a:e800:9076:288e:4e8c:e240:80...
* Connected to 6.ipv6proxy.cn (2408:400a:1a:e800:9076:288e:4e8c:e240) port 80 (#0)
> GET / HTTP/1.1
> Host: 6.ipv6proxy.cn
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.18.0 (Ubuntu)
< Date: Sun, 05 Jan 2025 14:10:17 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< 
<!DOCTYPE html>
<html>
<head>
    <title>Client IP Address</title>
</head>
<body>
    2402:4e00:21:100c:b680:754e:9aa0:0</body>
</html>
* Connection #0 to host 6.ipv6proxy.cn left intact

可以发现系统解析到ipv6地址,并进行ipv6访问。
另外一种情况,http被重定向301了,那么301后是什么呢? curl并没有继续访问下去。这种情况下,要加参数-L 来继续进行访问:
curl -v -6 -L http://6.ipv6proxy.cn

嗯,发现最终访问到了ipv6地址,并直接返回了结果显示在当前输出终端,结果就是我的客户端ipv6的地址。
wget -6 http://6.ipv6proxy.cn

wget默认会直接把访问的url地址作为文件名把结果保存下来,查看index.html就是结果。
如果我们想要wget直接在终端输出结果显示,需要用 -q -O –

$ wget -6 -q -O - http://6.ipv6proxy.cn
<!DOCTYPE html>
<html>
<head>
    <title>Client IP Address</title>
</head>
<body>
    2402:4e00:21:100c:b680:754e:9aa0:0</body>
</html>

这样是比较干净的结果。