Install NTP on Ubuntu 18.04

If you ever wondered about the automatic switching to summer/winter time, or wondered how the computer takes information from the Internet about the exact time, adjusting the internal clock, then today’s article is for you. And for those who need to configure clock synchronization on the server that is running the operating system Ubuntu 18.04, and on the client computer where you have installed the same Linux distribution.

We will discuss about NTP the network time Protocol. He is widely used for solving such problems. After reading the article you will be able to:

  • Install NTP server and configure it to work on server versions of Ubuntu 18.04.
  • To install the NTP client application on the client machine with Ubuntu 18.04, as well as to ensure that synchronization with the server is as expected.

Setting NTP server on Ubuntu 18.04

All actions that you must take to achieve the goal — that is, to set the NTP server and time synchronization will be described step by step. To repeat them in the same sequence without missing anything.

Step 1: update the repository list

First, let’s consider how to install NTP Ubuntu server 18.04. But the installation of any software in Ubuntu is preceded by the following command:

sudo apt update-y

It is necessary for the OS to update the list of repositories and had the current list of software files installed on the hard disk.

Step 2: Install NTP-server

When the computer finishes execution of the previous command, it’s time to give him his next assignment. It is to install NTP on Ubuntu 18.04 c long term support. The command looks like this:

sudo apt install ntp

After its receipt, the system will check whether her installation files and report how much memory will occupy the program. The screen displays a request for installation, which you confirm by pressing Y and ENTER, or reject it by pressing N and Enter (in that case, if you decide to postpone the whole thing for later).

After completion it will not hurt to verify that the installation was successful. This can be done by asking the system what version of NTP is available on the computer at the moment:

sntp version

Step 3: configure the pools of NTP servers

The work of the NTP server the default is based on four native pools for Ubuntu. Their addresses registered in the configuration file /etc/ntp.conf . There is no direct need for anything here to change, however, it makes sense to replace the pools at those located closest to the physical location of the server.

Link https://support.ntp.org/bin/view/Servers/NTPPoolServers you can choose the most preferred pools. We use European NTP pools.

To rewrite the addresses of the pools, you need to open the aforementioned configuration file in a text editor. To do this, use the following command:

sudo vim /etc/ntp.conf

The list of pools is most convenient to copy the page and paste to a file instead of those that were there before:

sudo vim /etc/ntp.conf

server 0.europe.pool.ntp.org
server 1.europe.pool.ntp.org
server 2.europe.pool.ntp.org
server 3.europe.pool.ntp.org

Then have to save the file and close it. However, the changes in strength will not come to the server to synchronize with new pools, you must restart the NTP service and then check its status. Doing this with two commands:

sudo systemctl restart ntp

sudo systemctl status ntp

If a firewall is active UWF, client computers will not be able to obtain information from our server. In order to grant them access, you need to allow him to work with the NTP service by executing one of these commands:

sudo ufw allow ntp

sudo ufw allow 123 / udp

With the new settings, the firewall will work only after reboot:

sudo ufw reload

To check if everything is done correctly, you can use this command:

sudo ufw status

If your screen appeared the same as you see on the screenshot, then install and configure NTP server was successful. You can now go to the same action on the client machine.

Install and configure NTP client in Ubuntu 18.04

In this section you will learn how to setup NTP client on Ubuntu 18.04, which acts as a client and needs to sync Ubuntu time with our server that you set up earlier.

Step 1: Update repositories

The beginning is no different — you should run the command to update the list of repositories and files.

sudo apt update-y

After completion you can proceed to the next step.

Step 2: Install Ntpdate

Ntpdate is a utility that allows you to synchronize your computer time (local) with the server (global). It uses the resources of the NTP. To install the system and dedicated team

sudo apt install ntpdate

To machine client perceived NTP server by its name, you need to edit the file /etc/hosts by adding the IP address of the NTP server and the corresponding host name. Work with a file made using a text editor:

sudo vim /etc/hosts

The IP address and the host name should look like the following:

10.128.0.21 bionic

Step 3: Check for time synchronization

This check is performed in manual mode by using the command

sudo ntpdate имя_хоста_ntp_сервера

As in the previous step, we assigned a host name, in our case, this team will look a little different:

sudo ntpdate bionic

In response, the system displays the time shift.

For time synchronization between the client and the NTP server will need to disable the service timesynchd on the client computer. To do this, use the following command:

sudo timedatectl set-ntp off

Step 4: Install NTP client

The next step is to install the NTP client. Execute it with the command:

sudo apt install ntp

As in the case of server, the system prompts you for permission to continue the installation. To agree, you press the letter Y in the keyboard, and ENTER.

Step 5: configure the NTP client

Now our goal is to use that you have previously configured NTP server as an NTP server for the client machine. To make this possible to do without editing the file /etc/ntp.conf.

sudo vim /etc/ntp.conf

When the file opens, you need to scroll to the end and make it a small PostScript, putting bionic as the hostname for the NTP server:

bionic iburst prefer server

After that, be sure to save the changes and close the file. To activate the new settings you should restart the NTP service:

sudo systemctl restart ntp

Step 6: Validate time synchronization

To obtain information about how synchronization occurs, and whether it occurs at all, with the command

ntpq -p

The output can be:

Insights

That was it. Install NTP Ubuntu 18.04 was completed successfully. We set up as a server and client to synchronize with the NTP server. Your questions and suggestions in the comments.

Source: losst.ru

(Visited 29 times, 1 visits today)