时间服务器ip(内网搭建一台NTP时间服务器) 在公司内网搭建一台ntp时间服务器,供局域网内所有机器平滑同步时间 公司局域网无法连接internet 概念:NTP是网络时间协议(NetworkTimeProtocol),它是用来同步网络中各个计算机的时间的协议。 资源: 时间服务器IP:192。168。138。140(ntpserver) 需要同步时间的服务器:192。168。138。136(ntpclient) linux系统:CentOSrelease6。9 配置ntpserver 打开192。168。138。140机器的etcntp。conf 文件内容如下:Formoreinformationaboutthisfile,seethemanpagesntp。conf(5),ntpacc(5),ntpauth(5),ntpclock(5),ntpmisc(5),ntpmon(5)。driftfilevarlibntpdriftPermittimesynchronizationwithourtimesource,butdonotpermitthesourcetoqueryormodifytheserviceonthissystem。restrictdefaultkodnomodifynotrapnopeernoqueryrestrict6defaultkodnomodifynotrapnopeernoqueryPermitallaccessovertheloopbackinterface。Thiscouldbetightenedaswell,buttodosowouldeffectsomeoftheadministrativefunctions。restrict127。0。0。1restrict6::1Hostsonlocalnetworkarelessrestricted。restrict192。168。1。0mask255。255。255。0nomodifynotrapUsepublicserversfromthepool。ntp。orgproject。Pleaseconsiderjoiningthepool(http:www。pool。ntp。orgjoin。html)。server0。centos。pool。ntp。orgiburstserver1。centos。pool。ntp。orgiburstserver2。centos。pool。ntp。orgiburstserver3。centos。pool。ntp。orgiburstbroadcast192。168。1。255autokeybroadcastserverbroadcastclientbroadcastclientbroadcast224。0。1。1autokeymulticastservermulticastclient224。0。1。1multicastclientmanycastserver239。255。254。254manycastservermanycastclient239。255。254。254autokeymanycastclientEnablepublickeycryptography。cryptoincludefileetcntpcryptopwKeyfilecontainingthekeysandkeyidentifiersusedwhenoperatingwithsymmetrickeycryptography。keysetcntpkeysSpecifythekeyidentifierswhicharetrusted。trustedkey4842Specifythekeyidentifiertousewiththentpdcutility。requestkey8Specifythekeyidentifiertousewiththentpqutility。controlkey8Enablewritingofstatisticsrecords。statisticsclockstatscryptostatsloopstatspeerstats 配置权限 文件中Permittimesynchronizationwithourtimesource,butdonotpermitthesourcetoqueryormodifytheserviceonthissystem。restrictdefaultkodnomodifynotrapnopeernoqueryrestrict6defaultkodnomodifynotrapnopeernoquery 上面是配置的说明,下面是配置项,这部分的配置是对客户端(需要同步时间的服务器)的请求的处理策略,默认是拒绝。有6的那一行是对ipv6的配置。可选的配置如下:ignore:关闭所有的NTP联机服务nomodify:客户端不能修改服务端的时间参数,但客户端可以同步时间。notrust:拒绝没有通过认证的客户端机器noquery:不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器notrap:不提供trap远端登陆nopeer:用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟kod:访问违规时发送KoD包。 把这两行注释掉,然后配置允许哪些机器可以跟ntpserver同步时间 可以配置具体的机器,如:restrict192。168。138。136nomodify 可以配置网段,如:mask配置子网掩码restrict192。168。0。0mask225。225。225。0nomodify 配置时间源 如果可以连接internet,可以配置internet上的时间源,internet上的ntp服务器有很多,可以去搜一下。 如果不能连接internet,则把本机作为时间源即可,配置如下:server127。127。1。0fudge127。127。1。0stratum10 时间源可以配置多个,先使用最上面的机器,如果这个机器不可用(比如网络连不上),则会逐下使用。 启动或重启ntp服务 查看ntp服务运行状态:etcinit。dntpdstatus 启动ntp服务etcinit。dntpdstart 客户端同步时间 使用ntpdate命令同步时间,ntpdatentpserveripntpdate192。168。138。140 linux系统,客户端的ntp服务不能启动,否则会报如下错误:ntpdate〔88383〕:theNTPsocketisinuse,exiting 停止ntp服务etcinit。dntpdstop 如果要每隔一段时间就同步一次时间,可以配置crontab定时任务,如,每小时校验一次时间1rootusrsbinntpdate192。168。138。140gt;devnull2gt;amp;1 注意事项: 注意防火墙的问题,如果无法同步,则检查防火墙