# 1. 修改網路設定
vim /etc/sysconfig/network
NETWORKING_IPV6=yes
# 2. 移除禁用模組設定 (如存在)
rm -f /etc/modprobe.d/disable_ipv6.conf
# 3. 載入模組並驗證
modprobe ipv6
lsmod | grep ipv6
關鍵坑點:HE 提供的範例腳本中 local 參數需填入 ECS 內網 IP (私有 IP),而非公網 IP。因阿里雲 ECS 在 NAT 後方,公網 IP 不在本機介面上。
# 假設內網 IP 為 172.16.100.50
# 從 Example Configurations 複製並修改 local 參數
modprobe ipv6
ip tunnel add he-ipv6 mode sit remote 216.218.221.42 local 172.16.100.50 ttl 255
ip link set he-ipv6 up
ip addr add 2001:470:xxxx:xxxx::2/64 dev he-ipv6
ip route add ::/0 dev he-ipv6
ip -6 addr show dev he-ipv6
執行後 ifconfig 或 ip addr 應顯示 he-ipv6 介面與 IPv6 位址。
ping6 ipv6.google.com
ping6 2001:4860:4860::8888
# 或使用 curl -6 ipv6.test-ipv6.com
將上述指令寫入 /etc/rc.d/rc.local 並賦予執行權限:
chmod +x /etc/rc.d/rc.local
cat >> /etc/rc.d/rc.local <<'EOF'
modprobe ipv6
ip tunnel add he-ipv6 mode sit remote 216.218.221.42 local 172.16.100.50 ttl 255
ip link set he-ipv6 up
ip addr add 2001:470:xxxx:xxxx::2/64 dev he-ipv6
ip route add ::/0 dev he-ipv6
EOF
補充發現:阿里雲 ECS CentOS 映像檔/etc、/usr/bin目錄預設無寫入權限 (不可修改系統檔),導致部分自動化腳本失效。/usr/local/bin在 PATH 優先順序較高,可放置自訂腳本繞過限制。