网络时间服务器IP地址(搭建内网必看)

在公司内网搭建一台ntp时间服务器,供局域网内所有机器平滑同步时间

公司局域网无法连接internet

概念:NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

资源:

时间服务器IP:192.168.138.140(ntp server)

需要同步时间的服务器:192.168.138.136 (ntp client)

linux 系统:CentOS release 6.9

配置ntp server

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

文件内容如下:

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

配置权限

文件中

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

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

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

把这两行注释掉,然后配置允许哪些机器可以跟ntp server同步时间

可以配置具体的机器,如:

restrict 192.168.138.136 nomodify

可以配置网段,如:mask配置子网掩码

restrict 192.168.0.0 mask 225.225.225.0 nomodify

配置时间源

如果可以连接internet,可以配置internet上的时间源,internet上的ntp服务器有很多,可以去搜一下。

如果不能连接internet,则把本机作为时间源即可,配置如下:

server 127.127.1.0
fudge 127.127.1.0 stratum 10

时间源可以配置多个,先使用最上面的机器,如果这个机器不可用(比如网络连不上),则会逐下使用。

启动或重启ntp服务

查看ntp服务运行状态:

/etc/init.d/ntpd status

启动ntp服务

/etc/init.d/ntpd start

客户端同步时间

使用ntpdate命令同步时间,ntpdate ntp_server_ip

ntpdate 192.168.138.140

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

ntpdate[88383]: the NTP socket is in use , exiting

停止ntp服务

/etc/init.d/ntpd stop

如果要每隔一段时间就同步一次时间,可以配置crontab定时任务,如,每小时校验一次时间

 * */1 * * * root /usr/sbin/ntpdate 192.168.138.140 >/dev/null 2>&1

注意事项:

注意防火墙的问题,如果无法同步,则检查防火墙

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

声明:所有白马号原创内容,未经允许禁止任何网站及个人转载、采集等一切非法引用。本站已启用原创保护,有法律保护作用,否则白马号保留一切追究的权利。发布者:白马号,转转请注明出处:https://www.bmhysw.com/article/13382.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
白马号白马号

相关推荐

  • word文档的高级排版(这些基本操作必须会)

    万丈高楼平地起,基础永远都是看上去最简单却永远是最重要的东西。在软件使用的过程中,很多人都被所谓的高手、大虾们的酷炫操作所吸引,殊不知,大虾们之所以能有运指如飞、潇洒酷炫的操作,完全是因为基础技巧掌握的牢固+勤学苦练的结果。 今天小编结合自己的工作体会,给大家整理了八条必会排版基础技巧,希望以此抛砖引玉,也欢迎大家积极留言,说说在Word排版工作中,对自己提…

    2022-04-30 投稿
    00
  • 20寸显示器分辨率多少合适(14寸至24寸分辨率介绍大全)

    在购买电脑时需要看各项数据,其中就包括分辨率,如果分辨率不对的话电脑画面的清晰度将会直接受到影响,电脑分辨率多少合适?一些人就在家里玩电脑的时候觉得分辨率不对而要进行调整,那电脑分辨率怎么调呢? 一、电脑分辨率多少合适 很多用户都认为设到最大值即为最理想的状态,其实不是这样想要起到好的效果,应该根据屏幕的尺寸大小来设置。一般情况下,显示器尺寸和分辨率值得关系…

    2022-04-30
    00
  • Win10怎么知道电脑的IP地址?查电脑的ip地址在哪里查?

    Win10怎么知道电脑的IP地址?查电脑的ip地址在哪里查? 什么是IP地址? Win10如何查看IP地址? 如何解决IP地址问题? 什么是IP地址? IP地址是Internet Protocol Address的缩写,是指分配给计算机或其他设备的数字标识符。它是一种唯一的地址,用于在网络上找到设备并进行通信。IP地址由四个数字组成,每个数字之间用点号分隔,…

    2023-08-07
    00
  • 电脑配件是什么梗(名词:电脑配件的来由究是动漫)

    动漫美少女角色中具有各种各样的萌属性,天然呆这种萌属性相信各位都很熟悉了,像是《轻音少女》中的平泽唯,就是这种萌属性的典型代表。 那天然疯,或者称之为人来疯的动漫美少女角色呢?可能这一类萌属性的美少女动漫角色就不是很多了,虽然数量不多,但是也还是有一部分典型的人来疯代表的。 物以稀为贵,正因为典型的人来疯动漫美少女角色并不算很多,所以当这些角色登场后,通常都…

    2022-05-01 投稿
    00
  • Win10总是更新失败怎么办?不同错误代码,一个小招快速解决!

    Win10总是更新失败怎么办?不同错误代码,一个小招快速解决! 错误代码1 错误代码2 错误代码3 错误代码4 错误代码1 错误信息:0x80073712 解决方法: 1. 打开“命令提示符”(管理员权限),输入以下命令并回车: DISM.exe /Online /Cleanup-image /Restorehealth 2. 等待命令执行完成,再次尝试更新…

    2023-08-08
    00

联系我们

QQ:183718318

在线咨询: QQ交谈

邮件:183718318@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信