Sing-Box 客户端配置求助

有两个设备A(archlinux) B(windows) 都运行下方配置
使用 localsend 能够互相发现,archlinux端向windows端发送文件正常,但是windows端向archlinux发送文件时,archlinux客户端接收不到请求。
关闭 sing-box 之后正常,所以可以确定是 sing-box 导致的。
有大佬知道怎么解决吗?

{
  "log": { "level": "info", "timestamp": true },
  "dns": {
    "servers": [
      { "tag": "google", "address": "tls://8.8.8.8" },
      {
        "tag": "local",
        "address": "https://223.5.5.5/dns-query",
        "detour": "direct"
      },
      { "tag": "fakeip", "address": "fakeip" }
    ],
    "rules": [
      { "outbound": "any", "server": "local" },
      { "clash_mode": "Direct", "server": "local" },
      { "clash_mode": "Global", "server": "google" },
      { "rule_set": "geosite-geolocation-cn", "server": "local" },
      {
        "type": "logical",
        "mode": "and",
        "rules": [
          { "rule_set": "geosite-geolocation-!cn", "invert": true },
          { "rule_set": "geoip-cn" }
        ],
        "server": "google",
        "client_subnet": "114.114.114.114/24"
      },
      { "query_type": ["A", "AAAA"], "server": "fakeip" }
    ],
    "fakeip": {
      "enabled": true,
      "inet4_range": "198.18.0.0/15",
      "inet6_range": "fc00::/18"
    },
    "strategy": "prefer_ipv4",
    "independent_cache": true
  },
  "inbounds": [
    {
      "type": "tun",
      "auto_route": true,
      "strict_route": false,
      "sniff": true,
      "address": ["172.19.0.1/30", "fdfe:dcba:9876::1/126"],
      "route_exclude_address": ["100.64.0.0/10", "fd7a:115c:a1e0::/48"]
    }
  ],
  "outbounds": [
    {
      "type": "selector",
      "tag": "default",
      "outbounds": []
    }
  ],
  "route": {
    "rules": [
      {
        "type": "logical",
        "mode": "or",
        "rules": [{ "protocol": "dns" }, { "port": 53 }],
        "outbound": "dns"
      },
      {
        "process_name": ["syncthing", "tailscale", "tailscaled"],
        "outbound": "direct"
      },
      { "ip_is_private": true, "outbound": "direct" },
      { "clash_mode": "Direct", "outbound": "direct" },
      { "clash_mode": "Global", "outbound": "default" },
      {
        "type": "logical",
        "mode": "or",
        "rules": [
          { "port": 853 },
          { "network": "udp", "port": 443 },
          { "protocol": "stun" }
        ],
        "outbound": "block"
      },
      { "rule_set": "geosite-google", "outbound": "default" },
      {
        "type": "logical",
        "mode": "or",
        "rules": [
          {
            "rule_set": [
              "geoip-cn",
              "geosite-geolocation-cn",
              "geosite-cn",
              "geosite-category-games@cn",
              "geosite-steam@cn"
            ]
          },
          { "process_path_regex": [".*steamapps[\\/]common.*"] }
        ],
        "outbound": "direct"
      }
    ],
    "rule_set": [
      {
        "type": "remote",
        "tag": "geosite-geolocation-cn",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-cn.srs",
        "download_detour": "default"
      },
      {
        "type": "remote",
        "tag": "geosite-geolocation-!cn",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-geolocation-!cn.srs",
        "download_detour": "default"
      },
      {
        "type": "remote",
        "tag": "geoip-cn",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs",
        "download_detour": "default"
      },
      {
        "type": "remote",
        "tag": "geosite-category-games@cn",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/[email protected]",
        "download_detour": "default"
      },
      {
        "type": "remote",
        "tag": "geosite-steam@cn",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/[email protected]",
        "download_detour": "default"
      },
      {
        "type": "remote",
        "tag": "geosite-cn",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-cn.srs",
        "download_detour": "default"
      },
      {
        "type": "remote",
        "tag": "geosite-google",
        "format": "binary",
        "url": "https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-google.srs",
        "download_detour": "default"
      }
    ],
    "final": "default",
    "auto_detect_interface": true
  },
  "experimental": {
    "cache_file": { "enabled": true },
    "clash_api": {
      "external_controller": "127.0.0.1:9090",
      "external_ui": "./ui",
      "external_ui_download_detour": "default",
      "default_mode": "Enhanced"
    }
  }
}

