服务器启用 ipv6 功能

  1. 检查 ipv6 状态
  2. cat /proc/sys/net/ipv6/conf/all/disable_ipv6
  3. cat /proc/sys/net/ipv6/conf/default/disable_ipv6
  4. 返回 0 开启,1 或不存在为禁用
  5. 查看 ip 进一步确认
  6. ifconfig 只有 ipv4 地址,可以确认没有启用 ipv6
  7. 配置服务器启用 ipv6
vim /etc/sysconfig/network
-------------------------
# made for IPv6
NETWORKING_IPV6=yes
-------------------------
  1. 增加 dns 地址
vim /etc/resolv.conf
-------------------------
......
# IPv6 DNS by google
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
-------------------------
  1. 修改内核参数
vim /etc/sysctl.conf
-------------------------
# for enable ipv6
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
-------------------------
# 确认是否修改成功
sysctl -p
# 成功的话会返回上面一样的信息,如果报unknow key,需要当手动调用ipv6模块
# 修改配置
vim /etc/modprobe.d/disable_ipv6.conf 
----------------------
#alias net-pf-10 off
#alias ipv6 off
options ipv6 disable=0
----------------------

# 手动调用
modprobe ipv6
# 检查
lsmod | grep ipv6

添加 tunnelbroker ipv6 隧道

  1. https://www.tunnelbroker.net/open in new window 登录/注册账号
  2. 创建隧道 Create Regular Tunnel
  3. ivp4 Endpoint 填 vps 服务器的 公网 ipv4 地址
  4. 如果创建的时候提示 This network is restricted 则可以先填写一个可以用成功创建的 ip 后,再改回实际的 ip
  5. 切换到 Example Configurations 标签页,选 debian,复制代码
vim /etc/network/interfaces
-------------------------------------
auto he-ipv6
iface he-ipv6 inet6 v4tunnel
        address xxxx:xxxx:xxxx:xxx::2
        netmask 64
        endpoint xxx.xxx.xxx.xx
        local xxx.xx.xxx.xxx
        ttl 255
        gateway xxxx:xxx:xxxx:xxx::1
   -------------------------------------
  1. 重启网络模块 /etc/init.d/networking restart
  2. 检查是否添加成功 ping6 -c 5 2001:4860:4860::8888ping6 -c 5 ipv6.google.com
  3. 定时ping一下本机ipv6 ip, 避免进入睡眠模式,隧道断连,crontab -e */10 * * * * ping6 -c 1 2001::1

参考链接

Last Updated:
Contributors: haizhiguang, zhangwl231