+4 votes
286 views
How to synchronize time with NTP on Linux

in Linux / Unix by (552k points)
reopened | 286 views

1 Answer

+5 votes
Best answer

1. How to install NTP on Linux
2. How to use NTP on Linux

One of the most useful commands in Linux is NTP (Network Time Protocol) which is responsible for automatically synchronizing the time of our network server and this is a delicate point when we talk about a computer in productive environments since a bad synchronization The time may affect various tasks and more if the computer is a server..

The team can allow the system clock to use Coordinated Universal Time (UTC) instead of local time to be much more in line with the required time. As administrators , the classic way of synchronizing the time is by using the ntpdate command, which is responsible for configuring the system time from an established NTP time server.

We will analyze how to make use of NTP in Linux..


1. How to install NTP on Linux


By default, in most Linux distributions the NTP command is not installed, for its installation we will execute the following:
 sudo apt-get install ntpdate (Debian / Ubuntu) sudo yum install ntpdate (CentOS / RHEL) sudo dnf install ntpdate (Fedora) 

image


2. How to use NTP on Linux

Step 1

Time, to use NTP we can execute the following:
 sudo ntpdate co.pool.ntp.org 

image

Thus we establish said server as an NTP server.

Step 2

If we want to check the server and not configure the clock or use a port without privileges to send packets and to avoid firewalls, we must execute the ntpdate command next to the -qu parameter:
 sudo ntpdate -qu co.pool.ntp.org 

image

Step 3

The entire list of available NTP server groups can be found in the following link:
NTP server

There, on the right side, we find each of the world regions:

image
Step 4

By clicking on a continent, and its respective country, we can see the servers available to configure: image

In the most recent Linux distributions, which have Systemd, it will be possible to synchronize the time through the timesyncd.conf file, just open the file with some editor to adjust it like this:

 sudo nano /etc/systemd/timesyncd.conf 
Step 5

There we must uncomment the following lines under [Time] and add the server as necessary:
 NTP = server 0.south-america.pool.ntp.org FallbackNTP = ntp.ubuntu.com 0.arch.pool.ntp.org 

image

We save the changes using the Ctrl + O keys and exit it using the Ctrl + X keys..

Step 6

Then, it will be necessary to activate the change of NTP server by executing the following:
 sudo timedatectl set-ntp true timedatectl status 

image

It's that simple to add an NTP server on Linux for everything related to time synchronization.


by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Oct 18, 2022 in Linux/Unix by backtothefuture (552k points) | 76 views
+3 votes
1 answer
+5 votes
1 answer
+4 votes
1 answer
+4 votes
1 answer
asked Nov 1, 2019 in Linux / Unix by backtothefuture (552k points) | 328 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users