本配置适合安卓客户端,版本需要 1.10.0-beta 以上版本。

安卓版本使用 tun 来实现代理,与 Linux 桌面版本略有不同。

配置策略

本配置主要策略:

  1. DNS 提供国内和国外分流,且避免 DNS 泄漏;
  2. 流量基于 GeoIP/GeoSite 实现国内外分流;
  3. 过滤广告;
  4. 忽略部分国内主流应用(微信/淘宝/京东等,避免流量经过代理);
  5. 忽略本地/似有地址的流量;

配置文件内容

本配置主要内容如下,适合 sing-box 1.10 beta 以上版本:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{
  "log": {
    "level": "info"
  },
  "dns": {
    "servers": [
      {
        "tag": "dns-remote",
        "address": "https://1.1.1.1/dns-query",
        "detour": "proxy",
        "client_subnet": "1.0.1.0"
      },
      {
        "tag": "dns-default",
        "address": "local",
        "detour": "direct"
      },
      {
        "tag": "dns-block",
        "address": "rcode://refused"
      }
    ],
    "rules": [
      {
        "rule_set": "anti-ad",
        "server": "dns-block"
      },
      {
        "rule_set": [
          "geosite-cn"
        ],
        "server": "dns-default"
      },
      {
        "outbound": "any",
        "server": "dns-default"
      }
    ],
    "final": "dns-remote",
    "disable_expire": true
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-auto",
      "mtu": 9000,
      "address": [
        "172.18.0.1/30",
        "fdfe:dcba:9876::1/126"
      ],
      "auto_route": true,
      "strict_route": true,
      "route_address": [
        "0.0.0.0/1",
        "128.0.0.0/1",
        "::/1",
        "8000::/1"
      ],
      "route_exclude_address": [
        "10.0.0.0/8",
        "172.16.0.0/12",
        "192.168.0.0/16",
        "fc00::/7"
      ],
      "exclude_package": [
        "com.jingdong.app.mall",
        "com.douban.frodo",
        "com.taobao.taobao",
        "com.eg.android.AlipayGphone",
        "com.tencent.mm",
        "com.tencent.mp",
        "com.tencent.soter.soterserver",
        "com.tencent.wemeet.app",
        "com.tencent.weread",
        "com.tencent.wework"
      ],
      "udp_timeout": "5m",
      "stack": "mixed",
      "platform": {
        "http_proxy": {
          "server": "127.0.0.1",
          "server_port": 8080
        }
      },
      "sniff": true
    }
  ],
  "outbounds": [
    {
      "type": "selector",
      "tag": "proxy",
      "outbounds": [
        "trojan",
        "hysteria"
      ],
      "default": "trojan"
    },
    {
      "type": "trojan",
      "tag": "trojan",
      ...
    },
    {
      "type": "hysteria",
      "tag": "hysteria",
      ...
    },
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    },
    {
      "type": "dns",
      "tag": "dns-out"
    }
  ],
  "route": {
    "rules": [
      {
        "rule_set": "anti-ad",
        "outbound": "block"
      },
      {
        "protocol": "dns",
        "outbound": "dns-out"
      },
      {
        "ip_is_private": true,
        "rule_set": [
          "geoip-cn",
          "geosite-cn"
        ],
        "outbound": "direct"
      }
    ],
    "rule_set": [
      {
        "type": "remote",
        "tag": "anti-ad",
        "format": "binary",
        "url": "https://github.com/SagerNet/sing-geosite/raw/rule-set/geosite-category-ads-all.srs",
        "download_detour": "proxy"
      },
      {
        "type": "remote",
        "tag": "geosite-cn",
        "format": "binary",
        "url": "https://github.com/SagerNet/sing-geosite/raw/rule-set/geosite-cn.srs",
        "download_detour": "proxy"
      },
      {
        "type": "remote",
        "tag": "geoip-cn",
        "format": "binary",
        "url": "https://github.com/SagerNet/sing-geoip/raw/rule-set/geoip-cn.srs",
        "download_detour": "proxy"
      }
    ],
    "final": "proxy",
    "auto_detect_interface": true
  },
  "experimental": {
    "cache_file": {
      "enabled": true
    }
  }
}

备注

需要注意的地方:

  1. 由于 sing-box 内部 DNS 服务性能原因,建议境内 DNS 使用 local,尽量不用 DOH/DOT,否则会因为解析延迟影响体验;
  2. tun.exclude_package 里是需要忽略的应用包名,常见应用可以去搜索包名添加,以避免走代理;
  3. route.rules.auto_detect_interface 是需要设置的,否则代理会无法生效;