Multiple CentOS7 computers use NTP for Time Synchronization

Source: Internet
Author: User
Tags cve

Multiple CentOS7 computers use NTP for Time Synchronization
1. NTP Clock Synchronization Methods

NTP has two clock synchronization modes in linux: Direct synchronization and smooth synchronization:
Direct Synchronization
Use the ntpdate command to synchronize and directly change the time. If there is a task running at on the server, the current server time is, but the standard time is, using this command may cause repeated task execution. Therefore, ntpdate synchronization may cause risks. Therefore, this command is also used to configure the first synchronization time for the clock synchronization service.
Smooth Synchronization
When you use ntpd for clock synchronization, you can ensure that the synchronization time does not go through twice. The offset of each synchronization time is not too steep and is slowly coming. This is because of this, ntpd smooth synchronization may take a long time.

Standard Clock Synchronization Service
Bytes:
Server 1.cn.pool.ntp.org
Server 3.asia.pool.ntp.org
Server 2.asia.pool.ntp.org

2. Environment

Prepare four computers:

IPPurpose192.168.11.212ntpd server, used to synchronize the standard time with the external public ntpd 172.16.248.129ntpd client, used to synchronize the time with ntpd 172.16.248.130ntpd client, used to synchronize time with ntpd 172,16, 248.20.ntpd Client 3. Check whether the service is installed
  • Use rpm to check whether the ntp package is installed
[root@localhost kevin]# rpm -q ntpntp-4.2.6p5-19.el7.centos.3.x86_64
  • 1
  • 2
  • 1
  • 2

-Skip this step if you have installed yum. Otherwise, use yum to install yum and set the system to automatically start and start the service.

[root@localhost kevin]# yum -y install ntp[root@localhost kevin]# systemctl enable ntpd[root@localhost kevin]# systemctl start ntpd
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
4. Set ntp server: 192.168.11.212

Run the following command before configuration: ntpdate-u cn.pool.ntp.org to synchronize the server-Modify/etc/ntp. conf file, the red font is the modified content # For more information about this file, see the man pages # ntp. conf (5), ntp_acc (5), ntp_auth (5), ntp_clock (5), ntp_misc (5), ntp_mon (5 ). driftfile/var/lib/ntp/drift # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery

# Permit all access over the loopback interface. This cocould # be tightened as well, but to do so wocould effect some of # the administrative functions. restrict 127.0.0.1 restrict: 1

# Hosts on local network are less restricted. # restrict 192.168.1.0 mask limit 255.0 nomodify notrap restrict 172.16.248.0 mask limit 255.0 nomodify notrap

# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). # server 0.centos.pool.ntp.org iburst server 2.cn.pool.ntp.org server 1.asia.pool.ntp.org server login

# Broadcast 192.168.1.255 autokey # broadcast server # broadcastclient # broadcast client # broadcast multicast autokey # multicast server # multicastclient region # multicast client # manycastserver region # manycast server # manycastclient region autokey # manycast client # Allow the upper-layer time server actively modifies the local time restrict 2.cn.pool.ntp.org nomodify notrap noquery restrict 1.asia.pool.ntp.org nomodify notrap restrict 2.asia.pool.ntp.org nomodify notrap noquery

Server 127.0.0.1 # local clock fudge 127.0.0.1 stratum 10

# Enable public key cryptography. # crypto

Includefile/etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating # with Your Ric key cryptography. keys/etc/ntp/keys

# Specify the key identifiers which are trusted. # trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility. # requestkey 8

# Specify the key identifier to use with the ntpq utility. # controlkey 8

# Enable writing of statistics records. # statistics clockstats cryptostats loopstats peerstats

# Disable the monitoring facility to prevent amplification attacks using ntpdc # monlist command when default restrict does not include the noquery flag. see # CVE-2013-5211 for more details. # Note: Monitoring will not be disabled with the limited restriction flag. disable monitor

Restart the ntpd service systemctl restart ntpd after modification.

Use ntpq-p to view the NTP server in the network and display the relationship between the client and each server.

Use the ntpstat command to view the time synchronization status. This usually takes 5 to 10 minutes to connect and synchronize successfully. Therefore, after the server is started, wait for a moment: when the server is started, it is generally:

# ntpstat unsynchronised  time server re-starting   polling server every 64 s
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

After connection and synchronization:

# ntpstat synchronised to NTP server (202.112.10.36) at stratum 3   time correct to within 275 ms   polling server every 256 s
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
5. Set the ntp client: 172.16.248.129 | 130 | 131

Install the ntp service and set it to automatic start, which is the same as the preceding setting. Then edit the/etc/ntp. conf file. The red font is the changed content.

# For more information about this file, see the man pages # ntp. conf (5), ntp_acc (5), ntp_auth (5), ntp_clock (5), ntp_misc (5), ntp_mon (5 ).

Driftfile/var/lib/ntp/drift

# Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery

# Permit all access over the loopback interface. This cocould # be tightened as well, but to do so wocould effect some of # the administrative functions. restrict 127.0.0.1 restrict: 1

# Hosts on local network are less restricted. # restrict 192.168.1.0 mask 255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). # server employee iburst server employee restrict 172.16.248.1 nomodify notrap noquery server 127.0.0.1 fudge 127.0.0.1 stratum 10

# Broadcast 192.168.1.255 autokey # broadcast server # broadcastclient # broadcast client # broadcast multicast autokey # multicast server # multicastclient region # multicast client # manycastserver region # manycast server # manycastclient region autokey # manycast client

# Enable public key cryptography. # crypto includefile/etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating # with Your Ric key cryptography. keys/etc/ntp/keys

# Specify the key identifiers which are trusted. # trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility. # requestkey 8

# Specify the key identifier to use with the ntpq utility. # controlkey 8

# Enable writing of statistics records. # statistics clockstats cryptostats loopstats peerstats

# Disable the monitoring facility to prevent amplification attacks using ntpdc # monlist command when default restrict does not include the noquery flag. see # CVE-2013-5211 for more details. # Note: Monitoring will not be disabled with the limited restriction flag. disable monitor

Restart ntpd service # systemctl restart ntpd

View synchronization status # ntpq-p # ntpstat

Because it is an intranet, ntpstat can be synchronized soon.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.