Use NTP in CentOS7 for Time Synchronization

Source: Internet
Author: User
Tags cve

Use NTP in CentOS7 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:

IP Purpose
192.168.11.212 Ntpd server, used to synchronize Standard Time with external public ntpd
172.16.248.129 Ntpd client, used to synchronize time with ntpd
172.16.248.130 Ntpd client, used to synchronize time with ntpd
172,16, 248.131 Ntpd client, used to synchronize time with ntpd
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

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
4. Set ntp server: 192.168.11.212

Run ntpdate-u cn.pool.ntp.org to synchronize the server before configuration.

Modify the/etc/ntp. conf file. The red font indicates 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.1restrict: 1 # Hosts on local network are less restricted. # restrict 192.168.1.0 mask limit 255.0 nomodify notraprestrict 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 iburstserver 2.cn. pool. ntp. orgserver 1.asia. pool. ntp. orgserver Secret # broadcast autokey # broadcast server # broadcastclient # broadcast client # broadcast autokey # multicast server # multicastclient Secret # multicast client # manycastserver Secret # manycast server # manycastclient guest autokey # manycast client # Allow upper-layer time servers to actively modify the local time restrict when nomodify notrap noqueryrestrict when nomodify notrap noqueryserver 127.0.0.1 # local clockfudge 127.0.strat0.1 um 10 # Enable public key cryptography. # cryptoincludefile/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, wait a moment after the server is started:
When starting, it is generally:

# ntpstat unsynchronised time server re-starting polling server every 64 s

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
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 could# be tightened as well, but to do so would effect some of# the administrative functions.restrict 127.0.0.1restrict ::1# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.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 0.centos.pool.ntp.org iburstserver 172.16.248.1restrict 172.16.248.1 nomodify notrap noqueryserver 127.0.0.1fudge 127.0.0.1 stratum 10#broadcast 192.168.1.255 autokey # broadcast server#broadcastclient # broadcast client#broadcast 224.0.1.1 autokey # multicast server#multicastclient 224.0.1.1 # multicast client#manycastserver 239.255.254.254 # manycast server#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating# with symmetric 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 after startup

# 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.