1. # 测试时钟服务器是否可用
  2. ntpdate -d 10.254.96.101
  3. # 修改配置文件
  4. vi /etc/ntp.conf

外网的时钟服务器

中国

cn.ntp.org.cn

中国香港

hk.ntp.org.cn

美国

us.ntp.org.cn

  1. # 时钟服务器的地址
  2. # server cn.ntp.org.cn iburst
  3. # 设置时钟服务器北京
  4. server 10.254.96.101 iburst
  5. # 上海
  6. server 10.254.17.253 iburst
  7. # 控制权限 本机IP mask 子网掩码 参数
  8. restrict 125.46.83.204 mask 255.255.255.224 nomodify
  9. restrict 62.66.6.20 mask 255.255.254.0 nomodify
  10. restrict 10.56.82.58 mask 255.255.255.192 nomodify
  11. restrict 62.208.36.250 mask 255.255.255.0 nomodify
  12. ignore :关闭所有的 NTP 联机服务
  13. nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
  14. notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网 NTP4.2 版本以后使用会出错
  15. noquery :不提供客户端的时间查询:用户端不能使用ntpqntpc等命令来查询ntp服务器
  16. notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
  17. nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
  18. # 设置本地时钟源的层次为5,这样如果NTP服务从本地时钟源获取时间的话,NTP对外宣布的时间层次为6
  19. # fudge 本机IP stratum 5
  20. fudge 62.208.36.250 stratum 5
  21. 配置完毕,重启NTP服务,使配置更改生效。
  22. service ntp restart
  23. 查看NTP服务和上级连通状态
  24. ntpq -p
  25. ---
  26. # 定时任务
  27. crontab -e
  28. # 每天12点同步时钟
  29. 0 12 * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1
  30. service crond reload
  31. ntpdate -u ntp 10.254.96.101
  32. systemctl start ntpd 启动
  33. systemctl stop ntpd 停止
  34. systemctl enable ntpd 设置开机自启
  35. timedatectl set-ntp yes
  36. 外网的都和 cn.ntp.org.cn 同步
  37. 内网的和 ntp服务器(可以连外网的)同步
  38. 郑州支队
  39. 192.168.100.245 62.66.6.20
  40. 郑州市局
  41. 192.168.100.112 62.66.6.20
  42. 济源
  43. 192.168.100.78 62.208.36.250
  44. 省厅
  45. 192.168.100.30 10.56.82.58
  46. 公安网的网络时钟服务器分别位于北京、上海、西安,服务地址依次为:10.254.96.10110.254.17.25310.254.57.253