Bootstrap

阿里云ecs开启支持ipv6

转载自:https://blog.csdn.net/u014201191/article/details/85112590

检查是否开启了ipv6

输入命令ip addr | grep inet6

如果返回中带有ipv6的字段,则表示已经开启了,如果没有请按照下列方式开启

添加ipv6模块

1、修改 /etc/modprobe.d/disable_ipv6.conf

 
  1. #修改前

  2. alias net-pf-10 off

  3. options ipv6 disable=1

  4. #修改后

  5. alias net-pf-10 off

  6. options ipv6 disable=0

2、修改/etc/sysconfig/network

 
  1. 修改前

  2. PEERNTP=no

  3. NETWORKING_IPV6=no

  4. 修改后

  5. PEERNTP=no

  6. NETWORKING_IPV6=yes

3、修改 /etc/sysconfig/network-scripts/ifcfg-eth0

 
  1. ## 添加 IPV6INIT 为 yes 和 IPV6_AUTOCONF 为 yes

  2. IPV6INIT=yes

  3. IPV6_AUTOCONF=yes

4、 修改 /etc/sysctl.conf

 
  1. ## 修改 net.ipv6.conf.all.disable_ipv6 为 0, net.ipv6.conf.default.disable_ipv6 为 0 和 net.ipv6.conf.lo.disable_ipv6 为 0

  2. 修改前

  3. net.ipv6.conf.all.disable_ipv6 = 1

  4. net.ipv6.conf.default.disable_ipv6 = 1

  5. net.ipv6.conf.lo.disable_ipv6 = 1

  6. net.ipv4.conf.lo.arp_announce=2

  7. 修改后

  8. net.ipv6.conf.all.disable_ipv6 = 0

  9. net.ipv6.conf.default.disable_ipv6 = 0

  10. net.ipv6.conf.lo.disable_ipv6 = 0

5、创建系统在启动时自动加载 IPv6 模块的脚本

 
  1. 创建脚本文件 ipv6.modules

  2. vi /etc/sysconfig/modules/ipv6.modules

  3. 脚本内容

  4. !/bin/sh

  5. if [ ! -c /proc/net/if_inet6 ] ; then

  6. exec /sbin/insmod /lib/modules/uname -r/kernel/net/ipv6/ipv6.ko

  7. fi

授权:chmod +x /etc/sysconfig/modules/ipv6.modules

6、重启系统,加载 IPv6 模块并查看

 
  1. ifconfig | grep -i inet6 #### 查看ipv6的信息,有看到输出就可以

  2. inet6 fe80::216:3eff:fe00:6fb8 prefixlen 64 scopeid 0x20<link>

  3. inet6 ::1 prefixlen 128 scopeid 0x10<host>

现在已经证明服务器支持ipv6的功能模块了

申请IPV6地址

1、在 tunnelbroker.net 上申请一个免费的 IPv6 地址,现注册个账号。

2、选择 Create Regular Tunnel 创建一个到自己公网 IP 的通道。(输入框内输入自己的ipv4公网ip地址)

3、选择HK,不过有时候也满了,选择Freemont,CA,US 也可以。

4、找到 Example Configurations,centos7.x 选择 linux-net-tools,复制命令,去服务器上执行。

5、ping6 {ipv6地址}测试是否能够入网

 
  1. [root@izhp34ij40k1dgq89lnntdz ~]# ping6 2001:470:23:999::2

  2. PING 2001:470:23:999::2(2001:470:23:999::2) 56 data bytes

  3. 64 bytes from 2001:470:23:999::2: icmp_seq=1 ttl=64 time=0.019 ms

  4. 64 bytes from 2001:470:23:999::2: icmp_seq=2 ttl=64 time=0.031 ms

  5. 64 bytes from 2001:470:23:999::2: icmp_seq=3 ttl=64 time=0.031 ms

  6. 64 bytes from 2001:470:23:999::2: icmp_seq=4 ttl=64 time=0.032 ms

  7. 64 bytes from 2001:470:23:999::2: icmp_seq=5 ttl=64 time=0.031 ms

  8. 64 bytes from 2001:470:23:999::2: icmp_seq=6 ttl=64 time=0.033 ms

