使用v2ray反向代理进行内网穿透

3371

前言

因为家里有台nas遂想在外网条件下也能够访问,目前能够折腾的就是DDNS、反向代理进行内网穿透,最后发现v2ray带有反向代理功能,然后进行配置实现了内网穿透,特将配置文件作记录。假设有3个设备:A(nas)、B(服务器)、C(要外网访问nas的设备)。

NAS端

{
    "log": {
        "loglevel": "info", 
        "access": "", 
        "error": ""
    }, 
    "reverse": {
        "bridges": [
            {
                "tag": "bridge", 
                "domain": "A 和 B 反向代理通信的域名,可以自己取一个,可以不是自己购买的域名,但必须跟下面 B 中的 reverse 配置的域名一致"
            }
        ]
    }, 
    "outbounds": [
        {
            "tag": "tunnel", 
            "protocol": "vmess", 
            "settings": {
                "vnext": [
                    {
                        "address": "服务端ip或者域名", 
                        "port": 暴露的端口, 
                        "users": [
                            {
                                "id": "服务端uuid", 
                                "alterId": 64
                            }
                        ]
                    }
                ]
            }
        }, 
        {
            "protocol": "freedom", 
            "settings": {
                "redirect": "内网nas的地址和端口"
            }, 
            "tag": "out"
        }
    ], 
    "routing": {
        "rules": [
            {
                "type": "field", 
                "inboundTag": [
                    "bridge"
                ], 
                "domain": [
                    "full:和上面的域名保持一致"
                ], 
                "outboundTag": "tunnel"
            }, 
            {
                "type": "field", 
                "inboundTag": [
                    "bridge"
                ], 
                "outboundTag": "out"
            }
        ]
    }
}

服务器端

{
  "log":{
    "loglevel": "info",
    "access": "日志放的地址",
    "error": "日志放的地址"
  },
  "reverse":{
    "portals":[
      {
        "tag":"portal",
        "domain":"必须和上面 A 设定的域名一样"
      }
    ]
  },
  "inbounds":[
    {
      "tag":"external",
      "port":接收C发来的请求的端口,可用nginx做转发,
      "protocol":"dokodemo-door",
        "settings":{
          "address":"nas内网地址",
          "port":nas内网端口,
          "network":"tcp"
        }
    },
    {
      "tag": "tunnel",
      "port":A主动连接B用的端口,
      "protocol":"vmess",
      "settings":{
        "clients":[
          {
            "id":"服务器端配置的uuid",
            "alterId":64
          }
        ]
      }
    }
  ],
  "routing":{
    "rules":[
      {
        "type":"field",
        "inboundTag":[
          "external"
        ],
        "outboundTag":"portal"
      },
      {
        "type":"field",
        "inboundTag":[
          "tunnel"
        ],
        "domain":[
          "full:和上面一致的域名"
        ],
        "outboundTag":"portal"
      }
    ]
  }
}

参考