当前位置: 代码迷 >> 综合 >> Linux下局域网同步时间
  详细解决方案

Linux下局域网同步时间

热度:40   发布时间:2024-01-16 21:30:37.0
  1. 选择一台能上外网的机器作为时间服务器(都不能上亦可以,任选一台即可,但是只能保证局域网内时间同步)
  2. 配置此时间服务器
    • 安装 ntp
    • 在 /etc/ntp.conf 中配置
      • restrict 127.0.0.1 //给予本机所有权限
        restrict -6 ::1 //不大明白,针对IPV6吗?
        restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap //给局域网内主机同步时间的权限,但不允许修改时间服务器的时间
        server 0.rhel.pool.ntp.org //时间服务器,下同
        server 1.rhel.pool.ntp.org
        server 2.rhel.pool.ntp.org
      • 其余采用默认的配置即可
  3. 配置局域网内机器
    • 安装 ntp
    • 在 /ect/ntp.conf 中配置
      • 注释掉原来的外网时间服务器,添加内网时间服务器:
        • server 192.168.1.100 //修改为你内网时间服务器的IP
    • 设置计划任务,每小时同步一次:
      • vi /etc/cron.hourly/ntpdatehourly.sh
        添加如下内容:
        #!/bin/sh 
        ntpdate 192.168.1.100
    • 停掉 ntpd 服务:service ntpd stop
    • 手动同步时间