NTP
sing-box 内置 NTP 客户端。ntp 块用于启用它、设置查询间隔,并可选 地把结果写回系统时钟。服务器与拨号器分别来自内嵌的 ServerOptions 与 DialerOptions,因此所有常规出站旋钮(绑定接口、路由 mark、 detour 等)都可用。
直接字段
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
enabled | bool | false | true | false | 运行内嵌 NTP 客户端。为 false 时块内其他字段被忽略。 |
interval | badoption.Duration | 30m | <duration> | 两次 NTP 查询的间隔。接受 "5m"、"30m"、"1h" 这类字符串。 |
write_to_system | bool | false | true | false | 每次同步成功后把时间写入操作系统时钟。需要更高的权限。 |
源码: option/ntp.go:5-11 · 锚定版本 v1.13.11 (553cfa1)
从 ServerOptions 继承
| 键 | 类型 | 描述 |
|---|---|---|
server | string | NTP 服务器主机名或 IP。 |
server_port | uint16 | NTP 服务器端口(除非提供方特殊,否则为 123)。 |
从 DialerOptions 继承
DialerOptions 是完整的出站拨号旋钮集合(option/outbound.go:67)。 配合 NTP 常用的字段:bind_interface、routing_mark、reuse_addr、 tcp_fast_open、detour。完整字段集合见 出站页。
示例
json
{
"ntp": {
"enabled": true,
"server": "time.cloudflare.com",
"server_port": 123,
"interval": "30m",
"write_to_system": false,
"detour": "direct"
}
}说明
- 若
server留空,默认工厂会使用time.cloudflare.com,但仍建议 显式写出。 write_to_system在 Linux 上通常需要 root,在 Windows 上需要管 理员权限。即使操作系统时钟无法更新,sing-box 仍会在内部使用同步 得到的时间用于 TLS 时钟偏差容忍。
源码: option/ntp.go:5-11 · v1.13.11 (553cfa1)