30 个赞

帮顶一下_(:з」∠)_

2 个赞

试试将 inbounds 的 address 改为 172.16.0.1/30呢?

4 个赞

帮顶,共同关注

2 个赞

虽然不知道为什么这么改,但是我尝试了一下,没有效果。

2 个赞

在Windows下抓取一下传输时的连接以及日志看一下?

可以断开外网用热点什么的组个内网减少一些外网日志的干扰,看一下传输时报的什么错?

正常来说Archlinux下发送文件正常,那可能是windows下tun模式存在一些问题,抓些日志分析一下可能有突破口?

2 个赞

把 windows 端的 sing-box 停止,仍然是 archlinux 可以传到 windows 但是 windows 不能传到 archlinux。
把 archlinux 端的 sing-box 停止,两边互传都正常了。
改成手机热点后情况不变
我觉得是 archlinux 有些问题。

2 个赞

你用的是内核吗,可以看日志

2 个赞

在 TUN 配置里的 route_exclude_address 添加上局域网地址,比如:"192.168.0.0/16"

2 个赞

那应该是Archlinux下tun的auto_route有些问题,估计和windows下行为不同,把localsend的传输package拦截了,你可以去了解一下tun的auto_redirect字段功能,据其官网说能使得在路由器上sing-box的auto_route可正常工作,然后应该和楼上一般配置放行地址应该就可以了

这样是可以传文件了,但是代理失效了
目标IP都变成了一些ipv6地址 2600:1901:1:7c5:: 之类的

archlinux的日志没有windows设备的IP,很奇怪

结合了一下上面各位大佬的方案,找到了一个解决方案,暂时没有遇到奇怪的问题。

"inbounds": [
    {
      "type": "tun",
      "auto_route": true,
      "auto_redirect": true,
      "strict_route": true,
      "sniff": true,
      "sniff_override_destination": true, // 加上就能用,去掉就不能访问需要代理的站点
      "address": ["172.16.0.1/30", "fdfe:dcba:9876::1/126"],
      "route_exclude_address": [
        "100.64.0.0/10",
        "fd7a:115c:a1e0::/48",
        "192.168.0.0/16"
      ]
    }
  ]

这个配置还是有一些问题,有些网站打不开, 但是不知道为什么,日志里完全没有相关的域名输出。
例如 raw.githubusercontent.com 不能访问,ping出来的ip是127.0.0.1

3 个赞

需要配置对应的日志等级,才能显示需要的日志,sing-box/日志配置

{
  "log": {
    "level": "trace",
    "timestamp": true
  }
}
2 个赞

关于 SingBox 配置文件,可以按功能模块拆分为多个文件来管理

我的 TUN 配置如下

{
  "inbounds": [
    {
      "type": "tun",
      "address": [
        "172.18.0.1/30"
      ],
      "auto_route": true,
      "auto_redirect": true,
      "strict_route": true
    }
  ]
}

参考你的配置,改成下面这样一切正常了

{
      "type": "tun",
      "auto_route": true,
      "strict_route": true,
      "sniff": true,
      "sniff_override_destination": true,
      "address": ["172.16.0.1/30", "fdfe:dcba:9876::1/126"],
      "route_exclude_address": ["100.64.0.0/10", "fd7a:115c:a1e0::/48"],
      "route_exclude_address_set": ["geoip-cn"]
    }

"strict_route": true,的问题吗,之前好像是false

应该并不是,strick_route 没感觉有什么影响。
加上 "route_exclude_address_set": ["geoip-cn"] 之后都正常了

不会吧,局域网通信怎么能走到 geoip-cn 里呢?

可以的话,在 archlinux 终端执行 sudo ip rule,看一下路由策略