Xray + Sing-box TUN
Closed this issue · 4 comments
Hi.
Since Xray-Core does not provied a tun/tap inbound, it's a little tricky to forward all the traffic to xray (I know about tun2socks
).
But I have an idea to setup tun device with sing-box
and forward traffic to local socks5 proxy provided by xray-core
.
On my phone I can exclude V2rayNG app in pre-app proxy section in Nekobox app. Then I set V2rayNG to proxy-mode
and connect to socks5://localhost:10808
proxy in Nekobox and it's working while Nekobox is in vpn-mode. I wonder how I can achive something similar to this in my linux pc.
I wrote this configurations but they don't work at all. I know something is wrong here but I could not figure it out.
Is this even possible? If yes, how we can achive this?
Thank you!
Xray Config:
{
"dns": {
"hosts": {
"geosite:ads": "127.0.0.1",
"domain:googleapis.cn": "googleapis.com"
},
"servers": [
"1.1.1.1",
"1.0.0.1",
{
"address": "8.8.8.8",
"domains": [
"domain:freeserver.top",
"geosite:ir"
],
"expectIPs": [
"geoip:cn"
],
"port": 53
}
]
},
"inbounds": [
{
"listen": "127.0.0.1",
"port": 10808,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true
},
"sniffing": {
"destOverride": [
"http",
"tls"
],
"enabled": true
},
"tag": "socks"
},
{
"listen": "127.0.0.1",
"port": 10809,
"protocol": "http",
"tag": "http"
}
],
"log": {
"loglevel": "warning"
},
"outbounds": [
{
// A VLess Server that is working
"tag": "proxy"
},
{
"protocol": "freedom",
"settings": {},
"tag": "direct"
},
{
"protocol": "blackhole",
"settings": {
"response": {
"type": "http"
}
},
"tag": "block"
},
{
"protocol": "freedom",
"settings": {
"fragment": {
"interval": "10-20",
"length": "10-20",
"packets": "tlshello"
}
},
"streamSettings": {
"network": "tcp",
"security": "",
"sockopt": {
"TcpNoDelay": true,
"mark": 255
}
},
"tag": "fragment"
}
],
"routing": {
"domainStrategy": "AsIs",
"rules": [
{
"ip": [
"1.1.1.1",
"1.0.0.1"
],
"outboundTag": "proxy",
"port": "53",
"type": "field"
},
{
"domain": [
"geosite:ir"
],
"outboundTag": "direct",
"type": "field"
},
{
"ip": [
"geoip:ir",
"geoip:private"
],
"outboundTag": "direct",
"type": "field"
},
{
"domain": [
"geosite:ads"
],
"outboundTag": "block",
"type": "field"
}
]
},
"stats": {}
}
Sing-Box config:
{
"log": {
"level": "panic"
},
"inbounds": [
{
"domain_strategy": "prefer_ipv4",
"endpoint_independent_nat": true,
"inet4_address": [
"172.19.0.1/28"
],
"inet6_address": [
"fdfe:dcba:9876::1/126"
],
"mtu": 9000,
"auto_route": true,
"strict_route": false,
"sniff": true,
"sniff_override_destination": true,
"stack": "gvisor",
"tag": "tun-in",
"type": "tun"
}
],
"outbounds": [
{
"tag": "xray-out",
"type": "socks",
"server": "127.0.0.1",
"server_port": 10808,
"version": "5",
"udp_over_tcp": true
},
{
"tag": "direct",
"type": "direct"
}
],
"route": {
"auto_detect_interface": true,
"rules": []
}
}
You need to let xray's traffic go to direct outbound in sing-box's rule. Otherwise it will cause a proxy loopback.
Thanks. But how should I change the configs for that purpose?
It worked! Thanks.