RouterOS+SingBox国内外分流

环境介绍

路由器是RB5009 7.16版本

singbox用的是“P核”(因为这个版本可以只用一个核心就能实现订阅功能)

P核介绍: https://linux.do/t/topic/183383

没有用fakeip,直接在Mangle中标记非CN的IP实现分流

配置文件

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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
{
"log": {
"disabled": false,
"level": "info",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "dns_local",
"address": "10.1.1.1",
// 本地DNS
"detour": "DIRECT"
},
{
"tag": "dns_proxy",
"address": [
"https://8.8.8.8/dns-query"
],
"strategy": "ipv4_only",
"detour": "🍕 DNS节点"
}
],
"rules": [
{
"outbound": "any",
"server": "dns_local",
"disable_cache": true
},
{
"clash_mode": "Direct",
"server": "dns_local"
},
{
"clash_mode": "Global",
"server": "dns_proxy"
},
{
"rule_set": [
"proxy"
],
"server": "dns_proxy"
},
{
"rule_set": [
"cn"
],
"server": "dns_local"
}
],
"final": "dns_proxy",
"disable_cache": true,
"disable_expire": false,
"independent_cache": false
},
"inbounds": [
{
"type": "direct",
"tag": "dns-in",
"listen": "0.0.0.0",
"listen_port": 53
},
{
"tag": "tun-in",
"type": "tun",
"interface_name": "tun0",
"address": [
"10.0.1.1/30"
],
"mtu": 9000,
"gso": true,
"stack": "system",
"auto_route": true,
"sniff": true,
"sniff_override_destination": true
}
],
"outbounds": [
{
"tag": "REJECT",
"type": "block"
},
{
"tag": "DIRECT",
"type": "direct"
},
{
"type": "dns",
"tag": "dns-out"
},
{
"tag": "🔰 节点选择",
"type": "selector",
"outbounds": [
"♻️ 自动选择",
"🇭🇰 香港自动",
"🇨🇳 台湾自动",
"🇯🇵 日本自动",
"🇰🇷 韩国自动",
"🇸🇬 狮城自动",
"🇺🇸 美国自动",
"🌀 手动切换",
"🎯 全球直连"
]
},
{
"tag": "🌀 手动切换",
"type": "selector",
"use_all_providers": true,
"includes": [
"🇭🇰|香港|HK|HONGKONG|HongKong|🇨🇳|台湾|TW|TAIWAN|Taiwan|🇯🇵|日本|JP|JAPAN|Japan|🇸🇬|新加坡|SG|SINGAPORE|Singapore|🇺🇸|美国|US|UNITED STATES|United States"
],
"outbounds": [
"my_us"
]
},
{
"tag": "🍕 DNS节点",
"type": "selector",
"use_all_providers": true,
"includes": [
"🇭🇰|香港|HK|HONGKONG|HongKong|🇨🇳|台湾|TW|TAIWAN|Taiwan|🇯🇵|日本|JP|JAPAN|Japan|🇸🇬|新加坡|SG|SINGAPORE|Singapore|🇺🇸|美国|US|UNITED STATES|United States"
]
},
{
"tag": "♻️ 自动选择",
"type": "urltest",
"url": "http://www.google-analytics.com/generate_204",
"tolerance": 50,
"outbounds": [
"🇭🇰 香港自动",
"🇨🇳 台湾自动",
"🇯🇵 日本自动",
"🇰🇷 韩国自动",
"🇸🇬 狮城自动",
"🇺🇸 美国自动"
]
},
{
"tag": "🤖 人工智能",
"type": "selector",
"outbounds": [
"🇭🇰 香港自动",
"🇨🇳 台湾自动",
"🇯🇵 日本自动",
"🇰🇷 韩国自动",
"🇸🇬 狮城自动",
"🇺🇸 美国自动"
]
},
{
"tag": "🎮 游戏服务",
"type": "selector",
"outbounds": [
"🎯 全球直连",
"🔰 节点选择"
]
},
{
"tag": "🪟 微软服务",
"type": "selector",
"outbounds": [
"🎯 全球直连",
"🔰 节点选择"
]
},
{
"tag": "🇬 谷歌服务",
"type": "selector",
"outbounds": [
"🎯 全球直连",
"🔰 节点选择"
]
},
{
"tag": "🍎 苹果服务",
"type": "selector",
"outbounds": [
"🎯 全球直连",
"🔰 节点选择"
]
},
{
"tag": "🇨🇳 直连域名",
"type": "selector",
"outbounds": [
"🎯 全球直连"
]
},
{
"tag": "🇨🇳 直连 IP",
"type": "selector",
"outbounds": [
"🎯 全球直连"
]
},
{
"tag": "🪜 代理域名",
"type": "selector",
"outbounds": [
"🔰 节点选择",
"🎯 全球直连"
]
},
{
"tag": "📲 电报消息",
"type": "selector",
"outbounds": [
"🔰 节点选择",
"🇭🇰 香港自动",
"🇨🇳 台湾自动",
"🇯🇵 日本自动",
"🇰🇷 韩国自动",
"🇸🇬 狮城自动",
"🇺🇸 美国自动"
]
},
{
"tag": "🖥️ 直连软件",
"type": "selector",
"outbounds": [
"🎯 全球直连"
]
},
{
"tag": "🔒 私有网络",
"type": "selector",
"outbounds": [
"🎯 全球直连"
]
},
{
"tag": "🛑 广告拦截",
"type": "selector",
"outbounds": [
"REJECT"
]
},
{
"tag": "🎯 全球直连",
"type": "selector",
"outbounds": [
"DIRECT"
]
},
{
"tag": "GLOBAL",
"type": "selector",
"outbounds": [
"DIRECT",
"REJECT",
"🇭🇰 香港自动",
"🇨🇳 台湾自动",
"🇯🇵 日本自动",
"🇰🇷 韩国自动",
"🇸🇬 狮城自动",
"🇺🇸 美国自动"
]
},
{
"tag": "🐟 漏网之鱼",
"type": "selector",
"outbounds": [
"🔰 节点选择",
"🎯 全球直连"
]
},
{
"tag": "🇭🇰 香港自动",
"type": "urltest",
"url": "http://www.google-analytics.com/generate_204",
"tolerance": 50,
"use_all_providers": true,
"includes": [
"🇭🇰|香港|HK|HONGKONG|HongKong"
]
},
{
"tag": "🇨🇳 台湾自动",
"type": "urltest",
"url": "http://www.google-analytics.com/generate_204",
"tolerance": 50,
"use_all_providers": true,
"includes": [
"🇨🇳|台湾|TW|TAIWAN|Taiwan"
]
},
{
"tag": "🇯🇵 日本自动",
"type": "urltest",
"url": "http://www.google-analytics.com/generate_204",
"tolerance": 50,
"use_all_providers": true,
"includes": [
"🇯🇵|日本|JP|JAPAN|Japan"
]
},
{
"tag": "🇰🇷 韩国自动",
"type": "urltest",
"url": "http://www.google-analytics.com/generate_204",
"tolerance": 50,
"use_all_providers": true,
"includes": [
"🇰🇷|韩国|KR|KOREA|Korea"
]
},
{
"tag": "🇸🇬 狮城自动",
"type": "urltest",
"url": "http://www.google-analytics.com/generate_204",
"tolerance": 50,
"use_all_providers": true,
"includes": [
"🇸🇬|新加坡|SG|SINGAPORE|Singapore"
]
},
{
"tag": "🇺🇸 美国自动",
"type": "urltest",
"url": "http://www.google-analytics.com/generate_204",
"tolerance": 50,
"use_all_providers": true,
"includes": [
"🇺🇸|美国|US|UNITED STATES|United States"
]
},
// 下面是单个节点的例子,自己替换,或者删掉
{
"tag": "my_us",
"type": "hysteria2",
"server": "1.1.11.1",
"server_port": 443,
"password": "11111111",
"tls": {
"enabled": true,
"server_name": "udptest.213123.1111",
"insecure": true
},
"tcp_fast_open": true,
"udp_fragment": true
}
// 单个节点放这里,注意上一行加逗号
],
// 下面是放订阅链接,如果只用到第一个,请删除2和3
"outbound_providers": [
{
"tag": "🛫 1",
"type": "remote",
"download_url": "https://1.com",
"path": "./1.yaml",
"download_interval": "24h",
"download_ua": "clash.meta",
"includes": [],
"healthcheck_url": "http://www.google-analytics.com/generate_204",
"healthcheck_interval": "10m"
},
{
"tag": "🛫 2",
"type": "remote",
"download_url": "https://2.com",
"path": "./2.yaml",
"download_interval": "24h",
"download_ua": "clash.meta",
"includes": [],
"healthcheck_url": "http://www.google-analytics.com/generate_204",
"healthcheck_interval": "10m"
},
{
"tag": "🛫 3",
"type": "remote",
"download_url": "https://3.com",
"path": "./3.yaml",
"download_interval": "24h",
"download_ua": "clash.meta",
"includes": [],
"healthcheck_url": "http://www.google-analytics.com/generate_204",
"healthcheck_interval": "10m"
}
],
"route": {
"rules": [
{
"protocol": [
"quic"
],
"outbound": "REJECT"
},
{
"inbound": "dns-in",
"outbound": "dns-out"
},
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"clash_mode": "Direct",
"outbound": "DIRECT"
},
{
"clash_mode": "Global",
"outbound": "GLOBAL"
},
{
"domain_suffix": [
"linux.do",
"ajay.app",
"returnyoutubedislikeapi.com"
],
"outbound": "🪜 代理域名"
},
{
"domain_suffix": [
"oaifree.com",
"guangbomi.com",
"bootcss.com",
"bilibili.com"
],
"outbound": "🇨🇳 直连域名"
},
{
"rule_set": [
"applications"
],
"outbound": "🖥️ 直连软件"
},
{
"rule_set": [
"private"
],
"outbound": "🔒 私有网络"
},
{
"rule_set": [
"microsoft-cn"
],
"outbound": "🪟 微软服务"
},
{
"rule_set": [
"apple-cn"
],
"outbound": "🍎 苹果服务"
},
{
"rule_set": [
"google-cn"
],
"outbound": "🇬 谷歌服务"
},
{
"rule_set": [
"games-cn"
],
"outbound": "🎮 游戏服务"
},
{
"rule_set": [
"ai"
],
"outbound": "🤖 人工智能"
},
{
"rule_set": [
"proxy"
],
"outbound": "🪜 代理域名"
},
{
"rule_set": [
"cn"
],
"outbound": "🇨🇳 直连域名"
},
{
"rule_set": [
"telegramip"
],
"outbound": "📲 电报消息",
"skip_resolve": true
},
{
"rule_set": [
"privateip"
],
"outbound": "🔒 私有网络",
"skip_resolve": true
},
{
"rule_set": [
"cnip"
],
"outbound": "🇨🇳 直连 IP"
}
],
"rule_set": [
{
"tag": "applications",
"type": "remote",
"format": "binary",
"path": "./applications.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/applications.srs"
},
{
"tag": "private",
"type": "remote",
"format": "binary",
"path": "./private.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/private.srs"
},
{
"tag": "microsoft-cn",
"type": "remote",
"format": "binary",
"path": "./microsoft-cn.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/microsoft-cn.srs"
},
{
"tag": "apple-cn",
"type": "remote",
"format": "binary",
"path": "./apple-cn.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/apple-cn.srs"
},
{
"tag": "google-cn",
"type": "remote",
"format": "binary",
"path": "./google-cn.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/google-cn.srs"
},
{
"tag": "games-cn",
"type": "remote",
"format": "binary",
"path": "./games-cn.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/games-cn.srs"
},
{
"tag": "ai",
"type": "remote",
"format": "binary",
"path": "./openai.srs",
"url": "https://mirror.ghproxy.com/https://raw.githubusercontent.com/yangchuansheng/sing-box-geosite/main/rule/OpenAI.srs"
},
{
"tag": "proxy",
"type": "remote",
"format": "binary",
"path": "./proxy.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/proxy.srs"
},
{
"tag": "cn",
"type": "remote",
"format": "binary",
"path": "./cn.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/cn.srs"
},
{
"tag": "telegramip",
"type": "remote",
"format": "binary",
"path": "./telegramip.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/telegramip.srs"
},
{
"tag": "privateip",
"type": "remote",
"format": "binary",
"path": "./privateip.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/privateip.srs"
},
{
"tag": "cnip",
"type": "remote",
"format": "binary",
"path": "./cnip.srs",
"url": "https://fastly.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/cnip.srs"
}
],
"final": "🐟 漏网之鱼",
"auto_detect_interface": true
},
"experimental": {
"cache_file": {
"enabled": true
},
"clash_api": {
"external_controller": "0.0.0.0:9090",
"secret": "",
"default_mode": "Rule"
}
}
}

