v2ray内网穿透
服务器A,B,C描述
# 服务器A,内网主机,提供服务如,存储,http,等等
# 服务器B,中转转发主机,需要公网IP,本文公网IP,134.134.134.134
# 服务器C,客户端,如自己正在使用的电脑
流量大致走向
# 服务器C,访问服务器B,服务器B会把流量全部转发到A
单个端口的内网穿透
A的配置
{
"reverse":{
#
"bridges":[
{
"tag":"bridge", #
"domain":"private.cloud.com" #
}
]
},
"outbounds": [
{
#
"tag":"tunnel", #
"protocol":"vmess",
"settings":{
"vnext":[
{
"address":"134.134.134.134", #
"port":16823,
"users":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
]
}
},
#
{
"protocol":"freedom",
"settings":{
},
"tag":"out"
}
],
"routing":{
"rules":[
{
#
"type":"field",
"inboundTag":[
"bridge"
],
"domain":[
"full:private.cloud.com"
],
"outboundTag":"tunnel"
},
{
#
"type":"field",
"inboundTag":[
"bridge"
],
"outboundTag":"out"
}
]
}
}
B的配置
{
"reverse":{ #
"portals":[
{
"tag":"portal",
"domain":"private.cloud.com" #
}
]
},
"inbounds": [
{
#
"tag":"external", #
"port":8880,
#
"protocol":"dokodemo-door",
"settings":{
"address":"127.0.0.1",
"port":8880, #
"network":"tcp"
}
},
#
{
"tag": "tunnel",#
"port":16823,
"protocol":"vmess",
"settings":{
"clients":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
}
],
"routing":{
"rules":[
{ #
"type":"field",
"inboundTag":[
"external"
],
"outboundTag":"portal"
},
{ #
"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":{
#
"bridges":[
{
"tag":"bridge", #
"domain":"pc1.localhost" #
}
]
},
"outbounds":[
{
#
"tag":"tunnel", #
"protocol":"vmess",
"settings":{
"vnext":[
{
"address":"134.134.134.134", #
"port":16823,
"users":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
]
}
},
#
{
"protocol":"freedom",
"settings":{
},
"tag":"out"
}
],
"routing":{
"rules":[
{
#
"type":"field",
"inboundTag":[
"bridge"
],
"domain":[
"full:pc1.localhost"
],
"outboundTag":"tunnel"
},
{
#
"type":"field",
"inboundTag":[
"bridge"
],
"outboundTag":"out"
}
]
}
}
B的配置
{
"reverse":{ #
"portals":[
{
"tag":"portal",
"domain":"pc1.localhost" #
}
]
},
"inbounds":[
{
#
"tag":"tunnel", #
"port":11872,
"protocol":"vmess",
"settings":{
"clients":[
{
"id":"a26efdb8-ef34-4278-a4e6-2af32cc010aa",
"alterId":64
}
]
}
},
#
{
"tag": "interconn", #
"port":16823,
"protocol":"vmess",
"settings":{
"clients":[
{
"id":"b831381d-6324-4d53-ad4f-8cda48b30811",
"alterId":64
}
]
}
}
],
"routing":{
"rules":[
{ #
"type":"field",
"inboundTag":[
"interconn"
],
"outboundTag":"portal"
},
{ #
"type":"field",
"inboundTag":[
"tunnel"
],
"domain":[
#"full:private.cloud.com"
""
],
"outboundTag":"portal"
}
]
}
}
C的配置
{
"inbounds": [
{
"port": 10080,
"protocol": "socks",
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"settings": {
"auth": "noauth"
}
}
],
"outbounds": [
{
"protocol": "vmess", #
"settings": {
"vnext": [
{
"address": "134.134.134.134", #
"port": 11872, #
"users": [
{
"id": "a26efdb8-ef34-4278-a4e6-2af32cc010aa", #
"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