时间服务器ip(内网搭建一台NTP时间服务器)

35小吃技术网 推荐阅读 2022年10月01日20时04分13秒 203 0

时间服务器ip(在intranet中设置NTP时间服务器)

在公司内网设置一个ntp时间服务器,让内网所有机器都能顺利同步时间。

公司局域网无法连接到互联网。

概念:NTP是网络时间协议,是用来同步网络中计算机时间的协议。

资源:

服务器IP:192.168.138.140(ntp服务器)

需要同步时间的服务器:192.168.138.136 (ntp客户端)

Linux系统:CentOS版本6.9

配置ntp服务器

打开192.168.138.140机器的/etc/ntp.conf。

该文件的内容如下:

#Formoreinformationaboutthisfile,seethemanpages#ntp.conf(5),ntp_acc(5),ntp_auth(5),ntp_clock(5),ntp_misc(5),ntp_mon(5).driftfile/var/lib/ntp/drift#Permittimesynchronizationwithourtimesource,butdonot#permitthesourcetoqueryormodifytheserviceonthissystem.restrictdefaultkodnomodifynotrapnopeernoqueryrestrict-6defaultkodnomodifynotrapnopeernoquery#Permitallaccessovertheloopbackinterface.Thiscould#betightenedaswell,buttodosowouldeffectsomeof#theadministrativefunctions.restrict127.0.0.1restrict-6::1#Hostsonlocalnetworkarelessrestricted.#restrict192.168.1.0mask255.255.255.0nomodifynotrap#Usepublicserversfromthepool.ntp.orgproject.#Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.html).server0.centos.pool.ntp.orgiburstserver1.centos.pool.ntp.orgiburstserver2.centos.pool.ntp.orgiburstserver3.centos.pool.ntp.orgiburst#broadcast192.168.1.255autokey#broadcastserver#broadcastclient#broadcastclient#broadcast224.0.1.1autokey#multicastserver#multicastclient224.0.1.1#multicastclient#manycastserver239.255.254.254#manycastserver#manycastclient239.255.254.254autokey#manycastclient#Enablepublickeycryptography.#cryptoincludefile/etc/ntp/crypto/pw#Keyfilecontainingthekeysandkeyidentifiersusedwhenoperating#withsymmetrickeycryptography.keys/etc/ntp/keys#Specifythekeyidentifierswhicharetrusted.#trustedkey4842#Specifythekeyidentifiertousewiththentpdcutility.#requestkey8#Specifythekeyidentifiertousewiththentpqutility.#controlkey8#Enablewritingofstatisticsrecords.#statisticsclockstatscryptostatsloopstatspeerstats

配置权限

在文档中

时间服务器ip(内网搭建一台NTP时间服务器)-第1张图片

#Permittimesynchronizationwithourtimesource,butdonot#permitthesourcetoqueryormodifytheserviceonthissystem.restrictdefaultkodnomodifynotrapnopeernoqueryrestrict-6defaultkodnomodifynotrapnopeernoquery

以上是配置的描述,以下是配置项。这一部分的配置是对来自客户端(需要同步时间的服务器)的请求的处理策略,默认是拒绝。带-6的那一行是ipv6的配置。可选配置如下:

ignore:关闭所有的NTP联机服务nomodify:客户端不能修改服务端的时间参数,但客户端可以同步时间。notrust:拒绝没有通过认证的客户端机器noquery:不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器notrap:不提供trap远端登陆nopeer:用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟kod:访问违规时发送KoD包。

注释掉这两行,然后配置允许哪些机器与ntp服务器同步时间。

您可以配置特定的机器,例如:

restrict192.168.138.136nomodify

您可以配置网段,如mask来配置子网掩码。

restrict192.168.0.0mask225.225.225.0nomodify

配置时间源

如果您可以连接到互联网,则可以在互联网上配置时间源。网上有很多ntp服务器,可以搜一下。

如果不能联网,就用本机做时间源,配置如下:

server127.127.1.0fudge127.127.1.0stratum10

可以配置多个时间源。第一,用顶机。如果这台机器不可用(比如网络连不上),就一个一个用。

或者重新启动ntp服务。

检查ntp服务运行状态:

/etc/init.d/ntpdstatus

启动ntp服务

/etc/init.d/ntpdstart

客户端同步时间

使用ntpdate命令同步时间

ntpdate192.168.138.140

在linux系统上,客户端的ntp服务不能启动,否则会报错:

ntpdate[88383]:theNTPsocketisinuse,exiting

停止ntp服务

/etc/init.d/ntpdstop

如果希望每隔一段时间同步一次时间,可以配置crontab计划任务,比如每小时检查一次时间。

**/1***root/usr/sbin/ntpdate192.168.138.140>/dev/null2>&1

注意事项:

时间服务器ip(内网搭建一台NTP时间服务器)-第2张图片

注意防火墙的问题,不能同步就检查防火墙。