文件与规则 · 技术说明

按监听、解析和分流查阅参考配置

查看配置时,可先按本地监听、控制接口、域名解析、出口选择和分流条件划分区域。示例里的字段展示书写位置,具体取值需要结合运行环境确认。

  • mixed-port
  • proxy-groups
  • external-controller
  • GEOIP
  • MATCH

旧版行为与适用边界

旧配置中的功能限制与内核代际有关。迁移到其他实现时,应重新确认字段支持情况;旧版的能力边界不能直接套用到正在运行的软件。

不同实现的字段差异可查阅 现用内核配置说明;涉及界面操作、安装步骤或权限时,另查 所用程序的使用指引 中的适用条件。

yaml
# HTTP(S) 请求的本地监听位置
port: 7890

# SOCKS5 请求的本地监听位置
socks-port: 7891

# 透明接入示例:TCP 及 TProxy UDP 重定向,适用于所列系统
# redir-port: 7892

# TProxy 同时接收 TCP 与 UDP 的透明接入示例
# tproxy-port: 7893

# 共享监听:HTTP(S) 与 SOCKS4(A)/SOCKS5 使用同一入口
# mixed-port: 7890

# 本地入口的访问身份配置
# authentication:
#  - "user1:pass1"
#  - "user2:pass2"

# 需要接收局域网其他地址的请求时启用
# allow-lan: false

# 下面的绑定设置以 allow-lan 已开启为前提
# '*': 在全部地址上监听
# 192.168.122.11: 只监听指定 IPv4 地址
# "[aaaa::a8aa:ff:fe09:57d8]": 只监听指定 IPv6 地址
# bind-address: '*'

# 请求转发的处理模式
# rule: 按条件决定出口
# global: 统一使用同一出口
# direct: 直接发往目标网络
mode: rule

# 未调整日志去向时,输出写往 STDOUT
# 输出详细程度可选择 info / warning / error / debug / silent
# log-level: info

# 关闭此项后,名称解析不返回 IPv6 地址
# ipv6: false

# 控制接口接收请求的位置
external-controller: 127.0.0.1:9090

# 界面资源目录可写相对配置目录的路径,也可写绝对路径;访问入口为
# `http://{{external-controller}}/ui`
# external-ui: folder

# 控制接口可设置访问凭证
# 请求头携带凭证:Authorization: Bearer ${secret}
# 监听地址采用 0.0.0.0 时,应填写 secret 来限制访问。
# secret: ""

# 转发流量所用的接口
# interface-name: en0

# 数据包标记示例,仅适用于原示例所列系统
# routing-mark: 6666

# 静态名称记录可用于解析与建连,形式可参照 /etc/hosts
#
# 名称记录可使用通配表达式,如 *.example.dev 或 *.foo.*.example.com
# 名称重叠时,精确写法先于通配写法
# 查找顺序示意:foo.example.com > *.example.com > .example.com
# +.foo.com 同时覆盖 foo.com 与其下级名称
# hosts:
  # '*.example.dev': 127.0.0.1
  # '.dev': 127.0.0.1
  # 'alpha.example.dev': '::1'

# profile:
  # select 的选择结果可写入配置目录中的缓存文件
  # 不保留选择结果时,关闭此项
  # 不同配置里名称相同的组,会复用已保存的选择
  # store-selected: true

  # 保存 fake-ip 映射状态
  # store-fake-ip: false

