Xray配置 TCP 链式代理 实践

需求

如果你需要跑什么业务, 出口IP很重要, 比如是海外的一个家宽IP.

而从你本地到这个节点的速度太慢.

你想到之前嫖Cloudflare的worker搭出来的节点速度不错, 只是出口IP总是乱跳.

那么把这两者结合起来, 搭一个链式代理.


思路

(1) 先搭一个隧道, 在本地的入口是Socks5, 比如, 127.0.0.1 : 10086

(2) 然后让本地翻墙客户端配置下一跳是这个Socks, 而不是原来的那样走 Freedom 地出去.

(3) 浏览器等实际应用就把第2步的翻墙软件像你平时一样地使用, 比如使用它的Socks5代理或者HTTP代理.


第(1)步用现有的翻墙客户端就可以实现, 比如, v2rayN.

第(2)步功能v2rayN没有支持, 可以自己稍微修改一下v2rayN生成的配置文件, 然后直接运行v2ray.exe


方案一 ProxySettings (失败)

如果使用 ProxySettings 指定 下一跳的 tag, 下一跳为 Socks5

config.json 文件类似下面这样

{
  "log": {
    "access": "",
    "error": "",
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "tag": "socks",
      "port": 10818,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ],
        "routeOnly": false
      },
      "settings": {
        "auth": "noauth",
        "udp": true,
        "allowTransparent": false
      }
    },
    {
      "tag": "http",
      "port": 10819,
      "listen": "127.0.0.1",
      "protocol": "http",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ],
        "routeOnly": false
      },
      "settings": {
        "auth": "noauth",
        "udp": true,
        "allowTransparent": false
      }
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "mci.ircf.space",
            "port": 443,
            "users": [
              {
                "id": "4804f14b-1234-452d-a6ec-eff1490aeac9",
                "alterId": 0,
                "email": "t@t.tt",
                "security": "auto"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "tlsSettings": {
          "allowInsecure": false,
          "serverName": "hdfy6c4.foriran.trade",
          "show": false
        },
        "wsSettings": {
          "path": "/lRkGCkYS9X51234YMWXN7kCm3lL",
          "headers": {
            "Host": "hdfy6c4.foriran.trade"
          }
        }
      },
      "ProxySettings": {
        "tag": "tunnel"
      },
      "mux": {
        "enabled": false,
        "concurrency": -1
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      }
    },
    {
      "tag": "tunnel",
      "protocol": "socks",
      "settings": {
        "servers": [
          {
            "address": "127.0.0.1",
            "port": 10086
          }
        ]
      }
    }
  ],
  "dns": {
    "servers": [
      "1.1.1.1",
      "8.8.8.8"
    ]
  },
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api"
      },
      {
        "type": "field",
        "port": "0-65535",
        "outboundTag": "proxy"
      }
    ]
  }
}

实测

跑不通.


方案二 sockopt 的 dialerProxy (成功)

如果在 streamSettings 里面, sockopt 里面, 设置 dialerProxy 为下一跳的 tag,  下一跳为 Socks5

config.json 文件类似下面这样

{
  "log": {
    "access": "",
    "error": "",
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "tag": "socks",
      "port": 10808,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ],
        "routeOnly": false
      },
      "settings": {
        "auth": "noauth",
        "udp": true,
        "allowTransparent": false
      }
    },
    {
      "tag": "http",
      "port": 10809,
      "listen": "127.0.0.1",
      "protocol": "http",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ],
        "routeOnly": false
      },
      "settings": {
        "auth": "noauth",
        "udp": true,
        "allowTransparent": false
      }
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "mci.ircf.space",
            "port": 443,
            "users": [
              {
                "id": "4804f14b-1234-452d-a6ec-eff1490aeac9",
                "alterId": 0,
                "email": "t@t.tt",
                "security": "auto"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "tlsSettings": {
          "allowInsecure": false,
          "serverName": "hdfy6c4.foriran.trade",
          "show": false
        },
        "wsSettings": {
          "path": "/lRkGCkYS91234NJYMWXN7kCm3lL",
          "headers": {
            "Host": "hdfy6c4.foriran.trade"
          }
        },
        "sockopt": {
          "dialerProxy": "tunnel"
        }
      },
      "mux": {
        "enabled": false,
        "concurrency": -1
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      }
    },
    {
      "tag": "tunnel",
      "protocol": "socks",
      "settings": {
        "servers": [
          {
            "address": "127.0.0.1",
            "ota": false,
            "port": 10086,
            "level": 0
          }
        ]
      }
    }
  ],
  "dns": {
    "servers": [
      "1.1.1.1",
      "8.8.8.8"
    ]
  },
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api"
      },
      {
        "type": "field",
        "port": "0-65535",
        "outboundTag": "proxy"
      }
    ]
  }
}

不要看到配置文件这么长被吓到了, 实际上, 你可以找到v2rayN生成的配置文件config.json, 然后自己修改一点点就行了.



实测

落地节点 如果搭的 Reality协议, 不通.

落地节点 如果用的 Websocket, (不管是 Vmess 还是 VLESS; 不管是不是 Tls) 都是通的.

落地节点 如果用的 TCP 协议, 比如 Vmess + TCP, 是通的.

隧道节点, 不管用的什么协议都可以.


实现在 v2rayN 上面的实例

演示视频 


评论

The Hot3 in Last 30 Days

无服务器 自建短链服务 Url-Shorten-Worker 完整的部署教程

ClouDNS .asia免费域名 托管到CloudFlare开CDN白嫖Websocket WS通道翻墙 / desec.io