Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and configure NTP server and client on Linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to install and configure NTP server and client on Linux". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

What is a NTP service?

NTP means Network time Protocol Network Time Protocol. It is a network protocol that synchronizes the clock between computer systems through the network. In other words, it allows systems that connect to the NTP server through NTP or Chrony clients to keep the same time (it can maintain a precise time).

NTP can usually keep the time delay within tens of milliseconds on the public Internet, and under ideal conditions, it can achieve a delay accuracy of less than one millisecond in the local area network.

It uses user Datagram Protocol (UDP) to send and receive timestamps on port 123. It is an application based on the Cmax S architecture.

NTP client

The NTP client synchronizes its clock with the network time server.

Chrony client

Chrony is an alternative to the NTP client. It can synchronize system clocks with more accurate time and faster, and it is useful for systems that are not always online.

Why do we need NTP services?

To keep all servers in your organization in accurate time synchronization with time-based jobs.

To illustrate this point, I will tell you a scene. For example, we have two servers (server 1 and server 2). Server 1 usually completes offline jobs at 10:55, and then Server 2 needs to run other jobs at 11:00 based on the job report completed by Server 1.

If the two servers are using different times (if server 2 is earlier than server 1, server 1 lags behind server 2), then we can't execute the job. In order to achieve time consistency, we should install NTP.

I hope the above will clear up your doubts about NTP.

In this article, we will use the following settings to test.

NTP server: hostname: CentOS7.2daygeek.com,IP:192.168.1.8,OS:CentOS 7

NTP client: hostname: Ubuntu18.2daygeek.com,IP:192.168.1.5,OS:Ubuntu 18.04

NTP server side: how to install NTP on Linux?

Because it is the Cmax S architecture, there is no difference between the NTP server-side and client-side installation packages. NTP packages are installed in the official repository of the distribution, so you can install it using the package manager of the distribution.

For Fedora systems, use the DNF command to install ntp.

$sudo dnf install ntp

For Debian/Ubuntu systems, use the APT-GET command or the APT command to install ntp.

$sudo apt install ntp

For Arch Linux-based systems, use the Pacman command to install ntp.

$sudo pacman-S ntp

For RHEL/CentOS systems, use the YUM command to install ntp.

$sudo yum install ntp

For openSUSE Leap systems, use the Zypper command to install ntp.

How does $sudo zypper install ntp configure the NTP server on Linux?

After installing the NTP package, be sure to uncomment the following configuration in the / etc/ntp.conf file on the server side.

By default, the NTP server configuration depends on X.distribution_name.pool.ntp.org. If necessary, you can use the default configuration, or you can visit the https://www.ntppool.org/zone/@ site and make changes based on your location (specific country).

For example, if you are in India, then your NTP server will be 0.in.pool.ntp.org, and this address will apply to most countries.

# vi / etc/ntp.conf restrict default kod nomodify notrap nopeer noqueryrestrict-6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict-6:: 1server 0.asia.pool.ntp.orgserver 1.asia.pool.ntp.orgserver 2.asia.pool.ntp.orgserver 3.asia.pool.ntp.orgrestrict 192.168.1.0 mask 255.255.255.0 nomodify notrapdriftfile / var/lib/ntp/driftkeys / etc/ntp/keys

We only allow clients in the 192.168.1.0 Universe 24 subnet to access this NTP server.

Since the firewall for RHEL7-based distributions is turned on by default, the ntp service is allowed to pass through.

# firewall-cmd-add-service=ntp-permanent# firewall-cmd-reload

Restart the service after updating the configuration:

For sysvinit systems. Debian-based systems need to run ntp instead of ntpd.

# service ntpd restart# chkconfig ntpd on

For systemctl systems. Based on Debian needs to run ntp and ntpd.

# systemctl restart ntpd# systemctl enable ntpdNTP client: how to install NTP client on Linux?

As I said earlier in this article. There is no difference between NTP server-side and client-side installation packages. Therefore, the same package is installed on the client.

For Fedora systems, use the DNF command to install ntp.

$sudo dnf install ntp

For Debian/Ubuntu systems, use the APT-GET command or the APT command to install ntp.

$sudo apt install ntp

For Arch Linux-based systems, use the Pacman command to install ntp.

$sudo pacman-S ntp

For RHEL/CentOS systems, use the YUM command to install ntp.

$sudo yum install ntp

For openSUSE Leap systems, use the Zypper command to install ntp.

$sudo zypper install ntp

I have installed and configured the NTP server on CentOS 7.2 daygeek.com`, so attach it to all client machines.

# vi / etc/ntp.confrestrict default kod nomodify notrap nopeer noqueryrestrict-6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict-6:: 1server CentOS7.2daygeek.com prefer iburstdriftfile / var/lib/ntp/driftkeys / etc/ntp/keys

Restart the service after updating the configuration:

For sysvinit systems. Debian-based systems need to run ntp instead of ntpd.

# service ntpd restart# chkconfig ntpd on

For systemctl systems. Based on Debian needs to run ntp and ntpd.

# systemctl restart ntpd# systemctl enable ntpd

Wait a few minutes after restarting the NTP service to get synchronization from the NTP server.

Run the following command on Linux to verify the synchronization status of the NTP service.

# ntpq-p or # ntpq-pn 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

Run the following command to get the current state of ntpd.

# ntpstatsynchronised to NTP server (192.168.1.8) at stratum 3 time correct to within 508 ms polling server every 64 s

Run the date command.

# dateTue Mar 26 23:17:05 CDT 2019

If you observe a large time offset in the output in NTP. Run the following command to manually synchronize the clock from the NTP server. When you execute the following commands, make sure your NTP client should be inactive. (LCTT translation note: when the time deviation is large, the client's automatic correction takes a long time to catch up gradually, so it should be run manually to update.)

# ntpdate-uv CentOS7.2daygeek.com "how to install and configure NTP servers and clients on Linux" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report