自己修改上面的配置文件

启动singbox

给ros装container就不再赘述了

我打包好的arm64版本tar包

https://wwub.lanzouw.com/idsHY2b2r5fi

给singbox创建一个VETH (我的网段是10.1.1.1/24,这里给singbox设置为10.1.1.254)

image

把这个接口加到默认lan的bridge里(就不给container单独建一个bridge了)

image

创建一个Mount挂载点,我这里插了一个U盘,就把singbox相关文件保存到/usb1/singbox,容器内的对应目录/etc/sing-box

image

大概是这样(只有config.json是我放进去的,其他都是singbox启动后生成的)

image

然后就该上传tar文件,准备启动container了

image

启动container(这里logging先开着,启动失败可以看报错日志,后面再关掉)

image

我的配置文件中国内列表走ROS自己的DNS (“tag”: “dns_local”),国外走https://8.8.8.8/dns-query (“tag”: “dns_proxy”)

如果没有报错,启动成功的话,现在应该可以用面板连接上了 (面板连接应该会遇到问题 参考这个issues解决)

image

配置防火墙

先导入国内IP列表和私有IP段列表,这两类IP不走singbox

https://github.com/ruijzhan/chnroute

1
2
3
4
5
6
7
8
9
/system script
add dont-require-permissions=no name=cn owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="
/tool fetch url=https://fastly.jsdelivr.net/gh/ruijzhan/chnroute@master/CN.rsc
import file-name=CN.rsc
file remove CN.rsc