说明此时我们的ipv6环境已经准备好了,在查看一下ecs返回的ipv6模块;

 
  1. [root@izhp34ij40k1dgq89lnntdz ~]# ifconfig | grep -i inet6

  2. inet6 fe80::216:3eff:fe00:6fb8 prefixlen 64 scopeid 0x20<link>

  3. inet6 ::1 prefixlen 128 scopeid 0x10<host>

  4. inet6 ::127.0.0.1 prefixlen 96 scopeid 0x90<compat,host>

  5. inet6 ::192.168.0.5 prefixlen 96 scopeid 0x80<compat,global>

  6. inet6 fe80::c0a8:5 prefixlen 64 scopeid 0x20<link>

  7. inet6 2001:470:23:999::2 prefixlen 64 scopeid 0x0<global>

6、ifconfig查看ipv6模块开启状态

 
  1. [root@izhp34ij40k1dgq89lnntdz ~]# ifconfig

  2. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

  3. inet 192.168.0.5 netmask 255.255.255.0 broadcast 192.168.0.255

  4. inet6 fe80::216:3eff:fe00:6fb8 prefixlen 64 scopeid 0x20<link>

  5. ether 00:16:3e:00:6f:b8 txqueuelen 1000 (Ethernet)

  6. RX packets 7006 bytes 9477709 (9.0 MiB)

  7. RX errors 0 dropped 0 overruns 0 frame 0

  8. TX packets 1610 bytes 178352 (174.1 KiB)

  9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  10.  
  11. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

  12. inet 127.0.0.1 netmask 255.0.0.0

  13. inet6 ::1 prefixlen 128 scopeid 0x10<host>

  14. loop txqueuelen 1 (Local Loopback)

  15. RX packets 12 bytes 1248 (1.2 KiB)

  16. RX errors 0 dropped 0 overruns 0 frame 0

  17. TX packets 12 bytes 1248 (1.2 KiB)

  18. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  19.  
  20. sit0: flags=193<UP,RUNNING,NOARP> mtu 1480

  21. inet6 ::127.0.0.1 prefixlen 96 scopeid 0x90<compat,host>

  22. inet6 ::192.168.0.5 prefixlen 96 scopeid 0x80<compat,global>

  23. sit txqueuelen 1 (IPv6-in-IPv4)

  24. RX packets 0 bytes 0 (0.0 B)

  25. RX errors 0 dropped 0 overruns 0 frame 0

  26. TX packets 0 bytes 0 (0.0 B)

  27. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  28.  
  29. sit1: flags=209<UP,POINTOPOINT,RUNNING,NOARP> mtu 1480

  30. inet6 fe80::c0a8:5 prefixlen 64 scopeid 0x20<link>

  31. inet6 2001:470:23:999::2 prefixlen 64 scopeid 0x0<global>

  32. sit txqueuelen 1 (IPv6-in-IPv4)

  33. RX packets 0 bytes 0 (0.0 B)

  34. RX errors 0 dropped 0 overruns 0 frame 0

  35. TX packets 0 bytes 0 (0.0 B)

  36. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

注意必须是上面那样子的,负责是不正确的。

7、添加域名解析记录AAAA;

注意在填写ipv6地址的时候,后面的/24是不需要填写的;

8、使用测试网站进行域名测试http://ipv6-test.com/validate.php

那此时此刻,我们的解析已经完成了,只是我们没有提供ipv6的访问服务,接下来使用nginx部署服务;

 

nginx开启IPV6支持配置

安装nginx的时候,使用--with-ipv6进行编译安装,然后添加对ipv6的监听;

 
  1. server {

  2. listen 80;

  3. listen [::]:80 ipv6only=on;

  4. server_name example.com;

  5. ……

  6. }

接下来我们从刚才的测试网站,再次查看一下测评的效果:

这里有一个注意的地方,如果你购买的是阿里云的ecs,务必开放ipv4的所有安全组访问,这样才能ping通顺,另外,如果想检查ecs是否配置好了ipv6的网快,使用 ping -6 ipv6.google.com,如果返回信息中包含了字节数,那么恭喜你,配置完成了。感谢

另外,还有一个残留的问题,在执行命令后,如果机器重启,还需要在隧道上面执行命令,才能生效,如果大家有什么解决的办法,就在下面留言吧~

;