大部分情况下,我们的VPS-A和VPS-B不在同一个内网,分别位于两个国家的机房

这种情况下,之前的iptables转发方案仍然可用,但需要把“内网IP”换成VPS-B的公网IP。不过需要注意,这样一来流量会走公网,速度和稳定性会受跨国网络影响。但有时候这是不得不采用的方案。

我们来分析三种可行方案,并给出对比推荐。


🌍 方案对比(跨国家中转)

方案 原理 优点 缺点 推荐度
方案一:iptables公网转发 VPS-A直接转发到VPS-B公网IP 配置简单,无需额外软件 流量明文,VPS-A到VPS-B这段暴露 ⭐⭐⭐
方案二:VPS-A部署代理客户端 VPS-A用代理协议转发(如Reality链式) 全程加密,两层伪装 配置稍复杂 ⭐⭐⭐⭐⭐
方案三:GRE/IPIP隧道 建立三层隧道,模拟内网 透明转发,可配合iptables 配置复杂,部分机房封禁GRE ⭐⭐

✅ 推荐方案:VPS-A上部署sing-box客户端(全程加密)

这是最安全、最适合当前情况下的方案。让VPS-A作为“跳板机”,用sing-box客户端连接VPS-B的Reality服务,然后在VPS-A上开一个本地SOCKS5或TUN代理给电脑用。

📍 架构图

1
2
3
4
5
6
7
你的电脑 
↓ (连接VPS-A:1080, SOCKS5)
VPS-A (中转节点,公网IP)
↓ (sing-box客户端,用REALITY协议加密连接)
VPS-B (落地节点,公网IP,REALITY服务端)

目标网站

🔧 配置步骤

第一步:在VPS-B上确认已有REALITY服务

VPS-B配置:

  • 端口:30446
  • UUID:d231faea-f47e-4622-bb9e-27861ee385c4
  • 公钥:RLYlyld_aOkt5ZO95D...(完整版)
  • SNI:www.paypal.com

第二步:在VPS-A上安装sing-box并配置客户端

1. 安装sing-box(使用233boy脚本):

1
bash <(curl -Ls https://raw.githubusercontent.com/233boy/sing-box/main/install.sh)

2. 手动创建出站配置文件(因为脚本主要用来做服务端,客户端配置需要手写):

创建 /root/sing-box-client-config.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
"log": {
"level": "info",
"output": "/root/sing-box-client.log"
},
"inbounds": [
{
"type": "socks",
"tag": "socks-in",
"listen": "0.0.0.0",
"listen_port": 1080,
"users": [
{
"username": "your_username",
"password": "your_password"
}
]
}
],
"outbounds": [
{
"type": "vless",
"tag": "reality-out",
"server": "VPS-B的公网IP",
"server_port": 30446,
"uuid": "d231faea-f47e-4622-bb9e-27861ee385c4",
"flow": "xtls-rprx-vision",
"tls": {
"enabled": true,
"server_name": "www.paypal.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "RLYlyld_aOkt5ZO95DxxxxxxxxxxxxxxDEixO636KNnpRSE"
}
}
}
],
"route": {
"rules": [
{
"inbound": "socks-in",
"outbound": "reality-out"
}
]
}
}

3. 启动sing-box客户端:

1
sing-box run -c /root/sing-box-client-config.json

后台运行(推荐使用screen或systemd):

1
2
3
4
# 使用screen
screen -S singbox
sing-box run -c /root/sing-box-client-config.json
# 按 Ctrl+A 再按 D 退出screen

第三步:电脑连接

电脑上任何支持SOCKS5代理的软件(如nekoray、Clash、浏览器SwitchyOmega),配置:

  • 代理类型:SOCKS5
  • 服务器:VPS-A的公网IP
  • 端口:1080
  • 用户名/密码:你在配置文件中设置的

🔄 简化版(如果不需要VPS-A做其他用途)

如果VPS-A单纯就是为了转发流量,可以用更轻量的 gost 工具,它支持TLS加密转发。

使用gost加密转发

在VPS-B上(服务端):

1
2
3
4
5
6
7
8
# 安装gost
wget https://github.com/ginuerzh/gost/releases/download/v2.11.5/gost-linux-amd64-2.11.5.gz
gunzip gost-linux-amd64-2.11.5.gz
chmod +x gost-linux-amd64-2.11.5
mv gost-linux-amd64-2.11.5 /usr/local/bin/gost

# 启动服务端(监听8080,转发到本地30446的REALITY服务)
gost -L=tls://:8443?auth=user:pass -F=forward://127.0.0.1:30446

在VPS-A上(客户端):

1
2
# 启动客户端,接收本地1080的SOCKS5,通过TLS加密转发到VPS-B
gost -L=socks5://:1080 -F=tls://VPS-B公网IP:8443?auth=user:pass

电脑连接VPS-A的1080端口即可。


💎 最终建议

你的技术水平 推荐方案 理由
会改配置 VPS-A部署sing-box客户端 全程REALITY加密,两层伪装,最安全
想要简单 使用gost加密转发 一条命令搞定,也有TLS加密
追求速度 iptables公网直转 最简单,但VPS-A到VPS-B这段是明文

考虑到当前情况,应“避免直连”和“抗封锁”,推荐使用方案一(VPS-A部署sing-box客户端)。这样即使跨国这段链路上有监控,看到的也是另一层REALITY加密流量,无法识别真实目的。