Skip to content

NTP

sing-box 内置 NTP 客户端。ntp 块用于启用它、设置查询间隔,并可选 地把结果写回系统时钟。服务器与拨号器分别来自内嵌的 ServerOptionsDialerOptions,因此所有常规出站旋钮(绑定接口、路由 mark、 detour 等)都可用。

直接字段

字段类型默认值允许值描述
enabledboolfalsetrue | false运行内嵌 NTP 客户端。为 false 时块内其他字段被忽略。
intervalbadoption.Duration30m<duration>两次 NTP 查询的间隔。接受 "5m"、"30m"、"1h" 这类字符串。
write_to_systemboolfalsetrue | false每次同步成功后把时间写入操作系统时钟。需要更高的权限。

源码: option/ntp.go:5-11 · 锚定版本 v1.13.11 (553cfa1)

ServerOptions 继承

类型描述
serverstringNTP 服务器主机名或 IP。
server_portuint16NTP 服务器端口(除非提供方特殊,否则为 123)。

DialerOptions 继承

DialerOptions 是完整的出站拨号旋钮集合(option/outbound.go:67)。 配合 NTP 常用的字段:bind_interfacerouting_markreuse_addrtcp_fast_opendetour。完整字段集合见 出站页

示例

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)

由 Argsment 出品的 Core Tutorial