Skip to content

NTP ​

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

直接字段 ​

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

源码: option/ntp.go:5-11 · 锚定版本 v1.14.2 (af6e64c)

从 ServerOptions 继承 ​

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

从 DialerOptions 继承 ​

DialerOptions 由 detour 与共享的拨号字段集合 AbstractDialerOptions 组成(option/outbound.go:80-112)。配合 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 标为必填;若留空,底层 NTP 客户端会回退到 time.apple.com。仍建议显式写出。
  • write_to_system 在 Linux 上通常需要 root,在 Windows 上需要管理员权限。即使操作系统时钟无法更新,sing-box 仍会在内部使用同步得到的时间用于 TLS 时钟偏差容忍。

源码: option/ntp.go:5-11 · v1.14.2 (af6e64c)

由 Argsment 出品的 Core Tutorial