UbuntuUbuntu Based

How To Install NTP on Ubuntu 22.04 LTS

Install NTP on Ubuntu 22.04

In this tutorial, we will show you how to install NTP on Ubuntu 22.04 LTS. For those of you who didn’t know, NTP is a networking protocol designed to synchronize the clocks of computers across a network. It works by exchanging timestamped messages between NTP servers and clients, allowing them to adjust their local clocks to match a reference time source. NTP uses a hierarchical structure of servers, known as strata, to ensure accurate timekeeping. Stratum 0 servers are the primary reference clocks, such as atomic clocks or GPS receivers, while stratum 1 servers synchronize directly with stratum 0 devices. Stratum 2 servers synchronize with stratum 1 servers, and so on, up to stratum 15.

NTP employs sophisticated algorithms to select the best clock sources and compensate for network latency, ensuring that the time on all devices remains accurate. By regularly synchronizing with reliable time sources, NTP helps maintain a consistent and precise time across a network, even in the presence of network delays and clock drift.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the NTP on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for NTP.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install NTP on Ubuntu 22.04 LTS Jammy Jellyfish

Step 1. To begin, update your Ubuntu server’s package lists and install the ntp package, which contains the NTP server and client components. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade
sudo apt install wget apt-transport-https gnupg2 software-properties-common

Step 2. Installing NTP on Ubuntu 22.04.

NTP is readily available in the Ubuntu repository. To install it, open a terminal and run the following command below:

sudo apt install ntp

Once the installation is complete, NTP will be automatically started, and it will synchronize the system clock with the default NTP server pool.

Step 3. Configuring NTP Server.

In some cases, you may want to configure your Ubuntu 22.04 system to act as an NTP server. This is particularly useful in a network environment where you have many devices that need to synchronize their time with a central server.

To configure your Ubuntu 22.04 system as an NTP server, you need to edit the NTP configuration file located at /etc/ntp.conf. Open the file using your preferred text editor:

nano /etc/ntp.conf

Install NTP on Ubuntu 22.04 LTS Jammy Jellyfish

If you’re looking to optimize the accuracy and reliability of your network time synchronization, it may be a good idea to switch to NTP server pools that are geographically closer to your location. The NTP Pool Project website is a great resource to help you find the closest NTP server pool. To demonstrate, let’s say you’re in Singapore and want to update your NTP configuration files with a list of nearby servers. You can easily replace the default NTP pool list in the configuration files with the new servers from the NTP Pool Project website.

Next, restart the NTP service for the changes to take effect:

sudo systemctl restart ntp

To verify that the NTP server is running correctly, use the following command:

sudo systemctl status ntp

Step 4. Configuring NTP Client.

If you have other devices on your network that need to synchronize their time with the Ubuntu 22.04 NTP server, you need to configure them as NTP clients.

To configure an NTP client, you need to edit the NTP configuration file located at /etc/ntp.conf. Open the file using your preferred text editor:

nano /etc/ntp.conf

Add the following line:

server (your-ntp-server-ip)

Save and close the file, then restart the NTP service for the changes to take effect:

sudo systemctl restart ntp

Step 5. Opening Firewall for NTP

To allow NTP traffic through your Ubuntu server’s firewall, you need to open UDP port 123. If you are using the ufw firewall, run the following command:

sudo ufw allow 123/udp

If you have clients on other networks that need to synchronize with your NTP server, you may need to configure additional firewall rules on your network devices to allow NTP traffic.

Step 6. Verify NTP Synchronization.

After configuring and restarting the NTP service, we can verify that the system is synchronized with the NTP server. Run the following command to check the status of the NTP service:

ntpq -p

This command will display a list of NTP servers and their synchronization status. If your system is properly synchronized, you should see an asterisk (*) next to the NTP server you added to the ntp.conf file.

Step 7. Troubleshooting NTP Issues

If you encounter issues with NTP synchronization, consider the following troubleshooting tips:

  • Ensure that the NTP server and client are reachable on the network and that firewalls are not blocking UDP port 123.
  • Verify that the NTP configuration files (/etc/ntp.conf) on both the server and client are properly configured and point to the correct NTP servers.
  • Check the NTP log files (/var/log/ntp.log) for any error messages or indications of synchronization problems.
  • Use the ntpdate command to perform a one-time synchronization and check if the clock is adjusted correctly.
  • Restart the NTP service on both the server and client using sudo systemctl restart ntp to apply any configuration changes.

If the issue persists, consult the official NTP documentation and community forums for further assistance and guidance specific to your setup.

Congratulations! You have successfully installed NTP. Thanks for using this tutorial for installing the NTP on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official NTP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button