ubuntu server安装ntp

本文档描述了一个本地网络中NTP服务器配置的问题。作者在一个没有互联网连接的局域网中设置了NTP服务器来同步所有计算机的时间。尽管服务器运行正常且能够广播时间,但客户端无法成功接收并同步服务器的时间。

I have a local net with no internet and want to keep all computers in there time synced. I do not care about the absolute time, it should just be the same for all.

I found several posts about this. The most useful ones were:

server

I did setup the server with the IP 192.168.1.123 and it seems to be working ok: The deamon "ntpd" is running and I had been adding in etc/ntp.conf the lines

# this sets the source to local time
server 127.127.1.0
fudge 127.127.1.0 stratum 8

# this makes the ntpd deamon to send out its time on the local net.
broadcast 192.168.255.255 

I verified it with the ntpq command:

 ntpq -c lpeer
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
192.168.255.255       .BCST.     16 B    -   64      0  0.000    0.000   0.000

"BCST" says its in broadcast more and the IP shows its broadcasting to all computers on the local net (a B class network, thus 2x 255).

client

On client side I also installed ntp, and used the default /etc/ntp.conf and added the lines

server 192.168.1.123 iburst
server 127.127.1.0
fudge 127.127.1.0 stratum 8

where 192.168.1.123 is the local IP of the server broadcasting and the other line should tell the client (a laptop) to use its own clock when the network connection is off. I restarted the service on the client and ran ntpq to check the connection

ntpq -c lpeer
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
192.168.1.123        .INIT.     16 u     1   64     0   0.000    0.000   0.000
LOCAL(0)             .LOCL.     8 l      6   64     1   0.000    0.000   0.000

Repeating this command I can see the "when" column counting up both and starting with 0 again when reaching 64sec. I did expect after the 64 sec this would change to this:

ntpq -c lpeer
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.1.123        .INIT.     16 u     1   64     0   0.000    0.000   0.000
LOCAL(0)              .LOCL.     8 l      6   64     1   0.000    0.000   0.000

Note the "*" before the server IP. But it did not. What I got after about 1hr was

ntpq -c lpeer
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
192.168.1.123        .INIT.     16 u     1   64     0   0.000    0.000   0.000
*LOCAL(0)            .LOCL.     8 l     63   64   377   0.000    0.000   0.000

I think this tells me, there are 2 sources for NTP configured, but as the remote source is not working/not available/whatever it is not used and the fallback case local clock is used, but I am not sure if that interpretation is correct.

what I tried

I waited more than 1hr, I restarted the ntpd serveral times with sudo /etc/init.d/ntp restartand I also rebooted. Further I commented out the local section clock so that the only server was server 192.168.1.123. I could not get that "*" to appear. Also I saw a section in the ntp.conf that said

#if you want to listen to time broadcasts on you local subnet, 
#de-comment the next lines. Please do this only if you trust 
#everybody on the network!
#disable auth
#broadcastclient

I tried un-commenting and restarting the service but still that star did not appear. I am wondering about the last section, though, because this section did turn up in any other post or internet result that I saw on the ntp configuration. There are several ones on local setups and most seem to be find with the server address alone. Ping from client to server is fine. There is not firewall etc.

question

I am out of ideas. I think I have a server with fully working ntp server which is sending out the time. But I do have a client which is failing to receive the time information from the server.

What can I do to get the client running?



原文:https://askubuntu.com/questions/885345/local-ntp-server-not-used-by-clients-setup-issue

### 安装和配置 NTP 服务器 要在 Ubuntu 20.04 上安装并配置 NTP (Network Time Protocol) 服务器,可以按照以下方法操作: #### 1. 更新系统软件包 在开始之前,确保系统的软件包列表是最新的。运行以下命令来更新: ```bash sudo apt update && sudo apt upgrade -y ``` #### 2. 安装 NTP 软件包 通过 APT 包管理器安装 `ntp` 和其他必要的工具。执行以下命令完成安装[^1]: ```bash sudo apt install ntp -y ``` #### 3. 修改 NTP 配置文件 默认情况下,NTP 的主要配置文件位于 `/etc/ntp.conf`。编辑此文件以调整时间源和其他选项。 打开配置文件: ```bash sudo nano /etc/ntp.conf ``` - **添加或修改时间源** 找到 `server` 行,并根据需求替换为你信任的时间服务器地址。例如: ```plaintext server 0.pool.ntp.org iburst server 1.pool.ntp.org iburst server 2.pool.ntp.org iburst ``` - **允许本地网络同步** 如果希望让局域网中的设备能够连接到该 NTP 服务器,则需要启用权限控制。找到 `restrict` 条目,在适当位置添加如下内容: ```plaintext restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap ``` 此处假设子网为 `192.168.1.x`,可以根据实际情况更改 IP 地址范围。 保存并关闭文件。 #### 4. 启动和验证服务状态 重启 NTP 服务使新配置生效: ```bash sudo systemctl restart ntp ``` 检查服务的状态以确认其正常工作: ```bash sudo systemctl status ntp ``` 还可以使用以下命令查看当前正在使用的上游时间服务器及其延迟情况: ```bash ntpq -p ``` #### 5. 自定义脚本(可选) 对于无法访问外部互联网的环境,可以通过预下载的方式准备所需的二进制文件及相关依赖项。参考提供的部署脚本示例[^2],其中提到的关键部分在于单独提取核心功能实现自动化安装流程。 --- ### 注意事项 - 确保防火墙规则允许 UDP 流量通过端口 123。 - 对于高精度场景下可能还需要考虑硬件时钟校准等因素影响最终效果表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值