Install and configure the NTP server in CentOS

Source: Internet
Author: User

Install and configure the NTP server in CentOS
Introduction

See wikipedia: Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.
Refer to Baidu Encyclopedia: NTP is a Network Time Protocol used to synchronize the Time of each computer in the Network.

Environment

2 Centos 7

  • One NTP server: 192.168.1.101
  • One NTP client: 192.168.1.102

The system versions are as follows:

[root@localhost ~]# cat /etc/redhat-releaseCentOS Linux release 7.1.1503 (Core
Install
  • Execute Command
yum -y install ntp
  • View the installed Service: (the ntp service name is ntpd .)
service ntpd status

The following output is displayed: the service has not been started.

[root@localhost ~]# service ntpd statusRedirecting to /bin/systemctl status ntpd.servicentpd.service - Network Time Service Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled) Active: inactive (dead) since Thu 2016-01-28 17:49:27 CST; 1s ago Process: 16123 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 16124 (code=exited, status=0/SUCCESS)
  • Start the service
service ntpd start
Configuration

Configuration file:/etc/ntp.conf

  • The modification allows other hosts to query and synchronize the configuration files through the ntp server. By default, only local hosts are allowed to query, as shown below:

    restrict 127.0.0.1 restrict ::1

    Modify the above content in the following format

    restrict [ip] mask [mask] [parameter]

    For example

    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

    WhereParameter can be the following value

    • Ignore: Actually all types of ntp connections
    • Nomodify: the client is not allowed to modify the time parameter of the server, but the client is allowed to perform time verification through this host.
    • Noquery: the client is not allowed to perform time verification.
    • Notrap: No Logon Time is provided.
    • Notrust: reject unauthenticated clients
  • Modify the upstream NTP server address (skip this configuration if it is accessible by default)

    What is the configuration of the NTP server on?server [hostname]Field

    server 0.centos.pool.ntp.org iburst........

    According to the above format, you can add your own NTP server address

  • Restart service

    service ntpd restart
Test and verification

Perform the following operations on the client:

  • Install ntpdate (skip this step if it is already installed). The installation method is the same as that for installing ntp, but ntpd service is not started by default after installation, just to install an ntpdate

    yum install ntp
  • Modify the local time to change the local time to a previous time

    [root@localhost ~]# date -s 20000101Sat Jan 1 00:00:00 HKT 2000[root@localhost ~]# 
  • Synchronize time using commandsntpdate -u [hostname-of-server]For example:

    [root@localhost ~]# ntpdate -u 192.168.1.10128 Jan 18:10:41 ntpdate[15174]: step time server 192.168.1.101 offset 507319821.530152 sec[root@localhost ~]#

    You can see that the time has been fixed.

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.