天天看點

使用V2R做反向代理内網穿透

環境

内網伺服器Prob1位于内網LAN1,

内網伺服器Prob2位于内網LAN2,

外網伺服器Serv1位于IP 123.123.123.123

内網節點配置

内網節點沒有inbound,隻需要配置一個bridge,一個outbound(以及預設的direct),一對路由規則

Prob1

{
  "log": {
    "loglevel": "debug",
    "access": "/var/log/v2r_tunnel_access.log",
    "error": "/var/log/v2r_tunnel_error.log"
  },
  "reverse":{
    "bridges":[
      {
        "tag":"bridge",
        "domain":"probe1.nowhere.com"
      }
    ]
  },
  "outbounds": [
    {
      "tag":"tunnel",
      "protocol":"vmess",
      "settings":{
        "vnext":[
          {
            "address":"123.123.123.123",
            "port":10103,
            "users":[
              {
                "id":"3301381f-6324-4d53-ad4f-1cda48b3012f",
                "alterId":64
              }
            ]
          }
        ]
      }
    },
    {
      "tag":"direct",
      "protocol":"freedom",
      "settings":{}
    }
  ],
  "routing":{
    "rules":[
      {
        "type":"field",
        "inboundTag":["bridge"],
        "domain":["full:probe1.nowhere.com"],
        "outboundTag":"tunnel"
      },
      {
        "type":"field",
        "inboundTag":["bridge"],
        "outboundTag":"direct"
      }
    ]
  }
}
           

配置說明

bridge中的domain,必須要存在于伺服器的portal中,否則會報failed to process reverse connection的錯誤

2020/07/20 17:43:41 [Info] [4068778249] v2r.com/core/proxy/vmess/inbound: received request for tcp:aaa.nowhere.com:0
2020/07/20 17:43:41 [Info] [4068778249] v2r.com/core/app/dispatcher: taking detour [portal_bridge02] for [tcp:aaa.nowhere.com:0]
2020/07/20 17:43:41 [Info] [4068778249] v2r.com/core/app/reverse: failed to process reverse connection > v2r.com/core/app/reverse: empty worker list
2020/07/20 17:43:41 [Info] [4068778249] v2r.com/core/app/proxyman/inbound: connection ends > v2r.com/core/proxy/vmess/inbound: connection ends > io: read/write on closed pipe
           

公網服務節點配置

外網伺服器沒有outbound,對應每個内網節點,要配置一個portal,一對inbound(分别對應bridge和client)和一對路由規則。規則中不需要再設定domain。

在這種規則配置下,對應每一個protal,會有一個專門的inbound連接配接,友善使用者端選擇使用不同的内網。

{
  "log": {
    "loglevel": "debug",
    "access": "/var/log/v2r_access.log",
    "error": "/var/log/v2r_error.log"
  },
  "reverse":{
    "portals":[
      {
        "tag":"portal_probe2",
        "domain":"probe2.nowhere.com"
      },
      {
        "tag":"portal_probe1",
        "domain":"probe1.nowhere.com"
      }
    ]
  },
  "inbounds":[
    {
      "tag":"to_probe2",
      "port":10100,
      "protocol":"vmess",
      "settings":{
        "clients":[
          {
            "id":"234ffdb8-ef14-4278-a4e6-2af32cc312cf",
            "alterId":64
          }
        ]
      }
    },
    {
      "tag": "tunnel_probe2",
      "port":10101,
      "protocol":"vmess",
      "settings":{
        "clients":[
          {
            "id":"3301381f-6324-4d53-ad4f-1cda48b3012f",
            "alterId":64
          }
        ]
      }
    },
 
    {
      "tag":"to_probe1",
      "port":10102,
      "protocol":"vmess",
      "settings":{
        "clients":[
          {
            "id":"a11efdb8-ef34-4278-a4e6-2af32cc010fc",
            "alterId":64
          }
        ]
      }
    },
    {
      "tag": "tunnel_probe1",
      "port":10103,
      "protocol":"vmess",
      "settings":{
        "clients":[
          {
            "id":"3301381f-6324-4d53-ad4f-1cda48b3012f",
            "alterId":64
          }
        ]
      }
    }
 
  ],
  "routing":{
    "rules":[
      {
        "type":"field",
        "inboundTag":["to_probe2"],
        "outboundTag":"portal_probe2"
      },
      {
        "type":"field",
        "inboundTag":["tunnel_probe2"],
        "outboundTag":"portal_probe2"
      },
 
      {
        "type":"field",
        "inboundTag":["to_probe1"],
        "outboundTag":"portal_probe1"
      },
      {
        "type":"field",
        "inboundTag":["tunnel_probe1"],
        "outboundTag":"portal_probe1"
      }
    ]
  }
}
           
...
    {
      "tag":"client_bridge02",
      "port":10102,
      "protocol":"vmess",
      "settings":{
        ...
      }
    },
# 添加的socks入口
    {
       "tag": "socks_bridge02",
       "port": 10200,
       "listen": "192.168.10.20",
       "protocol": "socks",
       "settings": {
         "udp": true
       }
    },
#
    {
      "tag": "tunnel_bridge02",
      "port":10103,
      "protocol":"vmess",
      "settings":{
        ...
      }
    },
...
 
  "routing":{
    "rules":[
      ...
      {
        "type":"field",
        "inboundTag":["client_bridge02","socks_bridge02"], # 将socks_bridge02添加到inboundTag
        "outboundTag":"portal_bridge02"
      },
      ...
           

建立服務

$ more /etc/systemd/system/v2r-tunnel.service
[Unit]
Description=V2R Tunnel Service
Documentation=https://www.v2r.com/
After=network.target nss-lookup.target
 
[Service]
Type=simple
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/bin/v2r/v2r -config /etc/v2r/config_tunnel.json
Restart=on-failure
 
[Install]
WantedBy=multi-user.target
           

附安裝記錄(arm64)

apt install lrzsz
rz
chmod u+x go.sh
./go.sh --version v4.26.0 --local v2r-linux-arm64.4.26.0.zip
systemctl is-enabled v2r.service
cd /etc/v2r/
rz
vi config-lan.json
rm config.json
mv config-lan.json config.json
systemctl start v2r.service
ps aux|grep v2r
tail -f /var/log/v2r_tunnel_error.log
           

繼續閱讀