
Clash Config 配置示例
2024年7月23日
折腾科学上网
YAML1# HTTP(S) 代理服务端口 2port: 7890 3 4# SOCKS5 代理服务端口 5socks-port: 7891 6 7# Linux 和 macOS 的透明代理服务端口 (TCP 和 TProxy UDP 重定向) 8# redir-port: 7892 9 10# Linux 的透明代理服务端口 (TProxy TCP 和 TProxy UDP) 11# tproxy-port: 7893 12 13# HTTP(S) 和 SOCKS4(A)/SOCKS5 代理服务共用一个端口 14# mixed-port: 7890 15 16# 本地 SOCKS5/HTTP(S) 代理服务的认证 17# authentication: 18# - "user1:pass1" 19# - "user2:pass2" 20 21# 设置为 true 以允许来自其他 LAN IP 地址的连接 22# allow-lan: false 23 24# 仅当 `allow-lan` 为 `true` 时有效 25# '*': 绑定所有 IP 地址 26# 192.168.122.11: 绑定单个 IPv4 地址 27# "[aaaa::a8aa:ff:fe09:57d8]": 绑定单个 IPv6 地址 28# bind-address: '*' 29 30# Clash 路由工作模式 31# rule: 基于规则的数据包路由 32# global: 所有数据包将被转发到单个节点 33# direct: 直接将数据包转发到互联网 34mode: rule 35 36# 默认情况下, Clash 将日志打印到 STDOUT 37# 日志级别: info / warning / error / debug / silent 38# log-level: info 39 40# 当设置为 false 时, 解析器不会将主机名解析为 IPv6 地址 41# ipv6: false 42 43# RESTful Web API 监听地址 44external-controller: 127.0.0.1:9090 45 46# 配置目录的相对路径或静态 Web 资源目录的绝对路径. Clash core 将在 47# `http://{{external-controller}}/ui` 中提供服务. 48# external-ui: folder 49 50# RESTful API 密钥 (可选) 51# 通过指定 HTTP 头 `Authorization: Bearer ${secret}` 进行身份验证 52# 如果RESTful API在 0.0.0.0 上监听, 务必设置一个 secret 密钥. 53# secret: "" 54 55# 出站接口名称 56# interface-name: en0 57 58# fwmark (仅在 Linux 上有效) 59# routing-mark: 6666 60 61# 用于DNS服务器和连接建立的静态主机 (如/etc/hosts) . 62# 63# 支持通配符主机名 (例如 *.clash.dev, *.foo.*.example.com) 64# 非通配符域名优先级高于通配符域名 65# 例如 foo.example.com > *.example.com > .example.com 66# P.S. +.foo.com 等于 .foo.com 和 foo.com 67# hosts: 68 # '*.clash.dev': 127.0.0.1 69 # '.dev': 127.0.0.1 70 # 'alpha.clash.dev': '::1' 71 72# profile: 73 # 将 `select` 手动选择 结果存储在 $HOME/.config/clash/.cache 中 74 # 如果不需要此行为, 请设置为 false 75 # 当两个不同的配置具有同名的组时, 将共享所选值 76 # store-selected: true 77 78 # 持久化 fakeip 79 # store-fake-ip: false 80 81# DNS 服务设置 82# 此部分是可选的. 当不存在时, DNS 服务将被禁用. 83dns: 84 enable: false 85 listen: 0.0.0.0:53 86 # ipv6: false # 当为 false 时, AAAA 查询的响应将为空 87 88 # 这些 名称服务器(nameservers) 用于解析下列 DNS 名称服务器主机名. 89 # 仅指定 IP 地址 90 default-nameserver: 91 - 114.114.114.114 92 - 8.8.8.8 93 # enhanced-mode: fake-ip 94 fake-ip-range: 198.18.0.1/16 # Fake IP 地址池 CIDR 95 # use-hosts: true # 查找 hosts 并返回 IP 记录 96 97 # search-domains: [local] # A/AAAA 记录的搜索域 98 99 # 此列表中的主机名将不会使用 Fake IP 解析 100 # 即, 对这些域名的请求将始终使用其真实 IP 地址进行响应 101 # fake-ip-filter: 102 # - '*.lan' 103 # - localhost.ptlogin2.qq.com 104 105 # 支持 UDP、TCP、DoT、DoH. 您可以指定要连接的端口. 106 # 所有 DNS 查询都直接发送到名称服务器, 无需代理 107 # Clash 使用第一个收到的响应作为 DNS 查询的结果. 108 nameserver: 109 - 114.114.114.114 # 默认值 110 - 8.8.8.8 # 默认值 111 - tls://dns.rubyfish.cn:853 # DNS over TLS 112 - https://1.1.1.1/dns-query # DNS over HTTPS 113 - dhcp://en0 # 来自 dhcp 的 dns 114 # - '8.8.8.8#en0' 115 116 # 当 `fallback` 存在时, DNS 服务器将向此部分中的服务器 117 # 与 `nameservers` 中的服务器发送并发请求 118 # 当 GEOIP 国家不是 `CN` 时, 将使用 fallback 服务器的响应 119 # fallback: 120 # - tcp://1.1.1.1 121 # - 'tcp://1.1.1.1#en0' 122 123 # 如果使用 `nameservers` 解析的 IP 地址在下面指定的子网中, 124 # 则认为它们无效, 并使用 `fallback` 服务器的结果. 125 # 126 # 当 `fallback-filter.geoip` 为 true 且 IP 地址的 GEOIP 为 `CN` 时, 127 # 将使用 `nameservers` 服务器解析的 IP 地址. 128 # 129 # 如果 `fallback-filter.geoip` 为 false, 且不匹配 `fallback-filter.ipcidr`, 130 # 则始终使用 `nameservers` 服务器的结果 131 # 132 # 这是对抗 DNS 污染攻击的一种措施. 133 # fallback-filter: 134 # geoip: true 135 # geoip-code: CN 136 # ipcidr: 137 # - 240.0.0.0/4 138 # domain: 139 # - '+.google.com' 140 # - '+.facebook.com' 141 # - '+.youtube.com' 142 143 # 通过特定的名称服务器查找域名 144 # nameserver-policy: 145 # 'www.baidu.com': '114.114.114.114' 146 # '+.internal.crop.com': '10.0.0.1' 147 148proxies: 149 # Shadowsocks 150 # 支持的加密方法: 151 # aes-128-gcm aes-192-gcm aes-256-gcm 152 # aes-128-cfb aes-192-cfb aes-256-cfb 153 # aes-128-ctr aes-192-ctr aes-256-ctr 154 # rc4-md5 chacha20-ietf xchacha20 155 # chacha20-ietf-poly1305 xchacha20-ietf-poly1305 156 - name: "ss1" 157 type: ss 158 server: server 159 port: 443 160 cipher: chacha20-ietf-poly1305 161 password: "password" 162 # udp: true 163 164 - name: "ss2" 165 type: ss 166 server: server 167 port: 443 168 cipher: chacha20-ietf-poly1305 169 password: "password" 170 plugin: obfs 171 plugin-opts: 172 mode: tls # or http 173 # host: bing.com 174 175 - name: "ss3" 176 type: ss 177 server: server 178 port: 443 179 cipher: chacha20-ietf-poly1305 180 password: "password" 181 plugin: v2ray-plugin 182 plugin-opts: 183 mode: websocket # 暂不支持 QUIC 184 # tls: true # wss 185 # skip-cert-verify: true 186 # host: bing.com 187 # path: "/" 188 # mux: true 189 # headers: 190 # custom: value 191 192 # vmess 193 # 支持的加密方法: 194 # auto/aes-128-gcm/chacha20-poly1305/none 195 - name: "vmess" 196 type: vmess 197 server: server 198 port: 443 199 uuid: uuid 200 alterId: 32 201 cipher: auto 202 # udp: true 203 # tls: true 204 # skip-cert-verify: true 205 # servername: example.com # 优先于 wss 主机 206 # network: ws 207 # ws-opts: 208 # path: /path 209 # headers: 210 # Host: v2ray.com 211 # max-early-data: 2048 212 # early-data-header-name: Sec-WebSocket-Protocol 213 214 - name: "vmess-h2" 215 type: vmess 216 server: server 217 port: 443 218 uuid: uuid 219 alterId: 32 220 cipher: auto 221 network: h2 222 tls: true 223 h2-opts: 224 host: 225 - http.example.com 226 - http-alt.example.com 227 path: / 228 229 - name: "vmess-http" 230 type: vmess 231 server: server 232 port: 443 233 uuid: uuid 234 alterId: 32 235 cipher: auto 236 # udp: true 237 # network: http 238 # http-opts: 239 # # method: "GET" 240 # # path: 241 # # - '/' 242 # # - '/video' 243 # # headers: 244 # # Connection: 245 # # - keep-alive 246 247 - name: vmess-grpc 248 server: server 249 port: 443 250 type: vmess 251 uuid: uuid 252 alterId: 32 253 cipher: auto 254 network: grpc 255 tls: true 256 servername: example.com 257 # skip-cert-verify: true 258 grpc-opts: 259 grpc-service-name: "example" 260 261 # socks5 262 - name: "socks" 263 type: socks5 264 server: server 265 port: 443 266 # username: username 267 # password: password 268 # tls: true 269 # skip-cert-verify: true 270 # udp: true 271 272 # http 273 - name: "http" 274 type: http 275 server: server 276 port: 443 277 # username: username 278 # password: password 279 # tls: true # https 280 # skip-cert-verify: true 281 # sni: custom.com 282 283 # Snell 284 # 请注意, 目前还没有UDP支持. 285 - name: "snell" 286 type: snell 287 server: server 288 port: 44046 289 psk: yourpsk 290 # version: 2 291 # obfs-opts: 292 # mode: http # or tls 293 # host: bing.com 294 295 # Trojan 296 - name: "trojan" 297 type: trojan 298 server: server 299 port: 443 300 password: yourpsk 301 # udp: true 302 # sni: example.com # aka 服务器名称 303 # alpn: 304 # - h2 305 # - http/1.1 306 # skip-cert-verify: true 307 308 - name: trojan-grpc 309 server: server 310 port: 443 311 type: trojan 312 password: "example" 313 network: grpc 314 sni: example.com 315 # skip-cert-verify: true 316 udp: true 317 grpc-opts: 318 grpc-service-name: "example" 319 320 - name: trojan-ws 321 server: server 322 port: 443 323 type: trojan 324 password: "example" 325 network: ws 326 sni: example.com 327 # skip-cert-verify: true 328 udp: true 329 # ws-opts: 330 # path: /path 331 # headers: 332 # Host: example.com 333 334 # ShadowsocksR 335 # 支持的加密方法: ss 中的所有流加密方法 336 # 支持的混淆方式: 337 # plain http_simple http_post 338 # random_head tls1.2_ticket_auth tls1.2_ticket_fastauth 339 # 支持的协议: 340 # origin auth_sha1_v4 auth_aes128_md5 341 # auth_aes128_sha1 auth_chain_a auth_chain_b 342 - name: "ssr" 343 type: ssr 344 server: server 345 port: 443 346 cipher: chacha20-ietf 347 password: "password" 348 obfs: tls1.2_ticket_auth 349 protocol: auth_sha1_v4 350 # obfs-param: domain.tld 351 # protocol-param: "#" 352 # udp: true 353 354proxy-groups: 355 # 中继链路代理节点. 节点不应包含中继. 不支持 UDP. 356 # 流量节点链路: clash <-> http <-> vmess <-> ss1 <-> ss2 <-> Internet 357 - name: "relay" 358 type: relay 359 proxies: 360 - http 361 - vmess 362 - ss1 363 - ss2 364 365 # url-test 通过对 指定URL 进行基准速度测试来选择将使用哪个代理. 366 - name: "auto" 367 type: url-test 368 proxies: 369 - ss1 370 - ss2 371 - vmess1 372 # tolerance: 150 373 # lazy: true 374 url: 'http://www.gstatic.com/generate_204' 375 interval: 300 376 377 # fallback-auto 基于优先级选择可用策略. 可用性通过访问 指定URL 来测试, 就像自动 url-test 组一样. 378 - name: "fallback-auto" 379 type: fallback 380 proxies: 381 - ss1 382 - ss2 383 - vmess1 384 url: 'http://www.gstatic.com/generate_204' 385 interval: 300 386 387 # 负载均衡: 同一 eTLD+1 的请求将拨号到同一代理. 388 - name: "load-balance" 389 type: load-balance 390 proxies: 391 - ss1 392 - ss2 393 - vmess1 394 url: 'http://www.gstatic.com/generate_204' 395 interval: 300 396 # strategy: consistent-hashing # or round-robin 397 398 # select 手动选择, 用于选择代理或策略组 399 # 您可以使用 RESTful API 来切换代理, 建议在GUI中切换. 400 - name: Proxy 401 type: select 402 # disable-udp: true 403 # filter: 'someregex' 404 proxies: 405 - ss1 406 - ss2 407 - vmess1 408 - auto 409 410 # 直接连接到另一个接口名称或 fwmark, 也支持代理 411 - name: en1 412 type: select 413 interface-name: en1 414 routing-mark: 6667 415 proxies: 416 - DIRECT 417 418 - name: UseProvider 419 type: select 420 use: 421 - provider1 422 proxies: 423 - Proxy 424 - DIRECT 425 426proxy-providers: 427 provider1: 428 type: http 429 url: "url" 430 interval: 3600 431 path: ./provider1.yaml 432 health-check: 433 enable: true 434 interval: 600 435 # lazy: true 436 url: http://www.gstatic.com/generate_204 437 test: 438 type: file 439 path: /test.yaml 440 health-check: 441 enable: true 442 interval: 36000 443 url: http://www.gstatic.com/generate_204 444 445tunnels: 446 # 单行配置 447 - tcp/udp,127.0.0.1:6553,114.114.114.114:53,proxy 448 - tcp,127.0.0.1:6666,rds.mysql.com:3306,vpn 449 # 全 yaml 配置 450 - network: [tcp, udp] 451 address: 127.0.0.1:7777 452 target: target.com 453 proxy: proxy 454 455rules: 456 - DOMAIN-SUFFIX,google.com,auto 457 - DOMAIN-KEYWORD,google,auto 458 - DOMAIN,google.com,auto 459 - DOMAIN-SUFFIX,ad.com,REJECT 460 - SRC-IP-CIDR,192.168.1.201/32,DIRECT 461 # 用于 IP 规则 (GEOIP, IP-CIDR, IP-CIDR6) 的可选参数 "no-resolve" 462 - IP-CIDR,127.0.0.0/8,DIRECT 463 - GEOIP,CN,DIRECT 464 - DST-PORT,80,DIRECT 465 - SRC-PORT,7777,DIRECT 466 - RULE-SET,apple,REJECT # 仅 Premium 版本支持 467 - MATCH,auto
0
Likes


