---
url: /configuration/route/rule-action.md
description: 路由规则的路由、拒绝、DNS 接管、嗅探、解析和选项动作
---

# 路由规则动作

规则用 `outbound` 隐式表示 `route`，或用 `action` 明确选择动作。

```yaml check
outbounds:
  direct:
    type: direct
  proxy:
    type: socks
    server: proxy.example:1080

route:
  rules:
    - {protocol: dns, action: hijack-dns}
    - {network: udp, port: 443, action: route-options, udp_timeout: 30s}
    - {domain_suffix: [blocked.example], action: reject, method: drop}
    - {domain_suffix: [example.com], action: sniff, sniffer: [tls, http], timeout: 1s}
    - {domain_suffix: [example.com], outbound: proxy}
  final: direct

dns:
  servers:
    default: {type: udp, address: 127.0.0.1:53}
  final: default
```

## 字段

### action

* 类型：字符串枚举。
* 默认：有 `outbound` 时是 `route`。
* 取值：`route`、`reject`、`hijack-dns`、`route-options`、`sniff`、`resolve`。

### outbound

* 类型：出站名。
* 必填：`route` 时是。
* 特殊值：`PASS`、`PASS-RULE` 继续下一条规则。

### method

* 类型：字符串枚举。
* 默认：`default`。
* 取值：`default`、`drop`、`unreachable`、`prohibited`。
* 限制：只用于 `reject`。

### no_drop

* 类型：布尔值。
* 默认：`false`。
* 限制：只用于默认的 reset/refused 拒绝；`drop`、`unreachable`、`prohibited` 不接受它。

### override_address

* 类型：IP 地址。
* 行为：`route-options` 替换流的目的地址。

### override_port

* 类型：`u16`。
* 行为：`route-options` 替换目的端口。

### udp_timeout

* 类型：时长。
* 行为：设置 UDP 会话空闲时间；后面的选项覆盖前面的。

### udp_disable_domain_unmapping

* 类型：布尔值。
* 默认：`false`。
* 行为：UDP 应答以回应地址返回，不映射回原域名。

### tls_fragment

* 类型：布尔值。
* 默认：`false`。
* 行为：把第一条 TLS 记录拆成多个等待前一段确认的 TCP 段。

### tls_fragment_fallback_delay

* 类型：时长。
* 行为：分片等待确认超时时的回退延迟。

### tls_record_fragment

* 类型：布尔值。
* 默认：`false`。
* 行为：把 ClientHello 切成多条 TLS 记录。

### sniffer

* 类型：协议名或数组。
* 默认：全部协议。
* 限制：只用于 `sniff`。

### timeout

* 类型：时长。
* 行为：`sniff` 等待首字节的时间，或 `resolve` 等待 DNS 的时间。

### server

* 类型：DNS 服务器名。
* 行为：`resolve` 直接询问该服务器，越过 DNS 规则。

### strategy

* 类型：字符串枚举。
* 取值：`as_is`、`prefer_ipv4`、`prefer_ipv6`、`ipv4_only`、`ipv6_only`。
* 行为：`resolve` 的地址族策略。

### disable_cache

* 类型：布尔值。
* 默认：`false`。
* 行为：`resolve` 不读也不写 DNS 缓存。

### client_subnet

* 类型：IP 地址或 CIDR。
* 行为：`resolve` 向上游发送 EDNS Client Subnet。

### rewrite_ttl

* 类型：32 位无符号整数，单位秒。
* 行为：`resolve` 改写响应 TTL，也决定缓存时间。

## 说明

只写 `outbound` 会选择 `route`。`route-options` 必须至少有一项选项，并且不能写 `outbound`。`sniff` 和 `resolve` 只负责补事实，不能同时写 `outbound` 或其他 route options。

`reject` 默认 reset/refused；30 秒内第五十一次重置后，后续连接改为静默丢弃，除非 `no_drop: true`。`method: drop` 直接丢弃，`unreachable` 和 `prohibited` 返回对应失败。

`PASS` 与 `PASS-RULE` 在当前规则模型里等价，都表示继续遍历下一条规则。

## 相关

* [路由规则](/configuration/route/rule)
* [协议探测](/configuration/route/sniff)
* [DNS 规则动作](/configuration/dns/rule-action)