/tool fetch url=https://fastly.jsdelivr.net/gh/ruijzhan/chnroute@master/LAN.rsc
import file-name=LAN.rsc
file remove LAN.rsc"

添加一个路由表

1
/routing/table/add name=proxy fib disabled=no

添加一条静态路由到singbox

1
/ip/route/add dst-address=0.0.0.0/0 gateway=10.1.1.254 routing-table=proxy

需要走singbox代理的IP列表 (不要包含singbox的ip)

1
/ip/firewall/address-list/add address=10.1.1.10-10.1.1.244 list=Proxy disabled=no

再添加下面两条Mangle规则

1
ip/firewall/mangle/add chain=prerouting src-address-list=Proxy dst-address-list=LAN dst-address-type=!local,broadcast action=accept
1
ip/firewall/mangle/add chain=prerouting src-address-list=Proxy dst-address-list=!CN dst-address-type=!local,broadcast action=mark-routing new-routing-mark=proxy

最后把DHCP分配的DNS服务器改成10.1.1.254

image

然后插拔下网线或者重启下网卡,就能拿到新分配的DNS服务器了,也能正常分流了

image


RouterOS+SingBox国内外分流
https://2333.world/RouterOS-SingBox国内外分流/
作者
Yuban10703
发布于
2024年9月28日
许可协议