1

I am trying to get NTP working on a Raspberry Pi using ntpd. I've disabled systemd-timesyncd and installed ntp by using:

$ sudo apt-get install ntp

But after installing it, ntp does not synchronise with any servers. After re-installing ntp, it sometimes connects to one or two servers and synchronises. But after a reset (sudo service ntp restart), it can't connect to any server anymore.

I am using a Raspberry Pi 2 model B and a Raspberry Pi 3 model B+. It doesn't work for both devices. I also have one Raspberry Pi 3 model B which does work as expected. The Raspberry Pi's are all connected to the same network (therefore, it can't be the fault of the firewall of the network). The Raspberry Pi's run on Raspbian Buster.

Sometimes when it is synchronising correctly, I execute ntpd -p and see that there are only one or two servers. But the Raspberry Pi that works correctly synchronises with 4+ servers. NTP worked before on the Raspberry Pi 2 model B, but it stopped working without changing anything to the system. Afterwards, I did a full reinstall of NTP, but with no success (sudo apt-get purge --autoremove ntp). These results are with the default configuration file in /etc/ntp.conf.

I cannot use systemd-timesyncd because I want this system to become a server for underlying systems. systemd-timesyncd seems to work fine though, but I need a server for < 1ms clock synchronisation between devices.

Status of NTP

Below I've placed the status of NTP and the result of ntpq -pn

The status of ntp after a restart:

pi@raspberrypi:~ $ sudo service ntp status
● ntp.service - Network Time Service
   Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-04-24 14:48:10 CEST; 5s ago
     Docs: man:ntpd(8)
  Process: 2837 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
 Main PID: 2843 (ntpd)
    Tasks: 2 (limit: 2200)
   Memory: 1.0M
   CGroup: /system.slice/ntp.service
           └─2843 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 109:114

Apr 24 14:48:10 raspberrypi ntpd[2843]: Listen normally on 3 eth0 192.168.0.103:123
Apr 24 14:48:10 raspberrypi ntpd[2843]: Listen normally on 4 lo [::1]:123
Apr 24 14:48:10 raspberrypi ntpd[2843]: Listen normally on 5 eth0 [fe80::1ef8:d982:66ac:4214%2]:123
Apr 24 14:48:10 raspberrypi ntpd[2843]: Listening on routing socket on fd #22 for interface updates
Apr 24 14:48:10 raspberrypi ntpd[2843]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized
Apr 24 14:48:10 raspberrypi ntpd[2843]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized
Apr 24 14:48:11 raspberrypi ntpd[2843]: Soliciting pool server 174.138.9.187
Apr 24 14:48:12 raspberrypi ntpd[2843]: Soliciting pool server 194.5.96.30
Apr 24 14:48:13 raspberrypi ntpd[2843]: Soliciting pool server 162.159.200.123
Apr 24 14:48:14 raspberrypi ntpd[2843]: Soliciting pool server 83.162.149.224

The result of ntpq -pn:

pi@raspberrypi:~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
 1.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
 2.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001
 3.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.001

The result of ntpstat:

pi@raspberrypi:~ $ ntpstat
unsynchronised
   polling server every 8 s

Does anyone know the cause of NTP not synchronising with a server?

The output of sudo ntpdate -qu 0.debian.pool.ntp.org:

pi@raspberrypi:~ $ sudo ntpdate -qu 0.debian.pool.ntp.org
server 213.136.0.252, stratum 1, offset 0.017778, delay 0.04608
server 45.159.204.28, stratum 2, offset 0.016319, delay 0.04184
server 83.98.155.30, stratum 2, offset 0.016869, delay 0.04346
server 94.228.220.14, stratum 2, offset 0.017546, delay 0.04454
24 Apr 16:23:17 ntpdate[3139]: adjust time server 213.136.0.252 offset 0.017778 sec

The configuration in /etc/ntp.conf:

pi@raspberrypi:~ $ grep '^[^#]' /etc/ntp.conf
driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
pool 0.debian.pool.ntp.org iburst
pool 1.debian.pool.ntp.org iburst
pool 2.debian.pool.ntp.org iburst
pool 3.debian.pool.ntp.org iburst
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery

Result of timedatectl status:

pi@raspberrypi:~ $ timedatectl status
               Local time: Fri 2020-04-24 16:40:05 CEST
           Universal time: Fri 2020-04-24 14:40:05 UTC
                 RTC time: n/a
                Time zone: Europe/Amsterdam (CEST, +0200)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no
7
  • When you run date, is the date/time accurate to within five minutes? It seems you're CEST, so when date --utc do you get an output that's approximately TWO hours behind your local time? As an example, it's 15:25 CEST right now, so I'd expect UTC to be 13:25. Commented Apr 24, 2020 at 13:24
  • Next questions. How long did you wait after (re)starting NTP before you tried ntpq -np? You must need to wait at 64 seconds before you'll get anything form ntpq -pn, and up to eight minutes for full synchronisation. It's looking like you cannot get to any of the chosen pool servers - you do have Internet connectivity? Commented Apr 24, 2020 at 13:27
  • I have internet connectivity and it is running for at least 20 minutes now without connecting to any server. Also the time is 15:32 CEST and therefore 13:32 UTC on the date of today. So that should also not be the problem. Commented Apr 24, 2020 at 13:31
  • 1
    Yeah, it is reasonably accurate and the timezone is correctly set in raspi-config Commented Apr 24, 2020 at 13:36
  • 1
    It should be the default NTP file. I've added the file to the post. Also, I noticed that it eventually connected to an NTP server. But that took around an hour, and my other Raspberry Pi connects with multiple servers within seconds. Both connected with ethernet to the same router (and they contain the same Raspbian version). Could it maybe be due to systemd-timesyncd? Although I disabled it (added this to the post too). Commented Apr 24, 2020 at 14:41

1 Answer 1

1

The issue is that the parameter System clock synchronised in timedatectl status should be yes. Though, I noticed that this is not always the case.

This is a correct output of timedatectl status:

$ timedatectl status
               Local time: Tue 2020-04-28 11:28:44 CEST
           Universal time: Tue 2020-04-28 09:28:44 UTC
                 RTC time: n/a
                Time zone: Europe/Amsterdam (CEST, +0200)
System clock synchronized: yes
              NTP service: inactive
          RTC in local TZ: no

This issue can be solved by executing the steps below.

You should first delete ntpd, else systemd-timesyncd could have issues starting. This can be achieved by the following command (this command does not remove /etc/ntp.conf):

sudo apt-get remove ntp

Afterwards, ntp can be enabled and ```systemd-timesyncd`` can be started by running the command:

sudo timedatectl set-ntp yes

This command automatically turns systemd-timesyncd on. Therefore, systemd-timesyncd should be stopped and disabled. This can be achieved by the following commands:

sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd

ntpd can now be reinstalled:

sudo apt-get install ntp

Now, ntpd can be restarted using the following command:

sudo service ntp restart

Check if it works correctly

You can check if ntp works correctly by executing the following commands:

ntpq -pn should return multiple IP's.

ntpstat should say it is synchronised to an NTP server. ntpstat can be installed with the command:

sudo apt-get install ntpstat

You must log in to answer this question.

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