最后更新于:2026年07月

IPv6-only VPS
IPv6-only VPS 与 NAT64/DNS64 部署

IPv4 地址已经枯竭,但 IPv6 地址几乎是无限的。很多云服务商(如 Vultr、DigitalOcean、Hetzner)提供的 IPv6-only VPS 价格只有双栈 VPS 的一半甚至更低。更重要的是,IPv6-only VPS 可以有效规避基于 IPv4 的封锁,因为攻击者很难对全球数十亿 IPv6 地址进行大规模扫描和封锁。

然而,IPv6-only VPS 面临一个问题:很多网站和服务只支持 IPv4。解决这个问题的方案是 NAT64 + DNS64——通过 NAT 转换让 IPv6-only 服务器能够访问 IPv4 网络。本文将带你从零开始部署 IPv6-only VPS,配置 NAT64/DNS64,并实现完整的双栈兼容。


🧭 IPv6-only VPS 是什么?

IPv6 vs IPv4

PLAINTEXT
┌──────────────────────────────────────────────────────────┐
│                     IPv4 vs IPv6                        │
│                                                          │
│  IPv4                                                    │
│  - 地址长度:32 位(约 43 亿个)                         │
│  - 已枯竭(2011 年分配完毕)                            │
│  - 地址稀缺,价格高                                      │
│  - 容易被封锁(地址数量有限)                            │
│                                                          │
│  IPv6                                                    │
│  - 地址长度:128 位(约 3.4×10³⁸ 个)                  │
│  - 几乎无限                                              │
│  - 地址充足,价格低                                      │
│  - 难以被大规模封锁(地址太多)                          │
│                                                          │
│  IPv6-only VPS                                           │
│  - 只分配 IPv6 地址,没有 IPv4                          │
│  - 价格通常是双栈 VPS 的 50%-75%                        │
│  - 需要额外配置才能访问 IPv4 网络                        │
│  - 非常适合作为代理节点(抗封锁能力强)                    │
└──────────────────────────────────────────────────────────┘

NAT64/DNS64 工作原理

PLAINTEXT
┌──────────────────────────────────────────────────────────┐
│              NAT64 / DNS64 工作原理                      │
│                                                          │
│  IPv6-only 服务器                                         │
│       │                                                  │
│       │  访问 google.com                                  │
│       ▼                                                  │
│  DNS64 服务器                                             │
│       │                                                  │
│       │  查询 google.com                                 │
│       │  → 发现只有 IPv4 地址                            │
│       │  → 合成 IPv6 地址(前缀 + IPv4 地址)           │
│       │  → 返回合成的 IPv6 地址                          │
│       ▼                                                  │
│  NAT64 网关                                              │
│       │                                                  │
│       │  收到 IPv6 流量                                  │
│       │  → 判断目标是合成地址                            │
│       │  → 提取 IPv4 地址                                │
│       │  → NAT 转换后转发到 IPv4 网络                    │
│       ▼                                                  │
│  IPv4 目标服务器                                          │
│                                                          │
│  结果返回:                                              │
│  IPv4 服务器 → NAT64 网关 → IPv6-only 服务器            │
└──────────────────────────────────────────────────────────┘

📦 第一步:购买 IPv6-only VPS

推荐服务商

服务商最低配置价格(月)IPv6 地址推荐指数
Vultr1 CPU / 512MB$2.5/64⭐⭐⭐⭐⭐
DigitalOcean1 CPU / 1GB$4/64⭐⭐⭐⭐⭐
Hetzner2 CPU / 4GB€2.93/64⭐⭐⭐⭐⭐
BuyVM1 CPU / 512MB$1.5/64⭐⭐⭐⭐
RackNerd1 CPU / 512MB$12/年/64⭐⭐⭐⭐
OVH1 CPU / 1GB€3.99/128⭐⭐⭐

推荐:Vultr / Hetzner(性能稳定,IPv6 支持好)

购买流程

PLAINTEXT
以 Vultr 为例:

1. 登录 Vultr 后台
2. 点击「Deploy Server」
3. 选择服务器类型:Cloud Compute
4. 选择数据中心(推荐:日本 / 新加坡 / 美国)
5. 选择操作系统:Debian 12 / Ubuntu 22.04
6. 选择套餐:$2.5/month(512MB / 1CPU / 10GB SSD)
7. 在「IPv6 Settings」中:
   - 勾选「Enable IPv6」
   - 选择「IPv6-only」(如果有)
8. 设置防火墙规则:
   - 允许 IPv6 所有出站
   - 允许必要的入站端口
9. 点击「Deploy Now」
10. 等待服务器启动(约 1 分钟)
11. 获取 IPv6 地址(在服务器详情中)

