Ubuntu如何在没有ntp的情况下同步时间?

n3v*_*m03 41 time ntp

通过单击“系统设置 -> 时间和日期 -> 自动从 Internet”,我可以从 Internet 同步时间。

但是,我发现我没有ntpd守护进程(甚至没有安装)。那么同步是如何工作的呢?

May*_*hux 37

这是通过与ntpdate工具同步来完成的 。

man ntpdate

NAME
       ntpdate - set the date and time via NTP

ntpdate sets the local date and time by polling the Network Time Proto?
       col (NTP) server(s) given as the server arguments to determine the cor?
       rect time. It must be run as root on the local host (unless the  option
       -q  is used). A number of samples are obtained from each of the servers
       specified and a subset of the NTP clock filter and selection algorithms
       are  applied  to  select  the best of these. Note that the accuracy and
       reliability of ntpdate depends on the number of servers, the number  of
       polls each time it is run and the interval between runs.

       ntpdate  can  be run manually as necessary to set the host clock, or it
       can be run from the host startup script to set the clock at boot  time.
       This is useful in some cases to set the clock initially before starting
       the NTP daemon ntpd. It is also possible to run  ntpdate  from  a  cron
       script.  However,  it  is important to note that ntpdate with contrived
       cron scripts is no substitute for the NTP daemon, which uses  sophisti?
       cated  algorithms to maximize accuracy and reliability while minimizing
       resource use. Finally, since ntpdate does not discipline the host clock
       frequency as does ntpd, the accuracy using ntpdate is limited.
Run Code Online (Sandbox Code Playgroud)

你可以这样做

sudo ntpdate TIME-SERVER
Run Code Online (Sandbox Code Playgroud)

时间服务器列表可以在这里找到

  • 但问题是,Ubuntu 上默认没有安装 ntpdate,那么 Ubuntu *ever* 是如何同步时间的? (8认同)
  • 注意:这个被接受的答案已经过时了。在最新版本的 Ubuntu (16.04+) 上,使用 timedatectl 而不是 ntpdate。timedatectl 控制 systemd 的 timesyncd 服务。 (3认同)

tho*_*ter 21

ntpdate每次网络连接出现时,Ubuntu 都会与该实用程序同步一次(通常在您启动时发生)。

该实用程序默认安装,但仅在 Ubuntu 调用它时运行,并且不会作为守护程序在后台运行。

安装ntp软件包会安装 NTP 守护程序。ntp 守护进程允许在系统运行时持续同步时间。


更新:在最新版本的 Ubuntu(例如 16.04)中ntpdate被替换timedatectl,它在启动时和网络出现时同步一次,但在其他时间不会继续运行。有关更多信息,请参阅https://help.ubuntu.com/lts/serverguide/NTP.html

  • 它本身并不是每次启动时;按照 [`dpkg-query --listfiles ntpdate`](http://askubuntu.com/q/32507/1859) 到 [`/etc/network/if-up.d/ntpdate`](http://manpages .ubuntu.com/manpages/utopic/en/man5/interfaces.5.html#contenttoc3)。 (4认同)

Mys*_*jin 16

对于那些使用 16.04 LTS 时间同步的人来说,似乎由 sytemd 专门处理“timedatectl”

timedatectl status
Local time: Wed 2016-11-30 17:45:18 CST
Universal time: Wed 2016-11-30 23:45:18 UTC
RTC time: Sun 2016-12-04 06:50:39
Time zone: America/Chicago (CST, -0600)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
Run Code Online (Sandbox Code Playgroud)

配置是

/etc/systemd/timesyncd.conf
Run Code Online (Sandbox Code Playgroud)

更多信息:时间同步与 NTPtimedatectl

  • 这是目前最好的答案。其余的实际上是题外话(除了提到 systemd-timedatectl 的编辑过的那些)。 (2认同)