Ubuntu 22.04: NTP Server
From:     https://linuxconfig.org/ubuntu-22-04-ntp-server


Intro Install NTP Server Cofig NTP Server NTP Client Config
Step 1 Step 2 Step 3 Step 4
Step 5 Step 6 Step 7 Appendix
NTPQ Command Col Ouput NTPQ Command Row Output Closing Thoughts Related Linux Tuts



Ubuntu 22.04 NTP server

25 April 2022 by Korbin Brown NTP stands for Network Time Protocol and is used for clock synchronization across multiple computers. An NTP server is responsible for keeping a set of computers in sync with each other. On a local network, the server should be able to keep all client systems to within a single millisecond of each other. Such a configuration would be necessary if, for example, the systems needed to start or stop a task in unison at a precise time. In this article, we’ll show you how to configure an NTP server on Ubuntu 22.04 Jammy Jellyfish and how to configure a client system to sync its system time with said server. In this tutorial you will learn: Ubuntu 22.04 NTP server Software Requirements and Linux Command Line Conventions
CategoryRequirements, Conventions or Software Version Used
SystemUbuntu 22.04 Jammy Jellyfish
SoftwareNTP server daemon
OtherPrivileged access to your Linux system as root or via the sudo command.
Conventions# – requires given linux commands to be executed with root privileges either
directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non -privileged user
Install NTP server
To begin, we need to install NTP server. You can do so by opening a command line terminal and entering the following command: $ sudo apt update $ sudo apt install ntp Configure NTP server
The NTP server comes pre-configured with some server pools already, which you can see inside the /etc/ntp.conf file. $ cat /etc/ntp.conf The default server pools inside our NTP config file The default server pools inside our NTP config file Generally, it’s best to replace these lines with server pools from your own country, or at least your own continent. The less latency between you and a time server, the better. You can use the NTP Pool Project website to find the closest NTP server pool to your location. Find your closest server pools from the NTP Pool Project website. Once you find the most relevant zone, all you need to do is add the lines in your config file by using nano or your preferred text editor: $ sudo nano /etc/ntp.conf Enter the servers into the NTP config file Once you’ve made these changes, save and exit the configuration file. Restart the NTP service for the changes to take effect: $ sudo systemctl restart ntp Check on the status of the NTP service at any time with this command: $ sudo systemctl status ntp The status of NTP server daemon Clients trying to connect to your NTP server will be doing so on UDP port 123. If you have the UFW firewall enabled on you system, be sure to configure it to allow these incoming connection requests: $ sudo ufw allow from any to any port 123 proto udp Rules updated Rules updated (v6) NTP client configuration
Now that we have an NTP server up and running, we will show how client systems can connect to it for time synchronization. Just follow the steps below on your client systems: Step 1 First, we need to install the ntpdate package. We can use this to verify connectivity between the client and the NTP time server we created. $ sudo apt update $ sudo apt install ntpdate Step 2 Next, let’s attempt to manually sync our system time with the NTP server. Type the following command, substituting your NTP server’s IP address or hostname where appropriate: $ sudo ntpdate 192.168.100.4 Connection to NTP server is successful Step 3 That seems to be working as we’d expect. Next, be sure to disable Ubuntu’s default timesyncd service, as this will conflict with our attempts to synchronize with the NTP server. $ sudo timedatectl set-ntp off Step 4 Now, we need to install the NTP daemon on our client system so we can configure it to pull the time from our NTP server that we set up earlier. $ sudo apt install ntp Step 5 We only need to add a single line to our ntp.conf file, and we can do that very easily with a single command. Just make sure to replace the IP address below with either the hostname or the IP address of your NTP server. $ sudo bash -c "echo server 192.168.100.4 prefer iburst >> /etc/ntp.conf" Step 6 Then, restart the NTP daemon: $ sudo systemctl restart ntp Step 7 Lastly, use the ntpq command to list the NTP time synchronization queue: $ ntpq -p Output from the ntpq command The asterisk * in the screenshot above indicates that our NTP server 192.168.100.4 is selected as the current time synchronization source. This should remain the case unless the NTP server goes offline, as that’s how we’ve configured it inside the ntp.conf configuration file. Read the below appendix for more information on how to interpret the ntpq command’s output. Appendix
NTPQ Command column output interpretation: NTPQ Command row output interpretation:
Ref: Ref: https://pthree.org/2013/11/05/real-life-ntp/ Closing Thoughts
In this tutorial, we learned about the National Time Protocol (NTP) and how to setup our own NTP server on Ubuntu 22.04 Jammy Jellyfish. We also saw how to configure a client machine (or multiple machines, as is usually the case) to connect to the NTP server for time synchronization. Related Linux Tutorials: