Setup NTP on Debian

使用systemd自带的timesyncd服务, 代替第三方的ntp服务.

注意: 在Debian中, timesyncd.conf配置文件, 使用Servers=xxx, 而非NTP=xxx. 未来有变化, 需持续关注. 请参考

Disable NTP daemon

$ systemctl stop ntp
$ systemctl disable ntp
$ systemctl mask ntp

Enable systemd-timesyncd

$ timedatectl list-timezones | grep -i shanghai
$ timedatectl set-timezone Asia/Shanghai

$ cat /etc/systemd/timesyncd.conf
[Time]
Servers=192.168.1.1 192.168.31.1

$ timedatectl set-ntp true

$ systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)
   Active: active (running) since Tue 2016-11-01 10:31:33 CST; 35min ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 1761 (systemd-timesyn)
   Status: "Using Time Server 192.168.1.1:123 (192.168.1.1)."
   CGroup: /system.slice/systemd-timesyncd.service
           └─1761 /lib/systemd/systemd-timesyncd

$ timedatectl status
      Local time: Tue 2016-11-01 11:05:31 CST
  Universal time: Tue 2016-11-01 03:05:31 UTC
        RTC time: n/a
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes  
 RTC in local TZ: no
      DST active: n/a

NTP synchronizedyes时, 表示NTP同步成功.

OpenWrt NTP Server

$ dnsmasq --help dhcp | grep ntp
 42 ntp-server
 71 nntp-server
System ▷ System ▷ Time Synchronization:  
  Enable NTP client: yes
  Provide NTP server: yes
  NTP server candidates:
    - 0.openwrt.pool.ntp.org
    - 1.openwrt.pool.ntp.org
    - 2.openwrt.pool.ntp.org
    - 3.openwrt.pool.ntp.org

Network ▷ Interfaces ▷ LAN ▷ DHCP Server ▷ Advanced Settings:  
  DHCP-Options:
    - 42,192.168.1.1

References