Specifically, how to configure a highly accurate Stratum-1 NTP server on your Linux machine. But first, let’s take a moment to appreciate the beauty of this task.
Why would anyone want to do this? Well, for starters, it’s not like we can just rely on our computer’s built-in clock anymore. Those things are as accurate as a drunken sailor trying to hit a moving target with a blindfold on. Nope, if you really care about timekeeping (and let’s face it, who doesn’t?), then you need an NTP server that can sync up your system clock with atomic clocks around the world.
Now, before we dive into the details of configuring this beast, let’s take a moment to appreciate just how cool it is. Imagine being able to set your watch by looking at your computer screen! No more fumbling for a wristwatch or checking your phone every five minutes. Just look over at your trusty NTP server and voila you know exactly what time it is, down to the nanosecond.
Okay, enough with the fanfare. Let’s get started. To start, make sure that your system clock is already set correctly using the `timedatectl` command:
# Set the system clock to a specific date and time using the timedatectl command
# The sudo command is used to run the command as a superuser, allowing for system changes
sudo timedatectl set-time "2021-07-31 14:30:00"
This will manually set the time to July 31, 2021 at 2:30 PM. If you’re not sure what time it is right now, just replace that with your current time. Next, let’s install NTP on our system using `apt-get` (or whatever package manager you prefer):
# Update the package list and upgrade any outdated packages
sudo apt-get update && sudo apt-get upgrade -y
# Install NTP and NTPdate packages using apt-get
sudo apt-get install ntp ntpdate -y
This will download and install the NTP server and client. Once that’s done, we need to configure our system to use an external time source by editing the `/etc/ntp.conf` file:
#!/bin/bash
# This line specifies the interpreter to be used for executing the script
sudo nano /etc/ntp.conf
# This command opens the /etc/ntp.conf file in the nano text editor with root privileges
# Add the following lines to the end of the file to configure the system to use an external time source:
server <external_time_source> # Replace <external_time_source> with the IP address or domain name of the external time source
restrict default kod nomodify notrap nopeer noquery # Restricts default access to the server
restrict -6 default kod nomodify notrap nopeer noquery # Restricts default IPv6 access to the server
# Save and exit the file by pressing Ctrl+X, then Y, then Enter
sudo systemctl restart ntp # Restarts the NTP service to apply the changes
# The following command checks the status of the NTP service to ensure it is running properly
systemctl status ntp
# If the service is not running, use the following command to start it:
sudo systemctl start ntp
# Finally, use the following command to enable the NTP service to start automatically on system boot:
sudo systemctl enable ntp
# This ensures that the NTP service will start automatically every time the system is booted up.
Add these lines at the bottom of the file (replace “pool.ntp.org” with your preferred NTP server):
# Add these lines at the bottom of the file (replace "pool.ntp.org" with your preferred NTP server):
# The following lines are used to configure the NTP server and specify the preferred NTP server to be used.
server pool.ntp.org iburst # Specifies the NTP server to be used and uses the iburst option for faster synchronization.
fudge 0.us.pool.ntp.org minpoll 4 maxpoll 8 prefer # Specifies the preferred NTP server for the first NTP server pool and sets the minimum and maximum poll intervals to 4 and 8 respectively.
fudge 1.us.pool.ntp.org minpoll 4 maxpoll 8 prefer # Specifies the preferred NTP server for the second NTP server pool and sets the minimum and maximum poll intervals to 4 and 8 respectively.
fudge 2.us.pool.ntp.org minpoll 4 maxpoll 8 prefer # Specifies the preferred NTP server for the third NTP server pool and sets the minimum and maximum poll intervals to 4 and 8 respectively.
This will configure our system to use three different NTP servers as backup options, and set some preferences for them (minpoll and maxpoll). Once that’s done, save the file and exit. Now let’s restart the NTP service:
# Restart the NTP service using systemctl command with sudo privileges
sudo systemctl restart ntp
And finally, we need to synchronize our clock with an external time source using `ntpdate` (which is included in the package we installed earlier):
# This script is used to synchronize the system clock with an external time source using ntpdate.
# It is assumed that the ntpdate package has been installed beforehand.
# The following command uses sudo to run ntpdate with the -s flag to enable logging and the pool.ntp.org server as the external time source.
sudo ntpdate -s pool.ntp.org
This will sync up your system clock with the NTP server you specified, and set it to use UTC time. And that’s it! Your system should now be using an external time source for highly accurate timekeeping. Of course, there are a lot of other options and configurations available depending on your needs (such as setting up a Stratum-2 or higher NTP server), but this is the basic setup to get you started.
So go ahead, set that clock and enjoy the precision! Your wristwatch will thank you later.