使用V2R做反向代理內網穿透
阿新 • • 發佈:2020-07-20
環境
內網伺服器Prob1位於內網LAN1,
內網伺服器Prob2位於內網LAN2,
外網伺服器Serv1位於IP 123.123.123.123
內網節點配置
內網節點沒有inbound,只需要配置一個reverse,一個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":50103, "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" } ] } }
外網服務節點配置
外網伺服器沒有outbound,對應每個內網節點,要配置一個portal,一對inbound和一對路由規則。在這種規則配置下,對應每一個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":50100, "protocol":"vmess", "settings":{ "clients":[ { "id":"234ffdb8-ef14-4278-a4e6-2af32cc312cf", "alterId":64 } ] } }, { "tag": "tunnel_probe2", "port":50101, "protocol":"vmess", "settings":{ "clients":[ { "id":"3301381f-6324-4d53-ad4f-1cda48b3012f", "alterId":64 } ] } }, { "tag":"to_probe1", "port":50102, "protocol":"vmess", "settings":{ "clients":[ { "id":"a11efdb8-ef34-4278-a4e6-2af32cc010fc", "alterId":64 } ] } }, { "tag": "tunnel_probe1", "port":50103, "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"], "domain":["full:probe2.nowhere.com"], "outboundTag":"portal_probe2" }, { "type":"field", "inboundTag":["to_probe1"], "outboundTag":"portal_probe1" }, { "type":"field", "inboundTag":["tunnel_probe1"], "domain":["full:probe1.nowhere.com"], "outboundTag":"portal_probe1" } ] } }
建立服務
對於已經運行了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 命令加入開機自啟動