NTP, Network Time Protocol is the theme of today's post! This isn't the be all and end all, font of all knowledge blog post. Rather an aide memoir.
What is NTP?
Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.
NTP is used to ensure that our computers are synchronised...but why?
Well if the time on our computer is incorrect then if we visit a website that uses SSL/TLS or another security certificate our computer may reject the certificate and claim that the site is insecure. The same is true for SSH connections.
Using NTP we can keep our clock set correctly and typically this is handled automatically via the operating system.
But what if you need to tinker with your NTP settings? Well you can and for this project I used a spare Raspberry Pi 3 as a test subject (No Pis were harmed in the creation of this post.)
On the Pi
Starting off I powered up the Pi and then opened a terminal. In the terminal I updated the repositories and then installed
sudo apt update && sudo apt install ntp
With that installed I then checked the status of the NTP service, running behind the scenes of the operating system.
sudo service ntp status
And I saw
● ntp.service - LSB: Start NTP daemon Loaded: loaded (/etc/init.d/ntp; generated; vendor preset: enabled) Active: active (running) since Thu 2018-01-25 10:35:14 GMT; 17min ago Docs: man:systemd-sysv-generator(8) Process: 18485 ExecStop=/etc/init.d/ntp stop (code=exited, status=0/SUCCESS) Process: 18670 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS) CGroup: /system.slice/ntp.service └─18681 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 111:116 Jan 25 10:35:14 raspberrypi ntpd: Listening on routing socket on fd #22 for interface updates Jan 25 10:35:15 raspberrypi ntpd: Soliciting pool server 188.8.131.52 Jan 25 10:35:16 raspberrypi ntpd: Soliciting pool server 184.108.40.206 Jan 25 10:35:17 raspberrypi ntpd: Soliciting pool server 220.127.116.11 Jan 25 10:35:17 raspberrypi ntpd: Soliciting pool server 18.104.22.168 Jan 25 10:35:18 raspberrypi ntpd: Soliciting pool server 22.214.171.124 Jan 25 10:35:18 raspberrypi ntpd: Soliciting pool server 126.96.36.199 Jan 25 10:35:19 raspberrypi ntpd: Soliciting pool server 188.8.131.52 Jan 25 10:35:19 raspberrypi ntpd: Soliciting pool server 184.108.40.206 Jan 25 10:36:21 raspberrypi ntpd: Soliciting pool server 220.127.116.11
So in this case my NTP service was working and checking the time. So lets turn it off.
sudo service ntp stop
Then we can manually ask NTP to update the time from the NTP servers.
sudo ntpd -qg
-q switch is used to automatically close the ntpd tool once the date / time is set.
-g switch stops the ntp tool from panicing if the update is particularly large (say changing the date from 2013 to 2018)
Now we can restart the NTP service.
sudo service ntp start
The check the date / time from the terminal.
Which looks like
[email protected]:/etc $ date Thu 25 Jan 11:03:54 GMT 2018
So there we go, a quick whistlestop tour of NTP, and how to fix the most common issue.