Ubuntu操作系统纯内网环境搭建ntp时钟同步服务器//京鸿通信/www.kyohoon.com/15507589165

发布时间 2023-04-21 11:47:47作者: 花无缺Andyi

一、环境准备

     服务器: 192.168.10.181(Ubuntu操作系统)

     客户端:192.168.10.82  (Ubuntu操作系统)

    所有服务器均不能访问互联网

二、ntp服务器端操作:

     (1).现在服务器端安装ntp服务器安装包,首先需要在172.16.20.129服务器上准备好ntp安装包。并进行安装ntp服务。

       apt-get install -y ntp

    (2).  编辑配置文件:

      vim /etc/ntp.conf    #修改以下内容

    restrict 192.168.10.1 mask 255.255.255.0 modify notrap     #注释:192.168.10.1  为局域网的网关。  255.255.255.0  为局域网的子网掩码

    在最后添加以下两行:

    server 127.127.1.0
    fudge 127.127.1.0 stratum 10

   (3)、重启ntp服务并设置开机自启动

     systemctl restart ntp

    systemctl enable ntp

    systemctl  status ntp

三、ntp客户端操作: (这步不确定)

    (1).客户端也需要下载离线的ntp软件并安装

    apt-get install -y ntp

    (2).修改配置:

    vim /etc/ntp.conf

restrict 172.16.20.129 nomodify notrap nopeer noquery      # 注释:172.16.20.129  为ntp服务端IP地址。

在最后添加以下一行:

server 172.16.20.129     # 注释:172.16.20.129 为ntp服务端IP地址 

    (3)重启服务并设置开机自启动

systemctl  restart ntp

systemctl  enable ntp

systemctl  status ntp

   (4)  添加定时任务:

vim /etc/crontab 

在最下面添加以下内容:

*       *       *       *       ntpdate 172.16.20.129        #注释 172.16.20.129 为ntp服务端IP地址。

 

等待ntp服务自动同步时间。大约需要等待10分钟左右。

或者直接  sudo ntpdate  -d 172.16.20.129

修改日期:date -s 2021-08-31

修改时间:date -s 12:00:00

将时间写入硬件: hwclouc --systohc