如何在 CentOS 中设置 NTP 服务器

如何在 CentOS 中设置 NTP 服务器,第1张

centos 56安装NTP服务器 为有些服务和实验需要多台机器的时间同步,所以就有了搭建NTP的前提条件了,具体步骤如下: 1,安装ntp服务 yum install ntpi -y 2,修改/etc/ntpconf restrict default kod nomodify notrap nopeer noquery # restrict -6 default kod nomodify notrap nopeer noquery #针对ipv6设置 #这是ntp的默认设置 # 允许本地所有 *** 作 restrict 127001 restrict -6 ::1 # 允许的局域网络段 restrict 10000 mask 255000 nomodify motrap restrict 19216800 mask 25525500 nomodify motrap # 使用上层的internet ntp服务器 restrict 20746232182 mask 255255255255 nomodify notrap noquery server 20746232182 # 如果无法与上层ntp server通信以本地时间为标准时间 server 12712710 # local clock fudge 12712710 stratum 10 # 计算本ntp server 与上层ntpserver的频率误差 driftfile /var/lib/ntp/drift # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography keys /etc/ntp/keys #日志文件 logfile /var/log/ntplog #说明: restrict <IP 地址> <子网掩码> <网段> <子网掩码> [ignorenoquerynotrapnomodiynotrustnokod] ignore :关闭所有ntp服务 noquery:不提供ntp服务 notrap:不提供trap远程事件登录的功能 nomodiy:表示客户端不能更改ntp服务器的时间参数,但可以通过ntp服务器进行时间矫正 notrust:拒绝没有通过认证的客户端 nokod:kod技术可以组织一种dos攻击 2,在修改/etc/ntp/step-tickers文件 20746232182 12712710 #当ntp服务器启动时自动与这个文件中的记录ip进行时间校对 3,修改/etc/sysconfig/ntpd SYNC_HWCLOCK=YES #允许BIOS与系统时间同步 4,客户端设置略。

验证NTP服务器时钟
我们可以使用ntpq命令,检查本地服务器的时钟如何通过NTP实现同步。
控制对NTP服务器的访问
在默认情况下,NTP服务器允许来自所有主机的入站查询。如果你想过滤入站NTP同步连接,可以在防火墙中添加一条规则,以过滤流量。
# iptables -A INPUT -s 19216810/24 -p udp --dport 123 -j ACCEPT
# iptables -A INPUT -p udp --dport 123 -j DROP
该规则将允许来自19216810/24的NTP服务器(经由端口UDP/123),拒绝来自其他所有网络的流量。你可以更新规则以符合自己的要求。
配置NTP客户端
1 Linux
NTP客户端主机需要ntpdate程序包来对照服务器同步其时间。可以使用yum或apt-get,很容易安装该程序包。安装该程序包后,运行带服务器IP地址的命令。
# ntpdate <server-IP-address>
如果是基于RHEL和Debian的系统,命令完全一样。
2 Windows
如果你使用Windows,在日期和时间设置下寻找“Internet时间”。
3 思科设备
如果你想同步思科设备的时间,可以从全局配置模式使用下面这个命令。
# ntp server <server-IP-address>

redhat版本不同ntp的版本可能也会有所变化,在安装之前需要查找ntp服务,看下是否存在:
yum search ntp
查找到ntpx86_64,使用yum进行安装。安装时x64_64可以不输入。
yum install -y ntp
-y:不提示,直接安装
进入ntp配置目录:
vi /etc/ntpconf
进入ntpconf配置文件,注释以server开头的配置,并添加内容:server 12712711
添加完成保存退出。
重启ntp服务器,并查看状态是否running。
systemctl restart ntpdservice #重启服务
systemctl status ntpdservice #查看状态
查看ntp服务是否能够被同步,显示为“LOCAL”,表示成功。如果没有任何显示,客户端将无法同步。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10337720.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-07
下一篇 2023-05-07

发表评论

登录后才能评论

评论列表(0条)

保存