阿里云公開的CentOS鏡像將IPv6支持給去掉了,需要加載相關模塊。通過HE的tunnelbroker開啟IPv6隧道使國內VPS支持IPv6地址。
1.
vim /etc/modprobe.d/disable_ipv6.conf
alias net-pf-10 off
options ipv6 disable=0
保存退出
2.
vim /etc/sysconfig/network
NETWORKING_IPV6=yes
保存退出
3.
vim /etc/sysconfig/network-scripts/ifcfg-eth1 #編輯要添加IPV6的網卡
IPV6INIT=yes #添加這兩行內容
IPV6_AUTOCONF=yes
保存退出
4.
vim /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 0 #這三行內容有則修改,無則添加
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
保存退出
5.創建自動加載ipv6模塊的腳本
cat > /etc/sysconfig/modules/ipv6.modules << end
#!/bin/sh
if [ ! -c /proc/net/if_inet6 ] ; then
fi
chmod +x /etc/sysconfig/modules/ipv6.modules
6.重啟服務器,加載IPV6模塊
ifconfig | grep -i inet6 # 查看ipv6的信息,有看到輸出就可以
inet6 addr: fe80::x:x:x:x/64 Scope:Link
inet6 addr: fe80::x:x:x:x/64 Scope:Link
inet6 addr: x:x:x:x::2/64 Scope:Global
inet6 addr: fe80::x:x/128 Scope:Link
inet6 addr: ::1/128 Scope:Host
7.申請IPV6地址
1)在tunnelbroker.net上申請一個免費的IPv6地址
瀏覽器打開https://www.tunnelbroker.net
注冊帳號,填寫注冊信息
2)點擊“Create Regular Tunnel”建立隧道
3)填寫需要開通IPV6的IPV4地址,點擊頁面底部的“Create Tunnel”
在"Available Tunnel Servers" 選一個隧道接入服務器,選擇亞洲的幾個接入點都可以,這樣速度會快一點,現在香港接入點好像不讓選擇了,然后點擊Create Tunnel 添加完成。
4)點擊“Example Configurations”,點擊“Linux-route2”
將自動生成對應的ipv6地址命令,將該命令復制到linux服務器上執行即可
modprobe ipv6
ip tunnel add he-ipv6 mode sit remote 66.220.18.42 local 47.91.150.65 ttl 255
ip link set he-ipv6 up
ip addr add 2001:470:c:b9::2/64 dev he-ipv6
ip route add ::/0 dev he-ipv6
ip -f inet6 addr
將以上命令寫入/etc/rc.local:
vim /etc/rc.local
sysctl -w net.ipv6.conf.all.disable_ipv6=0
sysctl -w net.ipv6.conf.lo.disable_ipv6=0
/sbin/modprobe ipv6
/sbin/ip tunnel add he-ipv6 mode sit remote 66.220.18.42 local 47.91.150.65 ttl 255
/sbin/ip addr add 2001:470:c:b9::2/64 dev he-ipv6
/sbin/ip -f inet6 addr
保存退出
輸入:ip a|grep inet #fe80::開頭的都是本地鏈接地址。帶有global的是公網地址
輸入:ping6 2001:470:c:b9::2 #發現能ping通
至此,IPV6配置完成。