43

By clicking "System settings -> Time & Date -> Automatically from the Internet" I can synchronize time from the Internet.

However, I find that I don't have a ntpd daemon (It's not even installed). So how does the synchronization work?

3
  • 7
    Notice that that interface is, IMHO, misleading. It should be a button and not a switch because it fires a one-shot action, using ntpdate, --- you have to manually install ntp for having continouos time sync with the internet. I reported it in bugs.launchpad.net/ubuntu/+source/gnome-control-center/+bug/…
    – Rmano
    Jun 26, 2015 at 8:04
  • I'm not sure that it is misleading. I was under the impression it ran ntpdate once at every boot unless this option was disabled. Can anyone confirm? Jun 27, 2015 at 2:53
  • on Kubuntu 16.04, the clock widget don't even shows the Automatically from the Internet option or anything related.
    – kmonsoor
    Oct 13, 2016 at 14:04

7 Answers 7

36

This is done by synchronizing with ntpdate tool.

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.

You can do so with

sudo ntpdate TIME-SERVER

TIME-SERVER lists can be founded here

3
  • 8
    but the question is, ntpdate is not installed by default on Ubuntu, so how does Ubuntu ever sync the time? Feb 28, 2017 at 19:52
  • 4
    Note: this accepted answer is very outdated. On recent versions of Ubuntu (16.04+), timedatectl is used instead of ntpdate. timedatectl controls systemd's timesyncd service. Jun 10, 2017 at 23:47
  • Yes, this answer is off-topic. It's not "how to sync time without ntpd+ntpq", but "How UBUNTU does it without any of the above (ntpdate / ntpq). I found this question just after noticing that my clock is synchronized, and I expected it to be off by at least a few dozen seconds (Ubuntu 18.04). I also remember the hell that full blown NTPd is, when it refuses to sync time "too far off" etc. And now - the clock is synced! Magic. Nov 21, 2018 at 20:52
22

Ubuntu synchronises with the ntpdate utility once each time the network connection comes up (which usually happens when you boot).

This utility is installed by default, but only runs when Ubuntu calls it and does not stay running in the background as a daemon.

Installing the ntp package installs the NTP daemon. The ntp daemon allows for the time to be continually synchronised while the system is running.


Update: in recent versions of Ubuntu (eg 16.04) ntpdate is replaced by timedatectl, which synchonises once on boot as well as when a network comes up, but does not keep running at other times. See https://help.ubuntu.com/lts/serverguide/NTP.html for more.

4
  • 4
    It's not at each boot, per se; follow dpkg-query --listfiles ntpdate to /etc/network/if-up.d/ntpdate.
    – ændrük
    Jun 27, 2015 at 3:02
  • 1
    Ah thanks, so I guess it's each time the network interface comes up, which won't necessarily be each boot for everyone. Jun 28, 2015 at 5:33
  • ah you sure this is installed by default? I'm sitting here on a spanking new Ubuntu 16.04 server instance and there is no ntpdate util installed. Feb 28, 2017 at 19:52
  • 1
    ntpdate was installed by default in 14.04 but no longer in 16.04, it's now considered deprecated by timedatectl which works similarly - it's installed by default and synchronises once on boot, but also when a network comes up. Mar 1, 2017 at 3:59
17

For those of you with 16.04 LTS time sync appears to be handled by sytemd specifically "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

Config is

/etc/systemd/timesyncd.conf

More info here: Time Synchronisation with NTP AND timedatectl

1
  • 2
    This is the best answer as of now. The rest is practically off-topic (except the edited ones, which mention systemd-timedatectl). Nov 21, 2018 at 20:49
2

Note also that it is entirely possible for there to be a front-end interface, to a service which is not installed.

You can change the settings in that front-end (GUI) interface all you want, but if the service that actually performs the tasks isn't installed, nothing will happen.

Note however, that I think the "switch" is valid because it tells it to do the one-time update at EACH boot. (or to not do so).

Unless this is a not-network connected system, or there is some other overriding reason to NOT have its time set to match "standard" time, I would strongly urge you to install ntpd, and properly configure and run it.

2

Refer to: https://help.ubuntu.com/community/UbuntuTime

Ubuntu comes with ntpdate as standard, and will run it once at boot time to set up your time according to Ubuntu's NTP server. However, a system's clock is likely to drift considerably between reboots if the time between reboots is long. In that case it makes sense to correct the time occasionally. The easiest way to do this is to get cron to run it every day.

ntpdate ntp.ubuntu.com
2
1

For some reason, on 16.04, Maythux's answer doesn't work straight away.

But taking the lead from there, this worked for me.

$ sudo ntpdate-debian

Please note that it requires sudo privilege, obviously.

Under the hood, it uses ntpdate tool, differing only the config file.

ntpdate-debian is identical to ntpdate(8) except that it uses the configuration in /etc/default/ntpdate by default. ntpdate sets the local date and time by polling Network Time Protocol (NTP) servers.

3
  • 16.04 uses systemd so I would expect it to have an equivalent new command to use.
    – Rinzwind
    Oct 13, 2016 at 9:40
  • @Rinzwind that'd fantastic, of course. Unfortunately, the supposedly main page on Ubuntu wiki is not updated for 16.04. It shows a msg saying "This article needs updating to include the latest versions of Ubuntu".
    – kmonsoor
    Oct 13, 2016 at 13:51
  • At least in 14.04sudo ntpdate-debiandoes the same assudo ntpdate ntp.ubuntu.com. The strange is why did they picked and tweaked this package from debian when we read itis identical to ntpdate(8) except that it uses the configuration in /etc/default/ntpdate by defaultand catting this file we readNTPDATE_USE_NTP_CONF=yes # List of NTP servers to use (Separate multiple servers with spaces.) # Not used if NTPDATE_USE_NTP_CONF is yes. NTPSERVERS="ntp.ubuntu.com"???
    – useful
    Nov 5, 2017 at 18:06
1

Well the later Ubuntu releases often do it using chrony which is an alternative implementation of ntp with some differences:-

  1. Some of the more rarely used ntp features are not implemented
  2. It attempts to cope well with the situation where you have intermittent network access - When connected, it syncs the local clock and tracks how fast it drifts. When disconnected, it uses the local clock, but adjusts the time to allow for how it usually drifts.

See https://chrony.tuxfamily.org/ for more information.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .