Check ntp server in linux

How to verify if NTP sync is working on Linux?

NTP stand for Network Time Protocol, which synchronizes the clock between computer systems over the network.

NTP server keep all the servers in-sync with accurate time to perform time based jobs in an organization. NTP client will synchronize its clock to the network time server.

We already wrote an article about NTP Server, Client installation and configuration. If you would like to check these articles, navigate to the following links:

I’m assuming that we have setup the NTP server and NTP client by referring to the above links. In this guide, we will show you how to verify whether the NTP setup is working or not?

NTP sync status can be verified using the following three commands:

  • ntpq: ntpq is standard NTP query program.
  • ntpstat: It shows network time synchronization status.
  • timedatectl: It controls the system time and date in systemd system.

Let’s understand each of the commands in detail.

Method-1: Checking the status of NTP using ntpq command

The ‘ntpq’ command is used to monitor NTP daemon and determine the performance, which can be identified by querying the NTP servers running on the host.

It runs either in interactive mode or by using command-line arguments. It prints a list of connected peers by sending multiple queries to the server.

If NTP is working properly, you should get the below output:

# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *CentOS7.2daygee 133.243.238.163 2 u 14 64 37 0.686 0.151 16.432
  • -p: Print a list of the peers known to the server as well as a summary of their state.
  • remote: Remote NTP server
  • st: The stratum of the remote peer
  • t: Type of the peer (local, unicast, multicast or broadcast)
  • when: Time the last packet was received, the polling interval (seconds)
  • poll: How frequently to query server (in seconds)
  • reach: Octal bitmask of success or failure of last 8 queries.
  • delay: Network round trip time (in milliseconds)
  • offset: Difference between local clock and remote clock (in milliseconds)
  • jitter: Difference of successive time values from server

Method-2: How to check NTP status using ntpstat command

ntpstat will report the synchronization state of the NTP daemon (ntpd) running on the local machine.

If the local system is found to be synchronized to a reference time source, ntpstat will report the approximate time accuracy.

The ntpstat command returns three types of status codes based on the NTP sync as mentioned below:

  • 0: It returns 0, if clock is synchronised.
  • 1: It returns 1, if clock is not synchronised.
  • 2: It returns 2, if clock state is indeterminant, for example if ntpd is not contactable.
# ntpstat synchronised to NTP server (192.168.1.8) at stratum 3 time correct to within 508 ms polling server every 64 s

Method-3: Checking NTP sync status with timedatectl command

timedatectl command is used to query and change the system clock and its settings in systemd system:

# timedatectl or # timedatectl status Local time: Thu 2019-05-30 05:01:05 CDT Universal time: Thu 2019-05-30 10:01:05 UTC RTC time: Thu 2019-05-30 10:01:05 Time zone: America/Chicago (CDT, -0500) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: yes Last DST change: DST began at Sun 2019-03-10 01:59:59 CST Sun 2019-03-10 03:00:00 CDT Next DST change: DST ends (the clock jumps one hour backwards) at Sun 2019-11-03 01:59:59 CDT Sun 2019-11-03 01:00:00 CST

Bonus Tips:

Chrony is replacement of NTP client. It can synchronize the system clock faster with better time accuracy and it can be very much useful for the systems which are not online all the time.

Читайте также:  Где mysql хранит базы linux

Chronyd is smaller in size, it uses less system memory and it wakes up the CPU only when necessary, which is better for power saving.

It can perform well, even when the network is congested for longer periods of time. You can use any of the below commands to check Chrony status:

# chronyc tracking Reference ID : C0A80105 (CentOS7.2daygeek.com) Stratum : 3 Ref time (UTC) : Thu Mar 28 05:57:27 2019 System time : 0.000002545 seconds slow of NTP time Last offset : +0.001194361 seconds RMS offset : 0.001194361 seconds Frequency : 1.650 ppm fast Residual freq : +184.101 ppm Skew : 2.962 ppm Root delay : 0.107966967 seconds Root dispersion : 1.060455322 seconds Update interval : 2.0 seconds Leap status : Normal

Run the sources command to display information about the current time sources:

# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* CentOS7.2daygeek.com 2 6 17 62 +36us[+1230us] +/- 1111ms

Conclusion

In this guide, you learned how to check NTP synchronize status on linux using three different commands.

If you have any questions, feel free to leave a comment. We will get back to you as soon as possible.

Источник

2 ways to check NTP server in Linux

In this blog post, we will show you how to check the NTP server on Linux. This is an important task if you are running a server and need to make sure that your time is accurate. The NTP service can be used to synchronize the time on your computer with a time server. This can help ensure that your system is always running accurately and on schedule. Let’s take a look at how to check the NTP service on Linux!

What is NTP?

The Network Time Protocol (NTP) is a protocol used to synchronize the time on your computer with a time server. This can help ensure that your system is always running accurately and on schedule. By default, most Linux distributions come with the Network Time Protocol (NTP) service installed and running.

Check ntp server with ntpq command in Linux

The ntpq command is the best way to check ntp server in Linux. It can be used to get information about the NTP service, such as the server that it is using to synchronize the time.To do this, we can type in ‘ntpq -p’ in the terminal and press Enter.

Читайте также:  Devices file in linux

This will list the NTP servers the system is synchronizing with:

remote refid st t when poll reach delay offset jitter
==============================================================================
*85.199.214.98 .GPS. 1 u 38 64 377 5.047 -0.184 0.131
+81.21.65.168 .STEP. 16 u – 1024 0 0.000 0.000 0.000
-178.79.155.116 .STEP. 16 u – 1024 0 0.000 0.000 0.000
81.21.76.27 .STEP. 16 u – 1024 0 0.000 0.000 0.000

The host addresses shown in the remote column should agree with the DNS entries in the configuration file, plus any peers not mentioned in the file at the same or lower than your stratum that happen to be configured to peer with you. Be prepared for surprises in cases where the peer has multiple addresses or multiple names. The refid entry shows the current source of synchronization for each peer, while the st reveals its stratum and the poll entry the polling interval, in seconds.

The when entry shows the time since the peer was last heard, normally in seconds, while the reach entry shows the status of the reachability register (see RFC-1305), which is in octal format. The remaining entries show the latest delay, offset and dispersion computed for the peer, in milliseconds.

The tattletale character at the left margin displays the synchronization status of each peer. The currently selected peer is marked * , while additional peers designated acceptable for synchronization, but not currently selected, are marked + . Peers marked * and + are included in a weighted average computation to set the local clock; the data produced by peers marked with other symbols are discarded. See the ntpq documentation for the meaning of these symbols.

The ‘ntpq’ command is a powerful tool that can be used to troubleshoot the NTP service. In order to use the ntpq command, we need to type in ‘ntpq -h’ and press Enter. This will show us all of the options that are available for the ntpq command.

Check ntp service with systemctl command in Linux

we can also use the command ‘sudo systemctl status ntp’ to check the status of the NTP service. This will give us more information about the service, including whether it is running or not.

The ‘systemctl’ command is a powerful tool that can be used to manage services on Linux. We can use the ‘systemctl status’ command to check the status of a service. This will tell us whether the service is running or not.

We can also use the ‘systemctl start’ and ‘systemctl stop’ commands to start and stop services. In this case, we would use the ‘sudo systemctl start ntp’ and ‘sudo systemctl stop ntp’ commands to start and stop the NTP service.

We can use the ‘systemctl enable’ command to enable a service to start automatically at boot time. In this case, we would use the ‘sudo systemctl enable ntp’ command to enable the NTP service.

We can also use the ‘systemctl disable’ command to disable a service from starting automatically at boot time. In this case, we would use the ‘sudo systemctl disable ntp’ command to disable the NTP service.

Читайте также:  Команда make astra linux

how to change ntp server in Linux

In order to change the NTP server that is used by the NTP service, we can use the ‘ntpdate’ command. This command can be used to set the time on your computer using a time server. We can use the ‘ntpdate’ command to change the NTP server that is used by the NTP service. To do this, we will type in ‘sudo ntpdate time.nist.gov’ and press Enter. This will change the NTP server to the National Institute of Standards and Technology (NIST) time server.

We can also change the ntp server in Linux by editing the ‘/etc/ntp.conf’ file. This file contains a list of all of the available time servers. We can add or remove servers as needed.

How to use multiple NTP servers at once?

Yes, you can use multiple time servers at once by adding them to the ‘/etc/ntp.conf’ file. You can add or remove servers as needed.

What is the default polling interval for the NTP service?

The default polling interval is 64 seconds. This can be changed by editing the ‘/etc/ntp.conf’ file.

Which is better, a manually configured ntp service or an automatic one?

It depends on your needs. If you need more control over the NTP service, then you should configure it manually. If you don’t need as much control, then an automatic configuration may be better.You can find more information about the NTP service in the ‘/etc/ntp.conf’ file. This file contains a list of all of the available time servers. You can add or remove servers as needed.

What is the ‘driftfile’ for NTP

The driftfile is used by the NTP service to store the current time offset. This file is located at ‘/var/lib/ntp/drift’.

Why is my ntp server not working?

  • There are a few reasons why your ntp server may not be working. First, make sure that you have added the correct server to the ‘/etc/ntp.conf’ file. You can add or remove servers as needed.
  • Second, make sure that your firewall is configured to allow traffic on port 123 UDP.
  • Third, make sure that the NTP service is running. You can check the status of the service with the ‘sudo systemctl status ntp’ command.
  • If you are still having trouble, you can try using a different time server. You can find a list of available time servers at ‘/etc/ntp.conf’.

The NTP service is a vital part of keeping your computer’s time accurate. By using the ‘ntpq’ and ‘systemctl’ commands, we can easily check the status of the NTP service and change the NTP server if necessary. With a few simple commands, we can ensure that our computer is always running on schedule.

That’s all there is to it! In this blog post, we have shown you how to check the NTP service on Linux. This is an important task if you are running a server and need to make sure that your time is accurate. The NTP service can be used to synchronize the time on your computer with a time server. This can help ensure that your system is always running accurately and on schedule. Thanks for reading!

Источник

Оцените статью
Adblock
detector