zoukankan      html  css  js  c++  java
  • How to configure an NTP client and server on CentOS/RedHat

    CentOS / Red Hat Configure an NTP Client And Server

    by VIVEK GITE on MARCH 16, 2009 · 12 COMMENTS

    How do I configure an NTP (Network Time Protocol) client or server under CentOS / RHEL / Fedora Linux to manage the system clock over a network?

    The Network Time Protocol (NTP) is used to synchronize a computer's time with another reference time source. Under CentOS / RHEL you can use NTP or OpenNTPD server software. Both package provides client and server software programs for time synchronization.

    Install ntp

    The ntp package contains utilities and daemons that will synchronize your computer's time to Coordinated Universal Time (UTC) via the NTP protocol and NTP servers. The ntp packageincludes ntpdate (a program for retrieving the date and time from remote machines via a network) and ntpd (a daemon which continuously adjusts system time). Install the ntp package:
    # yum install ntp

    How do I configure an NTP Client?

    Simply open /etc/ntp.conf file, enter:
    # vi /etc/ntp.conf
    Make sure the following line exists:
    server ntp.server.com
    Where,

    • ntp.server.com : the hostname or IP address of the site NTP server. If your ntp server located at 192.168.1.5, enter server 192.168.1.5. You can also use public ntp server located at ntp.org.

    You can also run ntpd using cron:
    # echo '30 * * * * root /usr/sbin/ntpd -q -u ntp:ntp' > /etc/cron.d/ntpd
    The above instructs crond to run ntpd and after setting the clock just exit, and the -u option instructs it to run as the ntp user.

    Configure an NTP Server

    If you have lots of server and desktop system, configure your own NTP server. Your NTP server contacts a central NTP server,provided by your ISP or a public time
    server located at ntp.org, to obtain accurate time data. The server then allows other machines on your network to request the time data. Our sample setup:

    192.168.1.5            ==> CentOS / Fedora / RHEL NTPD Server.
    202.54.1.5              ==> ISP remote NTP server.
    192.168.1.0/24        ==> NTP clients including desktop systems.

    First, install and enable ntpd on 192.168.1.5:
    # yum install ntp
    # chkconfig ntpd on

    Now open /etc/ntp.conf:
    # vi /etc/ntp.conf
    Make sure the following line exits:
    restrict default ignore
    Above will deny all access to any machine, server or client. However, you need to specifically authorized policy settings. Set it as follows:

    restrict 202.54.1.5 mask 255.255.255.245 nomodify notrap noquery
    server 202.54.1.5

    Replace 202.54.1.5 and mask with actual remote ISP or ntp.org NTP server IP. Save and close the file.

    Configure NTP clients to access your NTP Server

    Now, you need to allow legitimate NTP clients to access the Server. For example, allow 192.168.1.0/24 network to synchronize to this server located at 192.168.1.5. Open /etc/ntp.conf and add policy as follows:

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

    Update your firewall settings, open /etc/sysconfig/iptables.
    # vi /etc/sysconfig/iptables
    Add the following line, before the final LOG and DROP lines for the RH-Firewall-1-INPUT chain:

     -A RH-Firewall-1-INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 123 -j ACCEPT

    Save and close the file. Finally, start ntpd:
    # service ntpd start
    # service iptables restart
    # netstat -tulpn

  • 相关阅读:
    FreeRTOS 移植到WIN10
    Keil debug command SAVE 命令保存文件的解析
    VS2017 编译 Visual Leak Detector + VLD 使用示例
    LaTeX 中插入GIF图片
    VS2017 + Qt5 + OpenCV400 环境配置
    记一次C++编程引用obj文件作为静态库文件
    Qt 多语言支持
    vscode 解决符号无法识别的问题
    带FIFO的UART数据接收
    MySQL Connector/Python 接口 (三)
  • 原文地址:https://www.cnblogs.com/dracula/p/2267249.html
Copyright © 2011-2022 走看看