内网穿透(反向代理)
内网穿透,反向代理
·
v2ray内网穿透
服务器A,B,C描述
# 服务器A,内网主机,提供服务如,存储,http,等等
# 服务器B,中转转发主机,需要公网IP,本文公网IP,134.134.134.134
# 服务器C,客户端,如自己正在使用的电脑
流量大致走向
# 服务器C,访问服务器B,服务器B会把流量全部转发到A
单个端口的内网穿透
A的配置
{
"reverse":{
#// 这是 A 的反向代理设置,必须有下面的 bridges 对象
"bridges":[
{
"tag":"bridge", #// 关于 A 的反向代理标签,在路由中会用到
"domain":"private.cloud.com" #// A 和 B 反向代理通信的域名,可以自己取一个,可以不是自己购买的域名,但必须跟下面 B 中的 reverse 配置的域名一致
}
]
},
"outbounds": [
{
#//A连接B的outbound
"tag":"tunnel", #// A 连接 B 的 outbound 的标签,在路由中会用到
"protocol":"vmess",
"settings":{
"vnext":[
{
"address":"134.134.134.134", #// B 地址,IP 或 实际的域名
"port":16823,
"users":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
]
}
},
#// 另一个 outbound,最终连接私有网盘
{
"protocol":"freedom",
"settings":{
},
"tag":"out"
}
],
"routing":{
"rules":[
{
#// 配置 A 主动连接 B 的路由规则
"type":"field",
"inboundTag":[
"bridge"
],
"domain":[
"full:private.cloud.com"
],
"outboundTag":"tunnel"
},
{
#// 反向连接访问私有网盘的规则
"type":"field",
"inboundTag":[
"bridge"
],
"outboundTag":"out"
}
]
}
}
B的配置
{
"reverse":{ #//这是 B 的反向代理设置,必须有下面的 portals 对象
"portals":[
{
"tag":"portal",
"domain":"private.cloud.com" #// 必须和上面 A 设定的域名一样
}
]
},
"inbounds": [
{
#// 接受 C 的inbound
"tag":"external", #// 标签,路由中用到
"port":8880,
#// 开放 80 端口,用于接收外部的 HTTP 访问
"protocol":"dokodemo-door",
"settings":{
"address":"127.0.0.1",
"port":8880, #//假设 NAS 监听的端口为 80
"network":"tcp"
}
},
#// 另一个 inbound,接受 A 主动发起的请求
{
"tag": "tunnel",#// 标签,路由中用到
"port":16823,
"protocol":"vmess",
"settings":{
"clients":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
}
],
"routing":{
"rules":[
{ #//路由规则,接收 C 请求后发给 A
"type":"field",
"inboundTag":[
"external"
],
"outboundTag":"portal"
},
{ #//路由规则,让 B 能够识别这是 A 主动发起的反向代理连接
"type":"field",
"inboundTag":[
"tunnel"
],
"domain":[
"full:private.cloud.com"
],
"outboundTag":"portal"
}
]
}
}
运行并测试
# 服务器A开一个网页
# python3 -m http.server 8880
# 服务器A,运行v2ray
# 服务器B,运行v2ray进行流量转发
# 服务器C使用浏览器访问服务器B的8880端口
或者
curl http://127.0.0.1:8880
整体的内网穿透
# 不局限于某个或某几个端口,相当于C的所有网络都是A的网络
# C就相当于A
A的配置
{
"reverse":{
#// 这是 A 的反向代理设置,必须有下面的 bridges 对象
"bridges":[
{
"tag":"bridge", #// 关于 A 的反向代理标签,在路由中会用到
"domain":"pc1.localhost" #// 一个域名,用于标识反向代理的流量,不必真实存在,但必须跟下面 B 中的 reverse 配置的域名一致
}
]
},
"outbounds":[
{
#//A连接B的outbound
"tag":"tunnel", #// A 连接 B的 outbound 的标签,在路由中会用到
"protocol":"vmess",
"settings":{
"vnext":[
{
"address":"134.134.134.134", #// B 地址,IP 或 实际的域名
"port":16823,
"users":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
]
}
},
#// 另一个 outbound,最终连接私有网盘
{
"protocol":"freedom",
"settings":{
},
"tag":"out"
}
],
"routing":{
"rules":[
{
#// 配置 A 主动连接 B 的路由规则
"type":"field",
"inboundTag":[
"bridge"
],
"domain":[
"full:pc1.localhost"
],
"outboundTag":"tunnel"
},
{
#// 反向连接访问私有网盘的规则
"type":"field",
"inboundTag":[
"bridge"
],
"outboundTag":"out"
}
]
}
}
B的配置
{
"reverse":{ #//这是 B 的反向代理设置,必须有下面的 portals 对象
"portals":[
{
"tag":"portal",
"domain":"pc1.localhost" #// 必须和上面 A 设定的域名一样
}
]
},
"inbounds":[
{
#// 接受 C 的inbound
"tag":"tunnel", #// 标签,路由中用到
"port":11872,
"protocol":"vmess",
"settings":{
"clients":[
{
"id":"a26efdb8-ef34-4278-a4e6-2af32cc010aa",
"alterId":64
}
]
}
},
#// 另一个 inbound,接受 A 主动发起的请求
{
"tag": "interconn", #// 标签,路由中用到
"port":16823,
"protocol":"vmess",
"settings":{
"clients":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
}
],
"routing":{
"rules":[
{ #//路由规则,接收 C 的请求后发给 A
"type":"field",
"inboundTag":[
"interconn"
],
"outboundTag":"portal"
},
{ #//路由规则,让 B 能够识别这是 A 主动发起的反向代理连接
"type":"field",
"inboundTag":[
"tunnel"
],
"domain":[
#"full:private.cloud.com" // 将指定域名的请求发给 A,如果希望将全部流量发给 A,这里可以不设置域名规则。
""
],
"outboundTag":"portal"
}
]
}
}
C的配置
{
"inbounds": [
{
"port": 10080, // 监听端口
"protocol": "socks", // 入口协议为 SOCKS 5
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"auth": "noauth" //socks的认证设置,noauth 代表不认证,由于 socks 通常在客户端使用,所以这里不认证
}
}
],
"outbounds": [
{
"protocol": "vmess", #// 出口协议
"settings": {
"vnext": [
{
"address": "134.134.134.134", #// 服务器地址,请修改为你自己的服务器 IP 或域名
"port": 11872, #// 服务器端口
"users": [
{
"id": "a26efdb8-ef34-4278-a4e6-2af32cc010aa", #// 用户 ID,必须与服务器端配置相同
"alterId": 64 #// 此处的值也应当与服务器相同
}
]
}
]
}
}
]
}
运行并测试
# 服务器A运行v2ray
# 服务器B运行v2ray
# 服务器C运行v2ray,并将10080设置为全局代理,让后访问127.0.0.1:8880
export all_proxy=socks5://127.0.0.1:10080
curl http://127.0.0.1:8880
更多推荐

所有评论(0)