环境

内网服务器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"
      }
    ]
  }
}

如果想在当前节点也创建socks5代理, 可以在inbounds里添加一个socks, 然后再添加到routing.rules, 例如

...
    {
      "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"
      },
      ...

创建服务

对于已经运行了v2r的机器,可以再创建一个新的服务,例如

$ 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

通过systemctl enable 命令加入开机自启动

附安装记录(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