# 名称解析入口
# 未写此区域时,不开启内置解析服务
dns:
  enable: false
  listen: 0.0.0.0:53
  # ipv6: false # 关闭后,AAAA 请求返回空结果

  # 先用此处的服务器解析后续解析服务的主机名
  # 此处填写地址字面值
  default-nameserver:
    - 114.114.114.114
    - 8.8.8.8
  # enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16 # fake-ip 可分配范围
  # use-hosts: true # 使用静态名称记录作答

  # search-domains: [local] # 名称补全所用的搜索域

  # 名单中的名称跳过 fake-ip 映射
  # 对这些名称直接返回真实地址
  # fake-ip-filter:
  #   - '*.lan'
  #   - localhost.example.com

  # 可用传输方式包括 UDP、TCP、DoT 和 DoH,端口可单独填写
  # 查询直接交给解析服务器处理
  # 多个响应返回时,以最先到达的结果作答
  nameserver:
    - 114.114.114.114 # 原示例取值
    - 8.8.8.8 # 原示例取值
    - tls://dns.example.com:853 # DNS over TLS
    - https://1.1.1.1/dns-query # DNS over HTTPS
    - dhcp://en0 # 使用接口分配的解析服务
    # - '8.8.8.8#en0'

  # 配置 fallback 后,查询会同时发往备用服务器
  # 和 nameserver 所列服务器
  # GEOIP 判断为非 CN 时,采用备用结果
  # fallback:
  #   - tcp://1.1.1.1
  #   - 'tcp://1.1.1.1#en0'

  # 主解析结果落入下列网段时,
  # 将其排除,转而采用备用解析结果
  #
  # 开启 fallback-filter.geoip 且地址归属为 CN 时,
  # 采用主解析服务器返回的地址
  #
  # 关闭地域过滤且地址未命中排除网段时,
  # 继续使用主解析结果
  #
  # 这些条件用于筛选解析结果
  # fallback-filter:
  #   geoip: true
  #   geoip-code: CN
  #   ipcidr:
  #     - 240.0.0.0/4
  #   domain:
  #     - '+.example.com'
  #     - '+.example.net'
  #     - '+.example.org'

  # 为指定名称单独选择解析服务器
  # nameserver-policy:
  #   'www.example.com': '114.114.114.114'
  #   '+.internal.crop.com': '10.0.0.1'

proxies:
  # Shadowsocks
  # 可填写的加密方法示例:
  #   aes-128-gcm aes-192-gcm aes-256-gcm
  #   aes-128-cfb aes-192-cfb aes-256-cfb
  #   aes-128-ctr aes-192-ctr aes-256-ctr
  #   rc4-md5 chacha20-ietf xchacha20
  #   chacha20-ietf-poly1305 xchacha20-ietf-poly1305
  - name: "ss1"
    type: ss
    server: server
    port: 443
    cipher: chacha20-ietf-poly1305
    password: "password"
    # udp: true

  - name: "ss2"
    type: ss
    server: server
    port: 443
    cipher: chacha20-ietf-poly1305
    password: "password"
    plugin: obfs
    plugin-opts:
      mode: tls # or http
      # host: example.com

  - name: "ss3"
    type: ss
    server: server
    port: 443
    cipher: chacha20-ietf-poly1305
    password: "password"
    plugin: v2ray-plugin
    plugin-opts:
      mode: websocket # 旧示例未包含 QUIC 支持
      # tls: true # wss
      # skip-cert-verify: true
      # host: example.com
      # path: "/"
      # mux: true
      # headers:
      #   custom: value

  # vmess
  # 可填写的加密方法示例:
  #  auto/aes-128-gcm/chacha20-poly1305/none
  - name: "vmess"
    type: vmess
    server: server
    port: 443
    uuid: uuid
    alterId: 32
    cipher: auto
    # udp: true
    # tls: true
    # skip-cert-verify: true
    # servername: example.com # 覆盖 wss 主机设置
    # network: ws
    # ws-opts:
    #   path: /path
    #   headers:
    #     Host: example.com
    #   max-early-data: 2048
    #   early-data-header-name: Sec-WebSocket-Protocol

  - name: "vmess-h2"
    type: vmess
    server: server
    port: 443
    uuid: uuid
    alterId: 32
    cipher: auto
    network: h2
    tls: true
    h2-opts:
      host:
        - http.example.com
        - http-alt.example.com
      path: /

  - name: "vmess-http"
    type: vmess
    server: server
    port: 443
    uuid: uuid
    alterId: 32
    cipher: auto
    # udp: true
    # network: http
    # http-opts:
    #   # method: "GET"
    #   # path:
    #   #   - '/'
    #   #   - '/video'
    #   # headers:
    #   #   Connection:
    #   #     - keep-alive

  - name: vmess-grpc
    server: server
    port: 443
    type: vmess
    uuid: uuid
    alterId: 32
    cipher: auto
    network: grpc
    tls: true
    servername: example.com
    # skip-cert-verify: true
    grpc-opts:
      grpc-service-name: "example"

  # socks5
  - name: "socks"
    type: socks5
    server: server
    port: 443
    # username: username
    # password: password
    # tls: true
    # skip-cert-verify: true
    # udp: true

  # http
  - name: "http"
    type: http
    server: server
    port: 443
    # username: username
    # password: password
    # tls: true # https
    # skip-cert-verify: true
    # sni: custom.com

  # Snell
  # 旧示例的此类出口未提供 UDP 支持
  - name: "snell"
    type: snell
    server: server
    port: 44046
    psk: yourpsk
    # version: 2
    # obfs-opts:
      # mode: http # or tls
      # host: example.com

  # Trojan
  - name: "trojan"
    type: trojan
    server: server
    port: 443
    password: yourpsk
    # udp: true
    # sni: example.com # 服务端名称
    # alpn:
    #   - h2
    #   - http/1.1
    # skip-cert-verify: true

  - name: trojan-grpc
    server: server
    port: 443
    type: trojan
    password: "example"
    network: grpc
    sni: example.com
    # skip-cert-verify: true
    udp: true
    grpc-opts:
      grpc-service-name: "example"

  - name: trojan-ws
    server: server
    port: 443
    type: trojan
    password: "example"
    network: ws
    sni: example.com
    # skip-cert-verify: true
    udp: true
    # ws-opts:
      # path: /path
      # headers:
      #   Host: example.com

  # ShadowsocksR
  # 加密取值可参照 ss 的流加密类型
  # 混淆参数的可选写法:
  #   plain http_simple http_post
  #   random_head tls1.2_ticket_auth tls1.2_ticket_fastauth
  # 协议参数的可选写法:
  #   origin auth_sha1_v4 auth_aes128_md5
  #   auth_aes128_sha1 auth_chain_a auth_chain_b
  - name: "ssr"
    type: ssr
    server: server
    port: 443
    cipher: chacha20-ietf
    password: "password"
    obfs: tls1.2_ticket_auth
    protocol: auth_sha1_v4
    # obfs-param: domain.tld
    # protocol-param: "#"
    # udp: true

