19

I have a home server which runs an up to date Debian 7.5 (wheezy) installation.

I just discovered that the server has its internal clock set to ± 3 minutes in the future.

I knew that I could use NTP to synchronize Debian (and the motherboard internal clock) with NTP, so I installed NTP by following the steps described in the french Debian Wiki (the English page is less detailed).

I used the following command to sync the internal clock:

ntpdate -B -q 192.168.0.254

The clock was successfully adjusted. But this is a temporary solution, so I installed the NTP daemon and added a local server in the /etc/ntp.conf file:

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>

# added
server 192.168.0.254

server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

Is it the right solution? In fact I was surprised to find that the ntp daemon wasn't already installed. I'm wondering if the default installation of Debian installs a daemon to keep the internal clock synchronized. Are all the Debian installations time-shifting until their admins install ntpd?

Please tell me that the ntp daemon won't be useless because Debian has a built-in synchronization mechanism.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
A.L
  • 1,492
  • 3
  • 15
  • 29
  • Notice that you don't need to have both `ntp` and `ntpdate` installed anymore. Previously you needed `ntpdate` to initially set the time or `ntp` wouldn't start. That is not the case anymore. See `/usr/share/doc/ntp/NEWS.Debian.gz` Could be good to know. – Anders Apr 30 '15 at 14:57
  • @Anders is *anymore* referring to the last version of Debian? – A.L May 02 '15 at 00:09
  • No, it is like that many versions of the package ago, and it is documented in the package. See `/usr/share/doc/ntp/NEWS.Debian` for the date. – Anders May 03 '15 at 09:10
  • And if you uses the script `ntpdate-debian` (or something like that) it will use the same servers as `ntp`. See `/etc/defaults/ntpdate` and `/etc/defaults/ntp`. – Anders May 03 '15 at 09:18

3 Answers3

25

Debian expects you to install ntp yourself if you want your clock synchronized. Pretty much all you should have to do is apt-get install ntp. The default install, without any tasks, is fairly minimal.

I believe the GNOME desktop task, at least, will install it by default (as well as many other packages). Not sure if the other desktops will as well.

There isn't any other time synchronization method installed & running by default.

derobert
  • 107,579
  • 20
  • 231
  • 279
  • Yes, the only thing one might want to do is change the serves to something "closer" and one might serve the lan with time, so the DHCP-server might want to know this. – Anders Apr 30 '15 at 14:59
6

Note that with systemd apparently a different infrastructure involving timedatectl is in place (the old method still works though), see what the Arch guys write about it: https://wiki.archlinux.org/index.php/systemd-timesyncd

phk
  • 5,893
  • 7
  • 41
  • 70
5

For Debian GNU/Linux 10 (Buster), and next major versions:

The systemd-timesyncd (aka: timesyncd, aka: SystemD-TimeSyncD) is a lighter-weight & simpler alternative of ntpd.

View TimeSyncD NTP daemon's running status information in Debian:
cmd: systemctl status systemd-timesyncd
you may notice/see, the Status line in information is displaying "Idle".
If the Active line in information is NOT displaying "active (running)", then start it:
cmd: systemctl start systemd-timesyncd

If you have NOT enabled "SYSTEMD-TIMESYNCD" yet, then enable & start it:
cmd: systemctl enable systemd-timesyncd.service
cmd: systemctl start systemd-timesyncd.service

If SystemD-TimeSyncD is not enabling then you may have to remove NTPD, if it was installed earlier:
cmd: apt purge ntp

This new systemd-timesyncd daemon can also perform SNTP client functionality.

PROBLEM:
When viewing local time in Debian computer, and local time is not correct:
cmd: date
View status of System Clock Synchronized (SCS), run:
either, cmd: timedatectl
or, cmd: timedatectl status
You may notice/see below output from above timedatectl command: SCS is not working or time is not synced, that is: Debian computer is NOT obtaining & updating & displaying correct time information:

System clock synchronized: no
     NTP service: active

FIND NTP SERVER(s) CLOSE TO YOUR COMPUTER'S LOCATION:

Time information providing services are running in NTP SERVERS.

If your Debian computer is located in USA, or, if you want to use NTP server in USA, then goto this site:
    https://tf.nist.gov/tf-cgi/servers.cgi
