SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
19.34k stars 2.3k forks source link

TUN mode not working in macos but it worked in windows ? #655

Closed khayyamov closed 1 year ago

khayyamov commented 1 year ago

Welcome

Description of the problem

I have used this configuration for TUN mode in Windows and it worked, but the same configuration does not work in MacOS, there is an error in the name of the interface. What name should I set for the interface? Or I think I have to change somewhere in the config

Version of sing-box

```console sing-box version 1.2.7 Environment: go1.20.4 darwin/amd64 Tags: with_gvisor,with_quic,with_wireguard,with_utls,with_reality_server,with_clash_api Revision: c74d3a53d41b0e8586257a2a1071faf394d1ed2f CGO: disabled ```

Server and client configuration file

```console { "dns": { "servers": [ { "tag": "out_dns", "address": "8.8.8.8", "detour": "proxy" }, { "tag": "local", "address": "223.5.5.5", "detour": "direct" }, { "tag": "block", "address": "rcode://success" } ] }, "inbounds": [ { "type": "tun", "tag": "tun-in", "interface_name": "tun0", "inet4_address": "172.19.0.1/30", "inet6_address": "fdfe:dcba:9876::1/126", "mtu": 9000, "auto_route": true, "strict_route": false, "stack": "gvisor", "endpoint_independent_nat": true, "sniff": true } ], "outbounds": [ { "type": "socks", "tag": "proxy", "udp_fragment": true, "server": "127.0.0.1", "server_port": 10801 }, { "type": "block", "tag": "block" }, { "type": "direct", "tag": "direct" }, { "type": "dns", "tag": "dns_out" } ], "route": { "auto_detect_interface": true, "rules": [ { "inbound": "dns_in", "outbound": "dns_out" }, { "protocol": "dns", "outbound": "dns_out" }, { "network": "udp", "port": [ 135, 137, 138, 139, 5353 ], "outbound": "block" }, { "ip_cidr": [ "224.0.0.0/3", "ff00::/8" ], "outbound": "block" }, { "source_ip_cidr": [ "224.0.0.0/3", "ff00::/8" ], "outbound": "block" }, { "port": 53, "process_name": [ "wv2ray","v2ray","SagerNet","v2ray","v2ray","xray","wxray","clash-windows-amd64-v3","clash-windows-amd64","clash-windows-386","clash","Clash.Meta-windows-amd64-compatible","Clash.Meta-windows-amd64","Clash.Meta-windows-386","Clash.Meta","clash","hysteria-windows-amd64","hysteria-windows-386","hysteria","naiveproxy","naive","tuic-client","tuic"], "outbound": "dns_out" }, { "process_name": [ "wv2ray","v2ray","SagerNet","v2ray","v2ray","xray","wxray","clash-windows-amd64-v3","clash-windows-amd64","clash-windows-386","clash","Clash.Meta-windows-amd64-compatible","Clash.Meta-windows-amd64","Clash.Meta-windows-386","Clash.Meta","clash","hysteria-windows-amd64","hysteria-windows-386","hysteria","naiveproxy","naive","tuic-client","tuic","sing-box-client","sing-box"], "outbound": "direct" } ] } } ```

Server and client log file

```console ./sing-box run -c=tunConfig.json INFO[0000] router: updated default interface en0, index 11 TRACE[0000] initializing inbound/tun[tun-in] TRACE[0000] closing inbound/tun[0] TRACE[0000] closing outbound/socks[0] TRACE[0000] closing outbound/block[1] TRACE[0000] closing outbound/direct[2] TRACE[0000] closing outbound/dns[3] TRACE[0000] closing router TRACE[0000] router: closing rule[0] TRACE[0000] router: closing rule[1] TRACE[0000] router: closing rule[2] TRACE[0000] router: closing rule[3] TRACE[0000] router: closing rule[4] TRACE[0000] router: closing rule[5] TRACE[0000] router: closing rule[6] TRACE[0000] router: closing transport[0] TRACE[0000] router: closing transport[1] TRACE[0000] router: closing transport[2] TRACE[0000] router: closing interface monitor TRACE[0000] router: closing network monitor TRACE[0000] closing log factory FATAL[0000] start service: initialize inbound/tun[tun-in]: configure tun interface: bad tun name: tun0 ```
SafaSafari commented 1 year ago

Make sure there isn't any other interface named tun0 Also try this format in name: utun0-255 ex: utun128

khayyamov commented 1 year ago

Thank you for your answer @SafaSafari , I removed the fully interfaceـname field it fixed 😂, but a new problem has been added, the data is not transmit?

SafaSafari commented 1 year ago

Thank you for your answer @SafaSafari , I removed the fully interfaceـname field it fixed 😂, but a new problem has been added, the data is not transmit?

Nice😁🔥 Maybe it's because sing-box process name redirected to direct outbound in the last rule🤔

khayyamov commented 1 year ago

Singbox log:

./sing-box run -c=tunConfig.json
Password:
INFO[0000] router: updated default interface en0, index 11
TRACE[0000] initializing inbound/tun[tun-in]
INFO[0000] inbound/tun[tun-in]: started at utun3
INFO[0000] sing-box started (0.11s)
INFO[0000] [2343780100 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:60074
INFO[0000] [2343780100 0ms] inbound/tun[tun-in]: inbound packet connection to 178.22.122.100:53
DEBUG[0000] [2343780100 1ms] router: sniffed packet protocol: dns
INFO[0000] [2343780100 1ms] router: failed to search process: process not found
DEBUG[0000] [2343780100 1ms] router: match[1] protocol=dns => dns_out
DEBUG[0000] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
INFO[0000] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
INFO[0000] [3513107014 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:61606
INFO[0000] [3513107014 0ms] inbound/tun[tun-in]: inbound packet connection to 178.22.122.100:53
DEBUG[0000] [3513107014 0ms] router: sniffed packet protocol: dns
INFO[0000] [2983401709 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:49805
INFO[0000] [2983401709 0ms] inbound/tun[tun-in]: inbound packet connection to 178.22.122.100:53
DEBUG[0000] [2983401709 0ms] router: sniffed packet protocol: dns
INFO[0000] [3513107014 0ms] router: failed to search process: process not found
DEBUG[0000] [3513107014 0ms] router: match[1] protocol=dns => dns_out
INFO[0000] [2983401709 0ms] router: failed to search process: process not found
DEBUG[0000] [2983401709 0ms] router: match[1] protocol=dns => dns_out
DEBUG[0000] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0000] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0001] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
DEBUG[0001] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0001] dns: exchange dl.cloudnsham.ir. IN AAAA
INFO[0003] [3948909089 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:50433
INFO[0003] [3948909089 0ms] inbound/tun[tun-in]: inbound packet connection to 185.51.200.2:53
INFO[0003] [4264929993 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:64479
INFO[0003] [4264929993 0ms] inbound/tun[tun-in]: inbound packet connection to 185.51.200.2:53
DEBUG[0003] [4264929993 0ms] router: sniffed packet protocol: dns
INFO[0003] [1272018775 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:64495
INFO[0003] [4264929993 0ms] router: failed to search process: process not found
DEBUG[0003] [3948909089 2ms] router: sniffed packet protocol: dns
INFO[0003] [1272018775 2ms] inbound/tun[tun-in]: inbound packet connection to 185.51.200.2:53
DEBUG[0003] [1272018775 2ms] router: sniffed packet protocol: dns
INFO[0003] [3948909089 3ms] router: failed to search process: process not found
DEBUG[0003] [3948909089 3ms] router: match[1] protocol=dns => dns_out
INFO[0003] [1272018775 3ms] router: failed to search process: process not found
DEBUG[0003] [1272018775 3ms] router: match[1] protocol=dns => dns_out
DEBUG[0003] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0003] [4264929993 3ms] router: match[1] protocol=dns => dns_out
DEBUG[0003] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
DEBUG[0003] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0004] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0004] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
DEBUG[0004] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0006] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0006] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0006] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context deadline exceeded
INFO[0010] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
DEBUG[0010] [2343780100 10.1s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context canceled
INFO[0010] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context deadline exceeded
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context canceled
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context canceled
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
DEBUG[0010] [3513107014 10.0s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context canceled
DEBUG[0010] [2983401709 10.0s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context canceled
DEBUG[0010] [4264929993 6.94s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
DEBUG[0010] [1272018775 6.94s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
INFO[0010] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context deadline exceeded
DEBUG[0010] [3948909089 6.94s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: write udp 127.0.0.1:51453->127.0.0.1:10801: use of closed network connection
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: write udp 127.0.0.1:51453->127.0.0.1:10801: use of closed network connection
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context canceled
INFO[0010] [1625608565 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:60074

xray logs:

2023/06/18 00:43:11 [Warning] [806020230] app/proxyman/outbound: failed to process outbound traffic > proxy/vless/outbound: failed to find an available destination > common/retry: [transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: i/o timeout transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: no such host transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: i/o timeout transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: no such host transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: operation was canceled] > common/retry: all retry attempts failed
SafaSafari commented 1 year ago

Singbox log:

./sing-box run -c=tunConfig.json
Password:
INFO[0000] router: updated default interface en0, index 11
TRACE[0000] initializing inbound/tun[tun-in]
INFO[0000] inbound/tun[tun-in]: started at utun3
INFO[0000] sing-box started (0.11s)
INFO[0000] [2343780100 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:60074
INFO[0000] [2343780100 0ms] inbound/tun[tun-in]: inbound packet connection to 178.22.122.100:53
DEBUG[0000] [2343780100 1ms] router: sniffed packet protocol: dns
INFO[0000] [2343780100 1ms] router: failed to search process: process not found
DEBUG[0000] [2343780100 1ms] router: match[1] protocol=dns => dns_out
DEBUG[0000] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
INFO[0000] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
INFO[0000] [3513107014 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:61606
INFO[0000] [3513107014 0ms] inbound/tun[tun-in]: inbound packet connection to 178.22.122.100:53
DEBUG[0000] [3513107014 0ms] router: sniffed packet protocol: dns
INFO[0000] [2983401709 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:49805
INFO[0000] [2983401709 0ms] inbound/tun[tun-in]: inbound packet connection to 178.22.122.100:53
DEBUG[0000] [2983401709 0ms] router: sniffed packet protocol: dns
INFO[0000] [3513107014 0ms] router: failed to search process: process not found
DEBUG[0000] [3513107014 0ms] router: match[1] protocol=dns => dns_out
INFO[0000] [2983401709 0ms] router: failed to search process: process not found
DEBUG[0000] [2983401709 0ms] router: match[1] protocol=dns => dns_out
DEBUG[0000] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0000] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0001] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
DEBUG[0001] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0001] dns: exchange dl.cloudnsham.ir. IN AAAA
INFO[0003] [3948909089 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:50433
INFO[0003] [3948909089 0ms] inbound/tun[tun-in]: inbound packet connection to 185.51.200.2:53
INFO[0003] [4264929993 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:64479
INFO[0003] [4264929993 0ms] inbound/tun[tun-in]: inbound packet connection to 185.51.200.2:53
DEBUG[0003] [4264929993 0ms] router: sniffed packet protocol: dns
INFO[0003] [1272018775 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:64495
INFO[0003] [4264929993 0ms] router: failed to search process: process not found
DEBUG[0003] [3948909089 2ms] router: sniffed packet protocol: dns
INFO[0003] [1272018775 2ms] inbound/tun[tun-in]: inbound packet connection to 185.51.200.2:53
DEBUG[0003] [1272018775 2ms] router: sniffed packet protocol: dns
INFO[0003] [3948909089 3ms] router: failed to search process: process not found
DEBUG[0003] [3948909089 3ms] router: match[1] protocol=dns => dns_out
INFO[0003] [1272018775 3ms] router: failed to search process: process not found
DEBUG[0003] [1272018775 3ms] router: match[1] protocol=dns => dns_out
DEBUG[0003] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0003] [4264929993 3ms] router: match[1] protocol=dns => dns_out
DEBUG[0003] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
DEBUG[0003] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0004] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0004] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
DEBUG[0004] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0006] dns: exchange dl.cloudnsham.ir. IN AAAA
DEBUG[0006] dns: exchange dl.cloudnsham.ir. IN A
DEBUG[0006] dns: exchange 7.1.168.192.in-addr.arpa. IN PTR
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context deadline exceeded
INFO[0010] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
DEBUG[0010] [2343780100 10.1s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context canceled
INFO[0010] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context deadline exceeded
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context canceled
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context canceled
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
DEBUG[0010] [3513107014 10.0s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context canceled
DEBUG[0010] [2983401709 10.0s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: context canceled
DEBUG[0010] [4264929993 6.94s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
DEBUG[0010] [1272018775 6.94s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
INFO[0010] outbound/socks[proxy]: outbound packet connection to 8.8.8.8:53
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context deadline exceeded
DEBUG[0010] [3948909089 6.94s] inbound/tun[tun-in]: connection closed: upstream: context canceled | io: read/write on closed pipe
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN A: context canceled
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: write udp 127.0.0.1:51453->127.0.0.1:10801: use of closed network connection
ERROR[0010] dns: exchange failed for 7.1.168.192.in-addr.arpa. IN PTR: write udp 127.0.0.1:51453->127.0.0.1:10801: use of closed network connection
ERROR[0010] dns: exchange failed for dl.cloudnsham.ir. IN AAAA: context canceled
INFO[0010] [1625608565 0ms] inbound/tun[tun-in]: inbound packet connection from 172.19.0.1:60074

xray logs:

2023/06/18 00:43:11 [Warning] [806020230] app/proxyman/outbound: failed to process outbound traffic > proxy/vless/outbound: failed to find an available destination > common/retry: [transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: i/o timeout transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: no such host transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: i/o timeout transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: no such host transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://dl.cloudnsham.ir/):  > dial tcp: lookup dl.cloudnsham.ir: operation was canceled] > common/retry: all retry attempts failed

Why don't using sing-box directly? I mean set vless connection config on sing-box directly without any xray client

Config documentation: http://sing-box.sagernet.org/configuration/outbound/vless/

khayyamov commented 1 year ago

Yes, I have to use the same method. You know, the models of my program that I wrote with Dart were made for Flutter for xray client, so I have to convert them to singbox. It will probably take me a whole day. What version of xray core do you think singbox uses? I think it uses 1.7.5 because the 1.8.0 versions are pre-release and there are many features in this version. Thank you my brother for you help

SafaSafari commented 1 year ago

Yes, I have to use the same method. You know, the models of my program that I wrote with Dart were made for Flutter for xray client, so I have to convert them to singbox. It will probably take me a whole day. What version of xray core do you think singbox uses? I think it uses 1.7.5 because the 1.8.0 versions are pre-release and there are many features in this version. Thank you my brother for you help

Sing-box doesn't use xray core :)) Sing-box is completely different core and doesn't have any dependencies to xray-core Your welcome😘❤️

khayyamov commented 1 year ago

خب همین دیگه مثلا reality رو ساپورت نمیکنه ؟ میکنه ؟

SafaSafari commented 1 year ago

خب همین دیگه مثلا reality رو ساپورت نمیکنه ؟ میکنه ؟

چرا گلم، میکنه =)) http://sing-box.sagernet.org/configuration/shared/tls/#reality-fields

khayyamov commented 1 year ago

بنظرت چرا اون کانفیگ سینگ کار نمیکنه با xray ?

SafaSafari commented 1 year ago

بنظرت چرا اون کانفیگ سینگ کار نمیکنه با xray ?

گفتم که شاید اون رول آخر که تو اسم پروسس ها sing-box هست، باعث میشه

khayyamov commented 1 year ago

نه داداش اونم برداشتم همچنان کار نمیکنه

khayyamov commented 1 year ago

ERROR[0021] dns: exchange failed for detectportal.brave-http-only.com. IN A: context deadline exceeded

برای دامنه هایی که میخام باز کنم این ارور رو میده