1. 准备与购买(概要)
- 在五域通达控制台选择台湾节点的 VPS,建议选 Ubuntu 22.04 LTS 或 Debian 11。
- 选择带独立公网 IPv4 的实例;若有控制台安全组/防火墙,确认可放行自定义端口。
- 准备本地 SSH 密钥(ssh-keygen),记下 root 临时密码或控制台密钥注入方法。
2. 首次登录与系统初始化
- 使用 SSH 登录:ssh root@<你的VPSIP>(若非默认端口请相应调整)。
- 更新系统:apt update && apt upgrade -y。设置时区:timedatectl set-timezone Asia/Taipei。
- 创建非 root 用户并授权 sudo:adduser youruser; usermod -aG sudo youruser。
3. SSH 安全化
- 上传公钥到 /home/youruser/.ssh/authorized_keys,设置权限:chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys。
- 编辑 /etc/ssh/sshd_config:禁用密码登录 PasswordAuthentication no,改端口 Port 2222(可选),重启 sshd systemctl restart sshd。
4. 防火墙与内核转发设置
- 安装并启用 UFW:apt install ufw -y。允许 SSH 和 WireGuard:ufw allow 2222/tcp; ufw allow 51820/udp。
- 打开 IP 转发:echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && sysctl -p。
5. 安装 WireGuard(推荐用于稳定低延迟)
- 安装:apt install wireguard -y。生成密钥对:wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key。
- 设置权限:chmod 600 /etc/wireguard/server_private.key。
6. 配置服务器端 wg0.conf
- 创建 /etc/wireguard/wg0.conf 示例:
[Interface]
Address = 10.10.0.1/24
ListenPort = 51820
PrivateKey = (server_private_key)
PostUp = iptables -t nat -A POSTROUTING -s 10.10.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s 10.10.0.0/24 -o eth0 -j MASQUERADE
- eth0 如非默认请替换为实际出口网卡名称(ip a 查看)。
7. 启动与持久化
- 启用并启动:systemctl enable wg-quick@wg0 && systemctl start wg-quick@wg0。
- 检查状态:wg show;如报错查看 journalctl -u wg-quick@wg0 -e。
8. 客户端配置(以 Windows / Linux / 手机为例)
- 生成客户端密钥:wg genkey | tee client_private.key | wg pubkey > client_public.key。
- 客户端配置示例:
[Interface]
PrivateKey = (client_private)
Address = 10.10.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = (server_public)
Endpoint = your.vps.ip:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
9. 将客户端公钥加入服务器
- 在服务器 wg0.conf 中添加 Peer:
[Peer]
PublicKey = (client_public)
AllowedIPs = 10.10.0.2/32
- 然后重启 wg:systemctl restart wg-quick@wg0 或使用 wg set 添加即时生效。
10. NAT 与 路由问题排查
- 若客户端无法访问外网,检查 iptables MASQUERADE 是否生效:iptables -t nat -L -n -v。
- 若仅内网可通,确认 UFW 是否允许转发:编辑 /etc/default/ufw 将 DEFAULT_FORWARD_POLICY="ACCEPT"。
11. 域名、TLS 与反向代理(可选)
- 如要通过域名访问服务,在 DNS 添加 A 记录指向 VPS。
- 安装 nginx 与 certbot:apt install nginx certbot python3-certbot-nginx -y,使用 certbot --nginx 获取 TLS 证书并配置反代。
12. 性能与稳定性调优
- MTU 调优:若出现分片或断流,客户端试着将 MTU 降到 1420 或 1380。
- PersistentKeepalive 保持穿透(尤其客户端在 NAT 背后)。定期检查 wg 接口数据包丢失与延迟。
13. 监控与日志
- 安装基础监控:apt install htop vnstat iftop -y,使用 wg show peers 与 systemctl 查看链接状态。
- 可部署简单脚本监控 WireGuard 在线状态并通过邮件或 webhook 报警。
14. 五域通达控制台相关注意事项
- 在五域通达面板确认安全组/防火墙规则允许你配置的端口(SSH/WireGuard/HTTP)。
- 若遇到网络限速、端口被屏蔽或反向路由问题,联系五域通达客服请求确认节点出口策略或开通公网端口。
15. 备份与恢复建议
- 备份 /etc/wireguard、server_private.key 和 wg0.conf 到安全位置(不要公开私钥)。
- 可使用脚本自动导出客户端配置并在 VPS 损坏时快速恢复。
16. 常见故障与排查小结
- 无法连接:检查 VPS 防火墙与控制台安全组、WireGuard 服务状态、端口是否被 ISP/节点拦截。
- 只有局域访问:检查 NAT/iptables、DEFAULT_FORWARD_POLICY、sysctl ip_forward。
17. 问:使用五域通达台湾 VPS 做跨境通道合法合规吗?
- 回答:合规性取决于你访问的内容和用途。技术上可以搭建,但请遵守目的地与本地法律法规以及五域通达的服务条款,避免用于违法行为。
18. 问:如何保证连接稳定,减少丢包与延迟?
- 回答:选择离目标最近的台湾节点、使用 WireGuard、调节 MTU、启用 PersistentKeepalive 并监控链路。必要时与五域通达沟通更换或优化出口链路。
19. 问:如果需要 HTTP/HTTPS 的复用与多域名访问怎么做?
- 回答:在 VPS 上部署 nginx 反向代理并使用 certbot 获取 Let’s Encrypt 证书,反代到内部服务;若希望通过同一通道分流流量,可结合端口转发或 SNI 转发实现多域名托管。
来源:如何利用五域通达台湾vps构建稳定的跨境访问通道