---
title: "How to Setup Ubuntu NTP Server"
description: "Learn to configure an Ubuntu NTP server for precise time synchronization across your network. Ensure seamless operations with accurate timekeeping!"
canonical: "https://adamtheautomator.com/ubuntu-ntp/"
---

# How to Setup Ubuntu NTP Server

> Learn to configure an Ubuntu NTP server for precise time synchronization across your network. Ensure seamless operations with accurate timekeeping!

Source: https://adamtheautomator.com/ubuntu-ntp/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Setup Ubuntu NTP Server](https://adamtheautomator.com/wp-content/uploads/2024/03/ubuntu-ntp.jpg)

# How to Setup Ubuntu NTP Server

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)18 March 20246 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Ubuntu Linux](/tag/ubuntu-linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing and Configuring the Ubuntu NTP Server](#installing-and-configuring-the-ubuntu-ntp-server)
*   [Enabling and Securing the NTP Service Connection](#enabling-and-securing-the-ntp-service-connection)
*   [Installing and Configuring the Ubuntu NTP Client](#installing-and-configuring-the-ubuntu-ntp-client)
*   [Verifying the NTP Synchronization Works](#verifying-the-ntp-synchronization-works)
*   [Conclusion](#conclusion)

In the digital world, getting timing right is key to keeping smooth event loggings or handling database transactions. Messing up the timing invites chaos and errors, risking your systems and data integrity. But have you heard of a Network Time Protocol (NTP) server? With an Ubuntu NTP setup, you have the perfect tool to keep your system ticking along without a hitch!

This tutorial will walk you through setting up an NTP server as a reliable way to ensure consistent timing across your network.

Turn your system into a beacon of accurate timekeeping for your network!

## **Prerequisites**

Below are preparatory steps crucial to ensure a smooth and successful installation process for your NTP server:

*   Two servers running Ubuntu 18.04 or higher: One configured as the NTP (Network Time Protocol) server, and the other as a client – This tutorial uses Ubuntu 20.04 servers. Still, the instructions are compatible with any server edition of Ubuntu 18.04 or newer.

Related:[Install Ubuntu Server 20.04: A Step-by-Step Walkthrough](https://adamtheautomator.com/install-ubuntu/)

*   A user with `sudo` privileges on both servers.

Related:[How to Create a User on Ubuntu Linux in Multiple Ways](https://adamtheautomator.com/create-user-on-ubuntu/)

## Installing and Configuring the Ubuntu NTP Server

Accurate time synchronization is vital, from maintaining consistent logs to ensuring smooth coordination between distributed systems. By correctly setting up your Ubuntu NTP server, you lay a solid foundation for efficient time management within your network infrastructure.

To install and configure your Ubuntu NTP server, carry out the following:

1\. Open a terminal and execute the following [`apt update`](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update) command to update your server’s package index.

```bash
sudo apt update -y
```

![Updating the server's package index](https://adamtheautomator.com/wp-content/uploads/2024/03/image-128.png)

Updating the server’s package index

Related:[Ubuntu Apt Get Mastery: A Guide with Practical Examples](https://adamtheautomator.com/ubuntu-apt-get/)

2\. Once updated, run the command below to [`install`](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) the NTP package.

```bash
sudo apt install ntp -y
```

![Installing the NTP package](https://adamtheautomator.com/wp-content/uploads/2024/03/image-127.png)

Installing the NTP package

3\. Next, open NTP server’s configuration file (_/etc/ntp.conf_) in your preferred editor (i.e., `nano` or [`vim`](https://adamtheautomator.com/vim-for-linux/)), and comment out the default servers.

Related:[How to Get Started With Gedit Linux](https://adamtheautomator.com/gedit-linux/)

As shown below, the default configuration uses various NTP pool servers, generally providing accurate time. But, you will achieve better synchronization by using time sources closer to your geographic location.

![Commenting out the default servers](https://adamtheautomator.com/wp-content/uploads/2024/03/image-126.png)

Commenting out the default servers

4\. Now, open your favorite web browser, visit the [NTP Pool Servers](https://www.ntppool.org/zone/@) page, and pick servers from the list closest to your region for better performance.

![Picking servers to add to the pool of servers](https://adamtheautomator.com/wp-content/uploads/2024/03/image-125.png)

Picking servers to add to the pool of servers

5\. Return to the NTP server’s configuration file, add your chosen servers underneath the commented default servers, save the changes, and close the editor.

Adding servers from the NTP Pool Project to your NTP configuration is not just about sprucing up your settings but casting a wider net for time accuracy.

Imagine your local machine as a cozy timekeeper in its own right. But by roping in these servers from all corners of the globe, managed by folks, you give your network’s time sync a serious upgrade.

![Adding servers to the NTP server configuration file](https://adamtheautomator.com/wp-content/uploads/2024/03/image-124.png)

Adding servers to the NTP server configuration file

6\. With added servers, run the below `systemctl` command to `restart` the NTP service and apply your configuration changes.

This command has no output, but you will confirm the result later in the following step.

```bash
sudo systemctl restart ntp
```

Related:[Correct Way of Using Ubuntu systemctl to Control Systemd](https://adamtheautomator.com/ubuntu-systemctl/)

7\. Lastly, execute the following command to check the `status` of the NTP service.

```bash
sudo systemctl status ntp
```

If everything goes well, you will see an **active (running)** message in the output, which confirms your server is now acting as a reliable time source for your network.

![Checking the status of the NTP service](https://adamtheautomator.com/wp-content/uploads/2024/03/image-123.png)

Checking the status of the NTP service

## Enabling and Securing the NTP Service Connection

With a fully configured NTP service, you must ensure a secure connection to the service by managing your firewall. By default, UFW on Ubuntu is configured to allow all outbound connections and deny all incoming connections, including incoming traffic, to the NTP service.

Related:[How To Set Up the UFW Firewall on Linux](https://adamtheautomator.com/ufw-firewall/)

To enable NTP clients to synchronize time with your server, you must allow incoming traffic on the port used by NTP as follows:

Execute the following [`ufw`](https://help.ubuntu.com/community/UFW)command to create a UFW rule to `allow` traffic on UDP port `123`, which is the port NTP uses for its communication.

This configuration ensures your server is protected by UFW while still allowing NTP clients to communicate with your NTP server for time synchronization.

```bash
sudo ufw allow 123/udp
```

![Allowing incoming traffic to the NTP service](https://adamtheautomator.com/wp-content/uploads/2024/03/image-130.png)

Allowing incoming traffic to the NTP service

Now, run the command below to check the detailed (`verbose`) `status` of the UFW firewall.

```bash
sudo ufw status verbose
```

The output indicates incoming connections on port 123 for UDP traffic are allowed, as shown below.

![Checking the UFW firewall status](https://adamtheautomator.com/wp-content/uploads/2024/03/image-129.png)

Checking the UFW firewall status

## Installing and Configuring the Ubuntu NTP Client

Coming off the heels of securing your NTP service connection, you need a diligent timekeeper, syncing its clock with external NTP servers. You will set up an Ubuntu NTP client to ensure precise timekeeping.

To install and configure the Ubuntu NTP client, proceed with these steps:

1\. On your client system, execute the following command to `update` the package lists and `install` the NTP client software.

```bash
sudo apt update -y && sudo apt install ntpdate -y && sudo apt install ntp -y
```

![Update the package lists and install the NTP client software](https://adamtheautomator.com/wp-content/uploads/2024/03/image-135.png)

Update the package lists and install the NTP client software

2\. Next, switch to your NTP server and run the command below to display information about the NTP server’s network configuration and hostname.

```bash
hostname -I && hostname
```

Note the NTP server’s local IPv4 IP address (i.e., **192.168.1.3**) and hostname (i.e., **ntpserver**), as you will need them to configure your NTP client.

![Retrieving the NTP server’s local IP and the hostname](https://adamtheautomator.com/wp-content/uploads/2024/03/image-134.png)

Retrieving the NTP server’s local IP and the hostname

3\. Back on your client, open the hosts file (`/etc/hosts`) in your editor, add the following line to the end of the file, save the changes, and close the editor.

```
<Server_IP_Address> <Server_Hostname>
```

This hosts file update resolves the NTP server’s hostname to its IP address. Thus, ensure you replace `<Server_IP_Address>` and `<Server_Hostname>` with your NTP server’s IP address and hostname you noted in step two.

![Ensuring hostname resolution ](https://adamtheautomator.com/wp-content/uploads/2024/03/image-133.png)

Ensuring hostname resolution

Related:[Discovering the Ansible Hosts File](https://adamtheautomator.com/ansible-hosts-file/)

4\. Now, open the NTP configuration file (_/etc/ntp.conf_) on your client machine, comment out the default servers, then add your own NTP server line as follows.

Substitute `<Server_Hostname>` with the actual hostname of your NTP server, save the changes, and exit the editor. This configuration allows your NTP client to resolve the hostname to the corresponding IP address when attempting to synchronize its time.

```
server <Server_Hostname>
```

![Editing the NTP configuration file on the client machine](https://adamtheautomator.com/wp-content/uploads/2024/03/image-132.png)

Editing the NTP configuration file on the client machine

5\. Subsequently, run the command below to `enable` the NTP service on the client. Doing so ensures your NTP client synchronizes its time with the configured NTP server upon restart.

```bash
sudo systemctl enable ntp
```

![Enabling the NTP service on the client](https://adamtheautomator.com/wp-content/uploads/2024/03/image-131.png)

Enabling the NTP service on the client

6\. Lastly, execute the following `systemctl` command to `restart` the NTP service on the client machine to apply the changes.

This command produces no output to the terminal but you will later verify the synchronization works.

```bash
sudo systemctl restart ntp
```

## Verifying the NTP Synchronization Works

With all configurations done, you must ensure everything is ticking just right by diving into verifying the NTP synchronization works. You will verify your client machine is accurately adjusted according to the server.

To verify the NTP synchronization works, proceed as follows:

On your client machine, execute the [`ntpq`](https://www.thegeekdiary.com/ntpq-command-examples-in-linux/) command to query the NTP server status.

```bash
ntpq -p
```

The output shows a list of servers ([NTP peers](https://study-ccnp.com/ntp-peer-explanation-configuration)) your client communicates with, including the Ubuntu NTP server you set up earlier (**ntpserver**):

| Attribute | Details |
| --- | --- |
| remote | The IP address or hostname of your system’s NTP server or peer is synchronizing with. |
| refid | The reference ID of the peer could be an IP address or a special identifier representing the source of time synchronization for that peer. |
| st | The stratum level of the NTP server. Stratum 1 servers are directly connected to an authoritative time source (i.e., atomic clock), while Stratum 2 servers synchronize with Stratum 1 servers, and so on. |
| t | Indicates the type of peer. For example: ‘l’ is the local reference clock, ‘u’ is the unspecified source, ‘s’ is the symmetric active mode peer, and ‘x’ is the discarded or unreachable peer. |
| when | Indicates the time in milliseconds since the last response from the peer was received. |
| poll | The poll interval represents how often your system sends packets to the peer to obtain time updates. |
| reach | The reachability register indicates the recent success or failure of requests to the peer. |
| delay | The estimated round-trip delay between your system and the peer (measured in milliseconds). |
| offset | The time difference between your system’s and the peer’s clock (measured in milliseconds). |
| jitter | The estimated jitter or variability in the time measurements between your system and the peer (measured in milliseconds). |

![Verifying the NTP Synchronization](https://adamtheautomator.com/wp-content/uploads/2024/03/image-136.png)

Verifying the NTP Synchronization

## Conclusion

Successfully configuring an Ubuntu NTP server is not merely a technical necessity but an essential pillar for any robust network infrastructure. By harnessing the power of NTP, you are now equipped with the ability to orchestrate precise and unified timekeeping across all nodes within your digital realm.

But why stop here? Keep exploring different advanced configurations and features available through NTP to enhance timekeeping in your network. Why not dive deeper into the [_ntp.conf_](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/s1-understanding_the_ntpd_configuration_file) file and explore configuration directives at your disposal?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-ntp%2F&text=How%20to%20Setup%20Ubuntu%20NTP%20Server)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-ntp%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-ntp%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2022/04/How-to-Install-Apache-on-Ubuntu.jpg)

### [Install Apache on Ubuntu and Master Website Traffic Management](/install-apache-on-ubuntu/)

Ready to optimize your website for high traffic? Install Apache on Ubuntu with this step-by-step guide and ensure smooth performance under heavy loads.

![](https://adamtheautomator.com/wp-content/uploads/2022/04/How-to-Install-MySQL-on-Ubuntu.jpg)

### [Install MySQL on Ubuntu: Get Your Database Server Up and Running](/install-mysql-on-ubuntu/)

Want a robust, secure database for your projects? Discover how to install MySQL on Ubuntu and implement essential security measures with this guide.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