proxy-groups:
  # 串联多个出口时,链内不再嵌套中继;此方式不承载 UDP
  # 连接依次经过本地程序、http、vmess、ss1、ss2,最后到达目标网络
  - name: "relay"
    type: relay
    proxies:
      - http
      - vmess
      - ss1
      - ss2

  # url-test 按目标 URL 的响应情况选择出口
  - name: "auto"
    type: url-test
    proxies:
      - ss1
      - ss2
      - vmess1
    # tolerance: 150
    # lazy: true
    url: 'http://www.gstatic.com/generate_204'
    interval: 300

  # fallback 按排列顺序寻找可用出口,借助指定 URL 判断可用情况
  - name: "fallback-auto"
    type: fallback
    proxies:
      - ss1
      - ss2
      - vmess1
    url: 'http://www.gstatic.com/generate_204'
    interval: 300

  # 负载分配时,相同 eTLD+1 的请求保持使用同一出口
  - name: "load-balance"
    type: load-balance
    proxies:
      - ss1
      - ss2
      - vmess1
    url: 'http://www.gstatic.com/generate_204'
    interval: 300
    # strategy: consistent-hashing # or round-robin

  # select 由使用者指定当前出口或选择组
  # 可经由图形界面或 RESTful API 更改选择
  - name: Proxy
    type: select
    # disable-udp: true
    # filter: 'someregex'
    proxies:
      - ss1
      - ss2
      - vmess1
      - auto

  # 选择组也能使用指定接口、标记或其他代理出口
  - name: en1
    type: select
    interface-name: en1
    routing-mark: 6667
    proxies:
      - DIRECT

  - name: UseProvider
    type: select
    use:
      - provider1
    proxies:
      - Proxy
      - DIRECT

proxy-providers:
  provider1:
    type: http
    url: "url"
    interval: 3600
    path: ./provider1.yaml
    health-check:
      enable: true
      interval: 600
      # lazy: true
      url: http://www.gstatic.com/generate_204
  test:
    type: file
    path: /test.yaml
    health-check:
      enable: true
      interval: 36000
      url: http://www.gstatic.com/generate_204

tunnels:
  # 紧凑写法示例
  - tcp/udp,127.0.0.1:6553,114.114.114.114:53,proxy
  - tcp,127.0.0.1:6666,db.example.com:3306,vpn
  # 分字段写法示例
  - network: [tcp, udp]
    address: 127.0.0.1:7777
    target: target.com
    proxy: proxy

rules:
  - DOMAIN-SUFFIX,example.com,auto
  - DOMAIN-KEYWORD,example,auto
  - DOMAIN,example.com,auto
  - DOMAIN-SUFFIX,ad.com,REJECT
  - SRC-IP-CIDR,192.168.1.201/32,DIRECT
  # GEOIP、IP-CIDR、IP-CIDR6 等地址条件可附加 no-resolve
  - IP-CIDR,127.0.0.0/8,DIRECT
  - GEOIP,CN,DIRECT
  - DST-PORT,80,DIRECT
  - SRC-PORT,7777,DIRECT
  - RULE-SET,apple,REJECT # 旧版扩展内核适用
  - MATCH,auto