What is NTP, why do you need it, and how to install/configure it? Guide for DevOps engineers.

Andrey Byhalenko
DevOps Manuals and Technical Notes
5 min readJan 29, 2024

Imagine you have several Ubuntu servers running different applications.

Each server sends logs to the logger server, and you have monitoring software that collects resource metrics. All services show logs with a timestamp, which requires all servers and devices in a network to have accurate and consistent time information.

This is where Network Time Protocol steps into the picture.

Photo by Jon Tyson on Unsplash

NTP stands for Network Time Protocol. The main purpose of NTP is to make sure that all computers and devices in a network have accurate and consistent time information.

The Network Time Protocol is a client-server application. Each device in a network must be equipped with NTP client software to synchronize its clock to the NTP server.

Here are five important NTP use cases for DevOps:

  • Network Security: Accurate timekeeping is crucial for network security. In the case of a security breach, having synchronized time is important to track the security events and incidents.
  • Logging and Monitoring Accuracy: NTP helps ensure consistent timestamps across multiple devices in the network, so you can be sure that the timestamp you see in the logger is reflecting the true time.
  • Automation servers and scripts: Any automation requires the execution of commands at precise times.
  • Distributed Systems and Cloud Computing: In distributed computing environments and cloud-based services, you have to make sure that all devices are synchronized in real time.
  • Working with databases: In databases, time synchronization is essential for transaction ordering, replication, and consistency models.

Let’s talk about two main NTP implementation methods: NTP in the internal, closed network, and NTP in the external network with internet access.

Closed network:

It’s a network without internet access, so you will need to install an NTP server inside the network and connect our NTP clients to it.

There is an option to use the router with a calendar function as an NTP server, but in this tutorial, I will use one of the Windows computers running Windows 10 for that.

Configure the NTP server (Windows 10):

Windows 10 PC will be an NTP server, and my Ubuntu 22.04 machines will update the time from it as NTP clients.

  • Proceed to Control Panel\System and Security\Administrative Tools.
    Open the Run dialog (Windows Key + R), type services.msc and click OK.
  • Stop the Windows Time service.
  • Update the Windows Registry. Open the Run dialog (Windows Key + R), type regedit and click OK.
  • Navigate to the registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters.
  • Create LocalNTP DWORD (32 bit) Value.
    Right click > New > DWORD (32 bit) Value > LocalNTP.
    Double-click on LocalNTP, change the Value data to 1, make sure Base of Hexadecimal, and click OK.
  • Now navigate to the registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer.
  • Double-click on Enabled, change Value data to 1, make sure Base of Hexadecimal, and click OK.
  • Navigate to the registry key: Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config.
  • Double click on AnnounceFlags, change Value data to 1, make sure Base of Hexadecimal, and click OK.
  • Close the Registry Editor.
  • Proceed to Control Panel\System and Security\Administrative Tools.
    Open the Run dialog (Windows Key + R), type services.msc and click OK.
  • Double-click on Windows Time, Startup time = Automatic, press Start, press OK.

The local NTP Time Server configuration is complete.
Now you can synchronize the time of other devices in your local network.

Configure the NTP client (Ubuntu 22.04):

First, get the IP address of the NTP server.

  • On the Windows NTP server, press the Windows key, type cmd and press Enter.
  • Execute the ipconfig command, you will see the IP address on the output.

Proceed to the Ubuntu 22.04 machine.

  • Run a system update.
sudo apt-get update && sudo apt-get upgrade -y
  • Install NTP.
sudo apt-get install ntp -y
  • Configure the NTP server IP.
sudo vim /etc/ntp.conf
  • Specify the NTP server to which you want to synchronize your machine.
# Specify one or more NTP servers.

server 192.168.56.1 iburst
  • Save the changes and close the editor.
  • If you are using a Linux firewall, you need to allow NTP.
sudo ufw allow 123/udp 
  • Restart the NTP service.
sudo systemctl restart ntp
  • Verify NTP is working by checking the status.
sudo systemctl status ntp
  • That’s it, you configured the NTP server and connected the NTP client (your Ubuntu machine) to it.

Network with internet access:

On a network with internet access, you can choose from many NTP servers and connect your devices to one of them.

For example:

Google Public NTP: https://developers.google.com/time

Cloudflare time services: https://www.cloudflare.com/time/

Microsoft NTP server: https://learn.microsoft.com/en-us/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings?tabs=config

There are many of them, choose your own based on your needs.

If you liked my articles, you can join my newsletter, and you will receive weekly DevOps tutorials, articles, and tips every Saturday.

As a bonus, you will receive a free step-by-step DevOps CI/CD project, which you can use in your portfolio.

Subscribe here: https://junior-devops-hub.ck.page

--

--

Andrey Byhalenko
DevOps Manuals and Technical Notes

I'm a DevOps Engineer, Photography Enthusiast, and Traveler. I write articles aimed at junior DevOps engineers and those aspiring to become DevOps engineers.