Choose/select atleast two NTP servers that are geo-graphically closer to your Debian computer's physical geo-graphical location.
Select IPv4 type of IP address/addresses. If your Debian computer uses only IPv6 or also uses IPv6, then choose/select IPv6 type of IP address/addresses.

UPDATE "TIMESYNCD.CONF":

cmd: nano /etc/systemd/timesyncd.conf

Then add below 3 lines, if does not exist in timesyncd.conf:

[Time]
NTP=132.163.96.1
FallbackNTP=132.163.96.2,132.163.96.3,132.163.96.4,132.163.96.6

Specify only one server in "NTP=" line.
Specify multiple servers in "FallbackNTP=" line.
In above i'm displaying NTP servers from "Colorado, USA", as my Debian computer's location is in California, USA, which is close to Colorado, USA.

If your computer/device's DNS client (or DNS server/daemon) starts after the TimeSyncD NTP-client (or NTP server/daemon), then in "NTP=" or "FallbackNTP=" lines you should use IP address of NTP-server.
But, if your computer/device's DNS client (or DNS server/daemon) starts before the TimeSyncD NTP-client (or NTP server/daemon), then in "NTP=" or "FallbackNTP=" lines, you can use NTP-server's host-name (aka: server-name) for example: time-a-b.nist.gov instead of it's IP address 132.163.96.1.
And also note, even if your computer/device's DNS-client (or DNS server/daemon) starts after the TimeSyncD NTP-client (or NTP server/daemon) you can still use NTP-server's host-name in "NTP=" or "FallbackNTP=" lines, because TimeSyncD NTP client & local NTP server/daemon will again try to obtain/sync time, so it will succeed in 2nd or next time.
If your Debian computer/device will/does not have any DNS client (or DNS Server/daemon), then you have to use NTP-server's IP address.

You Must Change Above Displayed NTP Servers, based on YOUR Debian computer's actual location.

For example: if your Debian computer is located in Europe,
then goto here:
    https://www.pool.ntp.org/zone/europe
above website also lists other NTP servers for other locations.

As many servers, regular desktop/laptop, etc client computers, network devices, smartphones, etc, etc worldwide are using NTP servers,
so NTP servers are often overloaded,
so NTP servers might delay or take time to complete the response to your computer/device's query.

Please donate/contribute to NTP server operator, so they can afford faster/better server.

ACTIVATE NEW SETTINGS:

After creating or updating the timesyncd.conf file, then run below commands:
cmd: timedatectl show-timesync --all (verify new NTP configuration)
cmd: systemctl restart systemd-timesyncd (restart the local TimeSyncD NTP daemon)
cmd: timedatectl set-ntp true (enable & start NTP usage)

Now you can view status of System Clock Synchronized, run below any one of the command:
cmd: timedatectl or timedatectl status
you should see below lines:

System clock synchronized: yes
     NTP service: active

cmd: timedatectl timesync-status (view TimeSyncD NTP service connection info)

If you run the command systemctl status systemd-timesyncd, it should display "... Synchronized to time server for first time ...".

Run date command, it should show correct time, this time:
cmd: date
Displayed time should match with correct time, and it will be based on your pre-selected time-zone.

(sometime time server may delay to send the correct time response, so apply patience).

DONE.


OTHER SETTINGS/INFO:

cmd: timedatectl list-timezones (view time zones)
cmd: timedatectl set-timezone America/Los_Angeles (do this when you want to set time zone to PST, which is UTC-08:00)
cmd: timedatectl set-timezone UTC (do this when you want to set time zone to UTC. This UTC time is always same in all location all time, Every other time-zone is calculated, from this UTC time, by adding or subtracting specific numbers).

How can i view or obtain actual IP-addresses that are used by a NTP server (aka: hostname) or a NTP pool server ?
cmd: nslookup 1.europe.pool.ntp.org

If you have enabled firewall (aka: nftables, iptables, etc), then you should specify (multiple) IP-Address(es) of NTP Servers, in the NTP related UDP rules, to reduce abuse via NTP.

atErik
  • 171
  • 1
  • 5
  • I like your answer (because you talk about `systemd-timesyncd`), but if you'd simplify it, that'd be great! – Totor Aug 01 '22 at 12:34