給VPS配置HE.NET的IPv6
Debian/Ubuntu
編輯sysctl.conf,啟用IPv6:
nano /etc/sysctl.conf
下面三項修改為下面的樣子:
net.ipv6.conf.all.disable_ipv6 = 0 net.ipv6.conf.default.disable_ipv6 = 0 net.ipv6.conf.lo.disable_ipv6 = 0
使sysctl.conf的修改生效:
sysctl -p
編輯網絡接口配置:
nano /etc/network/interfaces
在配置文檔末尾增加以下格式的內容:
(注:下面的 <HE的IPv6地址> 處,需要替換成你在HE得到的 Server IPv6 Address ,但不包括最後的::1/64,如: 2001:1111:1111:1111 ::1/64只取下劃線黑體部分)
auto he-ipv6 iface he-ipv6 inet6 v4tunnel address 2001:470:xxx:xxx::2 netmask 64 remote 216.xxx.xxx.xxx #远程ip地址 local xxx.xxx.xxx.xxx #阿里云ip地址 endpoint any ttl 255 gateway 2001:470:xxx:xxx::1 up ip -6 route add 2000::/3 via ::216.xxx.xxx.xxx dev he-ipv6 up ip -6 addr add 2001:470:xxx:xxx::1:1/128 dev he-ipv6 up ip -6 addr add 2001:470:xxx:xxx::2:1/128 dev he-ipv6 down ip -6 route flush dev he-ipv6
重啟網絡服務使修改生效:
systemctl restart network
CentOS/RHEL
編輯sysctl.conf,啟用IPv6
nano /etc/sysctl.conf
下面三項修改為下面的樣子:
net.ipv6.conf.all.disable_ipv6 = 0 net.ipv6.conf.default.disable_ipv6 = 0 net.ipv6.conf.lo.disable_ipv6 = 0
使sysctl.conf的修改生效:
sysctl -p
新建一個接口配置:
nano /etc/sysconfig/network-scripts/ifcfg-he-ipv6
配置文檔內容如下:
DEVICE=he-ipv6
TYPE=sit
BOOTPROTO=none
ONBOOT=yes # set to "no" if you prefer to start the tunnel manually
IPV6INIT=yes
IPV6TUNNELIPV4=216.66.80.30 # Server IPv4 address
IPV6ADDR=2001:470:1f0a:6ef::2 # Client IPv6 address
/etc/sysconfig/network文件添加如下内容:
NETWORKING_IPV6=yes
IPV6_DEFAULTDEV=he-ipv6
重啟網絡服務使修改生效:
systemctl restart network
添加防火墙规则:
设置完 IPv6 地址,第二天早上,发现似乎无法通过 IPv6 地址访问 VPS 了。但在 VPS 中,对应的 IPv6 隧道接口仍然是 UP 状态,而且在 VPS 中执行 ping6 ipv6.google.com 后,又重新恢复正常。
这时候首先想到的是通过 crontab,定时 ping 一个 IPv6 地址,来实现对隧道的 keep-alive 操作,如下:
*/2 * * * * ping6 -c 3 ipv6.google.com > /dev/null
不过经过查找资料,其根本原因防火墙屏蔽了协议号 41 的入站流量,导致 IPv6 隧道的服务器无法访问到 VPS,所以根本的解决方法是添加对应的防火墙规则。(以下命令适用centos7,且IP地址需要修改为隧道服务器IP)
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="66.220.18.42" accept'
2020.2.10更新
centos7和centos8均可以使用以下命令直接建立隧道,使用该命令建立的隧道无需设置防火墙
nmcli connection add type ip-tunnel con-name sit1 ifname sit1 mode sit \remote SERVER_IPV4_ADDRESS -- ipv4.method disabled ipv6.method manual \
ipv6.address CLIENT_IPV6_ADDRESS ipv6.gateway SERVER_IPV6_ADDRESS \
ip-tunnel.ttl 64