初始登录

BASH
# 获取服务器 IPv6 地址
# Vultr 后台显示格式:2001:19f0:xxxx:xxxx::x

# 使用 IPv6 地址登录
ssh root@[2001:19f0:xxxx:xxxx::x]

# 如果本地不支持 IPv6,使用 Vultr 的控制台
# 或配置本地 IPv6 隧道(参考后续章节)

# 检查网络配置
ip addr
# 应看到类似:
# inet6 2001:19f0:xxxx:xxxx::x/64 scope global

🔧 第二步:配置基础网络

配置 IPv6 网络

BASH
# 查看当前网络配置
cat /etc/network/interfaces
# 或
cat /etc/netplan/*.yaml

# 确保 IPv6 配置正确
# Debian 12 示例:
cat > /etc/network/interfaces << 'EOF'
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet6 dhcp
    accept_ra 2
EOF

# 重启网络
systemctl restart networking

# 验证 IPv6 连接
ping6 google.com
# 应能 ping 通

配置 IPv6 路由

BASH
# 查看路由表
ip -6 route

# 确保默认路由正确
# 应该有:default via fe80::1 dev eth0 proto ra

# 如果没有默认路由,手动添加
ip -6 route add default via fe80::1 dev eth0

# 或在配置文件中添加
# /etc/network/interfaces
iface eth0 inet6 dhcp
    gateway fe80::1

配置 DNS

BASH
# 配置 IPv6 DNS 服务器
cat > /etc/resolv.conf << 'EOF'
nameserver 2001:4860:4860::8888  # Google IPv6 DNS
nameserver 2001:4860:4860::8844
nameserver 2606:4700:4700::1111  # Cloudflare IPv6 DNS
nameserver 2606:4700:4700::1001
EOF

# 或使用 systemd-resolved
cat > /etc/systemd/resolved.conf << 'EOF'
[Resolve]
DNS=2001:4860:4860::8888 2001:4860:4860::8844
DNSOverHTTPS=yes
EOF

systemctl restart systemd-resolved

测试 IPv6 网络

BASH
# 测试 IPv6 连通性
ping6 -c 4 google.com

# 测试 IPv6 下载速度
curl -6 -o /dev/null -s -w "%{speed_download}\n" https://speed.cloudflare.com/__down?bytes=100000000

# 查看公网 IPv6 地址
curl -6 ifconfig.co

# 检查 IPv6 端口监听
ss -tlnp6

🚀 第三步:部署 NAT64/DNS64

方案选择

方案复杂度性能推荐
Tayga⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Jool⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
bind9 DNS64 + iptables NAT64⭐⭐⭐⭐⭐⭐⭐⭐⭐
Public NAT64⭐⭐⭐⭐⭐⭐

推荐:Tayga(最简单,性能好,开箱即用)

方案一:Tayga(推荐)

Tayga 是一个轻量级的 NAT64/DNS64 实现,用 Go 编写,配置简单。

BASH
# 安装 Tayga
go install github.com/bgp/tayga@latest

# 或下载预编译二进制
VERSION=$(curl -s https://api.github.com/repos/bgp/tayga/releases/latest | grep tag_name | cut -d '"' -f 4)
wget https://github.com/bgp/tayga/releases/download/$VERSION/tayga_${VERSION}_linux_amd64.tar.gz
tar -xzvf tayga_${VERSION}_linux_amd64.tar.gz
cp tayga /usr/local/bin/

# 创建配置目录
mkdir -p /etc/tayga

创建配置文件 /etc/tayga/tayga.conf

YAML
# NAT64 配置
nat64:
  # NAT64 前缀(推荐使用 64:ff9b::/96,这是标准 Well-Known 前缀)
  prefix: "64:ff9b::/96"
  
  # 监听地址
  listen: "::"
  
  # 端口范围(用于 NAT 转换)
  port-range: "1024-65535"
  
  # 上游 DNS(用于查询 IPv4 地址)
  upstream-dns:
    - "8.8.8.8"
    - "1.1.1.1"
  
  # DNS64 配置
  dns64:
    # DNS64 监听地址
    listen: ":::53"
    
    # 本地域名(不走 DNS64)
    local-domains:
      - "localhost"
      - "local"
      - "internal"
    
    # 上游 DNS(用于查询原始记录)
    upstream:
      - "8.8.8.8"
      - "1.1.1.1"

# 日志配置
logging:
  level: "info"
  format: "text"

创建 systemd 服务

BASH
cat > /etc/systemd/system/tayga.service << 'EOF'
[Unit]
Description=Tayga NAT64/DNS64 Server
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/tayga -config /etc/tayga/tayga.conf
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

# 启动服务
systemctl daemon-reload
systemctl enable --now tayga
systemctl status tayga

配置系统使用本地 DNS64

BASH
# 修改 resolv.conf
cat > /etc/resolv.conf << 'EOF'
nameserver ::1
nameserver 127.0.0.1
EOF

# 或使用 systemd-resolved
cat > /etc/systemd/resolved.conf << 'EOF'
[Resolve]
DNS=::1
DNSOverHTTPS=no
EOF

systemctl restart systemd-resolved

测试 NAT64/DNS64

BASH
# 测试 DNS64(查询只有 IPv4 的域名)
dig ipv4.google.com AAAA

# 应返回合成的 IPv6 地址,格式如:64:ff9b::7f00:1

# 测试 NAT64(通过 IPv6 访问 IPv4 网站)
curl -6 http://ipv4.google.com

# 应能正常访问

# 测试 IPv4 地址访问(通过 NAT64)
curl -6 http://1.1.1.1

# 应能正常访问

方案二:Jool(内核级 NAT64)

Jool 是 Linux 内核级 NAT64 实现,性能最好,但配置复杂。

BASH
# 安装 Jool
apt install jool-tools

# 加载内核模块
modprobe jool

# 创建 NAT64 实例
jool instance add "nat64" --netfilter --pool6 "64:ff9b::/96"

# 查看实例
jool instance list

# 配置 IPv6 到 IPv4 的映射
jool "nat64" pool4 add 192.168.0.1-192.168.0.254

# 配置 DNS64(使用 bind9)
apt install bind9

# 修改 bind9 配置
cat >> /etc/bind/named.conf.options << 'EOF'
dns64 64:ff9b::/96 {
    clients { any; };
    mapped { any; };
    break-dnssec yes;
};
EOF

# 重启 bind9
systemctl restart bind9

方案三:使用 Public NAT64

如果不想自己部署,可以使用公共的 NAT64 服务:

BASH
# 公共 NAT64 服务列表:

# Google Public NAT64(最稳定)
# 前缀:64:ff9b::/96
# DNS:2001:4860:4860::8888, 2001:4860:4860::8844

# Cloudflare NAT64
# 前缀:64:ff9b::/96
# DNS:2606:4700:4700::1111, 2606:4700:4700::1001

# 使用方法:
# 直接配置 DNS 服务器为上述地址
# 系统会自动使用 NAT64

# 测试
cat > /etc/resolv.conf << 'EOF'
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
EOF

# 测试访问 IPv4 网站
curl -6 http://ipv4.google.com

🔗 第四步:配置代理服务

xray 配置(IPv6)

JSON
{
  "inbounds": [
    {
      "port": 443,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "your-uuid-here",
            "level": 0
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
          "path": "/secretpath",
          "headers": {
            "Host": "proxy.example.com"
          }
        },
        "security": "tls",
        "tlsSettings": {
          "certificates": [
            {
              "certificateFile": "/etc/letsencrypt/live/proxy.example.com/fullchain.pem",
              "keyFile": "/etc/letsencrypt/live/proxy.example.com/privkey.pem"
            }
          ]
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIPv6"
      }
    }
  ]
}

sing-box 配置(IPv6)

JSON
{
  "inbounds": [
    {
      "type": "vless",
      "tag": "vless-in",
      "listen": "::",
      "listen_port": 443,
      "users": [
        {
          "name": "default",
          "uuid": "your-uuid-here"
        }
      ],
      "transport": {
        "type": "ws",
        "path": "/secretpath",
        "headers": {
          "Host": "proxy.example.com"
        }
      },
      "tls": {
        "enabled": true,
        "certificate_path": "/etc/letsencrypt/live/proxy.example.com/fullchain.pem",
        "key_path": "/etc/letsencrypt/live/proxy.example.com/privkey.pem"
      }
    }
  ],
  "outbounds": [
    {
      "type": "direct"
    }
  ],
  "route": {
    "rules": [
      {
        "outbound": "direct",
        "ip_version": 6
      },
      {
        "outbound": "direct",
        "ip_version": 4
      }
    ]
  }
}

客户端配置(连接 IPv6 节点)

Clash Meta:

YAML
proxies:
  - name: "IPv6-VPS"
    type: vless
    server: "[2001:19f0:xxxx:xxxx::x]"
    port: 443
    uuid: your-uuid-here
    network: ws
    ws-opts:
      path: /secretpath
      headers:
        Host: proxy.example.com
    tls: true
    sni: proxy.example.com

sing-box 客户端:

JSON
{
  "outbounds": [
    {
      "type": "vless",
      "tag": "proxy-out",
      "server": "[2001:19f0:xxxx:xxxx::x]",
      "server_port": 443,
      "uuid": "your-uuid-here",
      "transport": {
        "type": "ws",
        "path": "/secretpath",
        "headers": {
          "Host": "proxy.example.com"
        }
      },
      "tls": {
        "enabled": true,
        "server_name": "proxy.example.com"
      }
    }
  ]
}

📡 第五步:本地 IPv6 连接

方案一:原生 IPv6

如果你的运营商支持 IPv6,直接连接:

BASH
# 检查本地 IPv6 支持
ip addr | grep inet6

# 如果有类似以下输出,说明支持 IPv6:
# inet6 2001:xxxx:xxxx:xxxx::x/64 scope global

# 测试访问 IPv6 网站
curl -6 https://ipv6.google.com

方案二:IPv6 隧道(HE.net)

如果运营商不支持 IPv6,可以使用隧道:

BASH
# 注册 HE.net 账户
# https://tunnelbroker.net/

# 创建隧道
# 选择 IPv4 端点(你的公网 IP)
# 获取隧道信息:
# - Server IPv4 Address
# - Client IPv6 Address (/64)
# - Routed /64

# 配置隧道
apt install radvd

# 创建隧道接口
ip tunnel add he-ipv6 mode sit remote 216.66.80.26 local your-public-ipv4
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

# 配置 DNS
echo "nameserver 2001:4860:4860::8888" >> /etc/resolv.conf

# 测试
ping6 google.com

方案三:WireGuard 隧道

使用 WireGuard 建立 IPv6 隧道:

BASH
# 在 IPv6-only VPS 上配置 WireGuard
cat > /etc/wireguard/wg0.conf << 'EOF'
[Interface]
PrivateKey = vps-private-key
ListenPort = 51820
Address = fd42:42:42::1/64

[Peer]
PublicKey = client-public-key
AllowedIPs = fd42:42:42::2/128
EOF

# 在本地配置 WireGuard
cat > /etc/wireguard/wg0.conf << 'EOF'
[Interface]
PrivateKey = client-private-key
Address = fd42:42:42::2/64

[Peer]
PublicKey = vps-public-key
Endpoint = [vps-ipv6-address]:51820
AllowedIPs = ::/0
EOF

# 启动 WireGuard
wg-quick up wg0

# 测试
ping6 fd42:42:42::1
curl -6 https://google.com

🔒 第六步:安全配置

防火墙配置

BASH
# 使用 UFW
ufw default deny incoming
ufw default allow outgoing

# 允许必要的入站端口
ufw allow in proto tcp from any to any port 443
ufw allow in proto udp from any to any port 51820

# 允许 IPv6
ufw enable

# 使用 iptables(IPv6)
ip6tables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
ip6tables -A INPUT -i lo -j ACCEPT
ip6tables -A INPUT -p tcp --dport 443 -j ACCEPT
ip6tables -A INPUT -p udp --dport 51820 -j ACCEPT
ip6tables -A INPUT -j DROP

SSH 安全

BASH
# 修改 SSH 端口
sed -i 's/Port 22/Port 2222/' /etc/ssh/sshd_config

# 禁用密码登录
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config

# 禁用 root 登录
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config

# 重启 SSH
systemctl restart sshd

Fail2ban

BASH
# 安装 Fail2ban
apt install fail2ban

# 配置
cat > /etc/fail2ban/jail.local << 'EOF'
[sshd]
enabled = true
port = 2222
maxretry = 3
bantime = 3600
EOF

# 启动
systemctl enable --now fail2ban

📊 性能优化

内核参数优化

BASH
cat > /etc/sysctl.d/ipv6-optimizations.conf << 'EOF'
# IPv6 优化
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.all.forwarding = 1
net.ipv6.conf.all.accept_ra = 2

# TCP 优化
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1

# 文件句柄
fs.file-max = 65535
EOF

# 应用配置
sysctl -p /etc/sysctl.d/ipv6-optimizations.conf

NAT64 性能优化

BASH
# 增加 NAT 表大小
echo "net.ipv6.netfilter.ip6t_nat.max_entries = 65535" >> /etc/sysctl.conf

# 增加连接跟踪大小
echo "net.netfilter.nf_conntrack_max = 65535" >> /etc/sysctl.conf

# 增加 TCP 连接数
echo "net.ipv4.tcp_max_syn_backlog = 65535" >> /etc/sysctl.conf

# 应用
sysctl -p

🔍 故障排查

问题 1:无法访问 IPv4 网站

BASH
# 检查 DNS64
dig ipv4.google.com AAAA

# 应返回合成的 IPv6 地址(64:ff9b::xxx)

# 检查 NAT64 服务状态
systemctl status tayga

# 检查路由
ip -6 route

# 检查防火墙
ip6tables -L -n

# 检查 NAT64 前缀
ip -6 addr show | grep 64:ff9b

# 常见原因:
# 1. DNS 没有配置 DNS64
# 2. NAT64 服务没有运行
# 3. 路由配置错误
# 4. 防火墙阻止了流量

问题 2:IPv6 连接缓慢

BASH
# 测试延迟
ping6 -c 10 google.com

# 测试下载速度
curl -6 -o /dev/null -s -w "%{speed_download}\n" https://speed.cloudflare.com/__down?bytes=100000000

# 检查 MTU
ip link show eth0 | grep mtu

# IPv6 推荐 MTU:1500(和 IPv4 一样)

# 检查 TCP 拥塞控制
sysctl net.ipv4.tcp_congestion_control

# 应返回:bbr

# 优化建议:
# 1. 使用 BBR 拥塞控制
# 2. 检查网络路径(mtr6)
# 3. 更换数据中心

问题 3:本地无法连接 IPv6 VPS

BASH
# 检查本地 IPv6 支持
curl -6 ifconfig.co

# 如果失败,说明本地没有 IPv6

# 解决方案:
# 1. 联系运营商开通 IPv6
# 2. 使用 IPv6 隧道(HE.net)
# 3. 使用 WireGuard 隧道
# 4. 使用 Cloudflare Tunnel(通过 IPv4 访问 IPv6 VPS)

# 使用 Cloudflare Tunnel
cloudflared tunnel run --token your-token
# 然后通过 Cloudflare 的域名访问

问题 4:某些网站无法访问

BASH
# 检查是否是 DNS 问题
dig example.com AAAA
dig example.com A

# 如果只有 A 记录(IPv4),应该通过 NAT64 访问

# 检查 NAT64 是否工作
curl -6 http://example.com

# 如果失败,检查:
# 1. NAT64 前缀配置
# 2. DNS64 配置
# 3. 目标网站的 IPv4 可达性

# 某些网站可能阻止 NAT64 流量
# 可以尝试更换 NAT64 前缀或使用公共 NAT64

📋 完整部署检查清单

PLAINTEXT
VPS 购买:
□ 选择 IPv6-only VPS(Vultr/Hetzner)
□ 获取 IPv6 地址和登录信息
□ 选择数据中心(日本/新加坡/美国)

基础配置:
□ 登录服务器(SSH / 控制台)
□ 配置 IPv6 网络
□ 配置 DNS(使用 Google/Cloudflare IPv6 DNS)
□ 测试 IPv6 连通性

NAT64/DNS64 部署:
□ 安装 Tayga(推荐)
□ 配置 NAT64 前缀(64:ff9b::/96)
□ 配置 DNS64 监听
□ 启动服务并设置开机自启
□ 测试访问 IPv4 网站

代理服务配置:
□ 安装 xray/sing-box
□ 配置 IPv6 监听(::)
□ 配置 TLS/WS/gRPC
□ 测试客户端连接

本地连接:
□ 检查本地 IPv6 支持
□ 配置 IPv6 隧道(如需要)
□ 测试连接到 IPv6 VPS

安全配置:
□ 配置防火墙(UFW/iptables)
□ 安全 SSH(改端口、禁用密码)
□ 安装 Fail2ban
□ 更新系统和软件包

性能优化:
□ 启用 BBR 拥塞控制
□ 优化内核参数
□ 监控 CPU/内存/网络使用
□ 测试速度和延迟

结语

IPv6-only VPS 是未来的趋势——更便宜、更安全、更难被封锁。通过 NAT64/DNS64 技术,你可以在享受 IPv6 优势的同时,无缝访问所有 IPv4 资源。

总结要点:

推荐组合方案:

PLAINTEXT
入门用户:
  Vultr IPv6-only VPS + 公共 NAT64(Google)+ xray

进阶用户:
  Hetzner IPv6-only VPS + Tayga NAT64/DNS64 + sing-box

性能用户:
  x86 IPv6-only 服务器 + Jool 内核级 NAT64 + 负载均衡

抗封锁用户:
  多个 IPv6-only VPS + WireGuard 组网 + 自动切换

记住:IPv6 是互联网的未来,现在开始学习和使用,你将走在时代的前沿。

愿你的 IPv6 之旅畅通无阻!🌐

版权声明

作者: 易邦

链接: https://blog.e8k.net/posts/ipv6-only-vps-nat64/

许可证: 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。