个人学习笔记,谢绝转载!!!
原文:https://www.cnblogs.com/wshenjin/p/14923509.html
nginx中的listen
如果要同时监听IPv4、IPv6的所有接口
listen 80;
listen 443 ssl;
listen [::]:80;
listen [::]:443 ssl;
curl命令测试IPv6的站点
- -6 --ipv6: 将目标域名仅解析为 IPv6 地址.
- -g: 正确的对url中的 [ ] 字符的处理方式,必须携带该选项;
- 为了在URL中使用文本IPv6地址,文本地址应该用符号[ ]来封闭。
要对指定IPv6的站点curl:
# curl -6 -g -v 'http://[fd15:4ba5:5a2b:1008:a1e4:138a:b153:3f01]:80/api/service/login?oack=c247ea7a2d115d' -H 'host: ipv6.example.com'
# curl -6 -g -k -v 'https://[fd15:4ba5:5a2b:1008:a1e4:138a:b153:3f01]:443/api/service/login?oack=c247ea7a2d115d' -H 'host: ipv6.example.com'
要求域名仅解析为IPv6进行curl:
# curl -6 -v 'http://ipv6.example.com:80/api/service/login?oack=c247ea7a2d115d'
# curl -6 -v 'https://ipv6.example.com:443/api/service/login?oack=c247ea7a2d115d'
cURL 的 IPv6、IPv4 选择策略
- 解析被请求的域名,通常会获得一个ip地址列表,同时包含了IPv4和IPv6地址;
- 会首先发起连接IPv6地址,如果200ms内连接成功,则直接使用此地址;
- 如果200ms未连接成功IPv6地址,cURL会对列表中地址并发发起连接;
- 最后等待第一个成功建立的连接,将作为后续cURL传输地址。
例如某个站点同时解析了IPv6、IPv4
# nslookup ipv6.example.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: ipv6.example.com
Address: 192.168.1.3
Name: ipv6.example.com
Address: fd15:4ba5:5a2b:1008:a1e4:138a:b153:3f01
用curl请求会发现其第一次对IPv6发起了connect
root@ ~]# curl -Iv 'http://ipv6.example.com/api/service/login?oack=c247ea7a2d115d'
* About to connect() to ipv6.example.com port 80 (#0)
* Trying fd15:4ba5:5a2b:1008:a1e4:138a:b153:3f01...
* Connection refused
* Trying 192.168.1.3...
* Connected to ipv6.example.com (192.168.1.3) port 80 (#0)
> HEAD /api/service/login?oack=c247ea7a2d115d HTTP/1.1
> User-Agent: curl/7.29.0
> Host: ipv6.example.com
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx
如果想强制使用IPv4 or IPv6,可以使用参数通过命令行参数:--ipv4 或 -4 强制使用 ipv4 协议,--ipv6 或 -6 强制使用 ipv6 协议。
[root@ ~]# curl --ipv6 -Iv 'http://ipv6.example.com/api/service/login?oack=c247ea7a2d115d'
* About to connect() to ipv6.example.com port 80 (#0)
* Trying fd15:4ba5:5a2b:1008:a1e4:138a:b153:3f01...
* Connection refused
* Failed connect to ipv6.example.com:80; Connection refused
* Closing connection 0
curl: (7) Failed connect to ipv6.example.com:80; Connection refused
[root@ ~]# curl --ipv4 -Iv 'http://ipv6.example.com/api/service/login?oack=c247ea7a2d115d'
* About to connect() to ipv6.example.com port 80 (#0)
* Trying 192.168.1.3...
* Connected to ipv6.example.com (192.168.1.3) port 80 (#0)
> HEAD /api/api/sg-service/pull?limit=100 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: ipv6.example.com
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx
Server: nginx
https://daniel.haxx.se/blog/2020/04/20/curl-ootw-ipv4/
网卡的设置
IPV6INIT="yes"
IPV6_AUTOCONF="yes" ##是否从自动获取
DHCPV6C="yes"
#IPV6ADDR="fd15:4ba5:5a2b:1008:a1e4:138a:b153:3f01" ##静态配置
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"