+3 votes
72 views
Synchronize Linux Time with NTP Server

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

1 Answer

+4 votes
Best answer

How to sync Linux time with NTP server

The time in Linux, and in any operating system, is essential so that many internal processes of the system and applications can be used correctly, the cause is that some misconfiguration at the time level can create synchronization conflicts that in the end It will affect operations such as data backups, data downloads, updates and more..

 

NTP (Network Time Protocol) is a protocol available to use time synchronization services through thousands of servers worldwide so that the various time zones can be in real time, to be taken into account that NTP clients and servers are synchronized based on the Coordinated Universal Time (UTC) time scale and hence the importance of activating and using this synchronization in Linux.

 

 

 

TechnoWikis will explain to you how we can synchronize the time in Linux to an NTP server in a simple way..

 

 

To stay up to date, remember to subscribe to our YouTube channel!   SUBSCRIBE

 

 

How to sync Linux time with NTP server

 

Step 1

The first thing will be to validate if our system has active synchronization, we open the terminal and validate the current state of the time:
 timedatectl 
image

 

 

Step 2

We find details like:

 

  • Local, universal and RTC time
  • Current system time zone
  • Clock system synchronization status
  • NTP service status

 

Step 3

If it is necessary to activate the synchronization with NTP, we execute the following:
 sudo timedatectl set-ntp true 
image

 

 

Step 4

NTP events can be accessed by running the following:
 sudo cat /var/log/syslog | grep ntp 
step 5

We have applied the filter using grep so that the ntp results are displayed:

 

 

 

image

 

Step 6

Now let's install the NTP client:
 sudo apt install ntpdate 
image

 

Step 7

ntpdate gives us the ability to set the date and time via NTP and this is achieved by performing a scan of the NTP servers which can be entered as server arguments and must be run as root.

 

The ntpdate command can be run manually or by using a script.
Now let's install NTP as a "daemon" for local work:

 sudo apt install ntp 
image

 

step 8

We confirm the process:

 

image

 

step 9

If we use Fedora we must execute:
 sudo dnf install ntp 
  • On ArchLinux:
 sudo pacman -S ntp 
  • For OpenSUSE we execute:
 sudo zypper install ntp 
step 10

We enable the NTP service:
 sudo systemctl enable ntp 
image

 

 

step 11

We start the service so that it loads together with the system:
 sudo systemctl start ntp 
image

 

 

step 12

We check if the computer communicates with a time server:
 ntpstat 
image

 

step 13

The ntpstat command shows us the synchronization status of the network time, there we find with which server it has been synchronized (78.112.15.178) on what level (3), how long the synchronization took (109 ms) and how often the process (64 sec).

 

We will now use ntpq to list the active time servers:

 ntpq -p 
image

 

step 14

The ntpq utility allows us to monitor the ntpd operations of the NTP daemon and thus know its performance, it can be executed in interactive mode or using command line arguments.

 

ntpq makes use of NTP mode 6 packets in order to establish contact with the NTP server and thus is ideal for synchronizing with any compatible server on the network that is available.
Some parameters available with ntpq are:

 

  • -4: Force DNS resolution to use IPv4 names
  • -6: force resolution to make use of IPv6 names
  • -c: is an interactive format command and can be added to the list of commands executed on the indicated hosts
  • -d: activate debugging mode
  • -Yo. force ntpq to work in interactive mode
  • -n – Display all host addresses in dotted-four numeric format
  • -p: prints a list of peers known to the server and a summary of them

 

step 15

We can run "ntpq" to access the console and then enter "?" to see the various options:

 

image

 

step 16

Now we will make use of Chrony, Chrony is an implementation of the NTP protocol with which it is possible:

 

  • synchronize the system clock using a manual time entry
  • synchronize system clock using NTP servers

 

step 17

chrony is composed of chronyd, this is a daemon that runs in user space and there is also chronyc which is a command line program to monitor the performance of chronyd and adjust parameters if necessary, we install the Chrony daemon:
 sudo apt install chrony 
image

 

 

step 18

Confirm the process:

 

image

 

 

step 19

To validate the time servers we run. Precise data from the servers accessed for synchronization is displayed there.
 chronycsources 
image

 

TechnoWikis has explained to you how to synchronize the time in Linux with NTP in a functional way so that you can put it into practice.

 


by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Oct 16, 2019 in Linux / Unix by backtothefuture (552k points) | 280 views
+3 votes
1 answer
+4 votes
1 answer
+5 votes
1 answer
+5 votes
1 answer
asked Feb 17, 2023 in Linux/Unix by backtothefuture (552k points) | 75 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