【问题标题】:ntp port was blocked, how to sync timentp端口被阻塞,如何同步时间
【发布时间】:2022-01-09 13:30:58
【问题描述】:

说明

我目前在学习中学习相关知识。在我的树莓派上使用Debian操作系统时,发现系统时间与实时不同步。

错误

  1. 错误信息如下。
 Certificate verification failed: The certificate is NOT trusted. The certificate chain uses not yet valid certificate.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]
Reading package lists... Done
W: Failed to fetch https://mirrors.tuna.tsinghua.edu.cn/debian/dists/buster/InRelease  Certificate verification failed: The certificate is NOT trusted. The certificate chain uses not yet valid certificate.  Could not handshake: Error in the certificate verification. [IP: 101.6.15.130 443]

NTP已经配置好了(可能我没有?不过我已经按照文档仔细配置了,如果可以的话,你可以简单描述一下配置过程。)经过很多次,我还是搞不明白问题所在.

ntp.conf 文件

  1. 我的ntp.conf如下:
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata
leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable


# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
server ntp.aliyun.com iburst minpoll 4 maxpoll 10

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
pool 0.debian.pool.ntp.org iburst
pool 1.debian.pool.ntp.org iburst
pool 2.debian.pool.ntp.org iburst
pool 3.debian.pool.ntp.org iburst


# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Needed for adding pool entries
restrict source notrap nomodify noquery
restrict ntp.aliyun.com nomodify notrap nopeer noquery
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient
root@rpi4-20210823:~#
  1. 关于我的 ntp 的一些事情
root@rpi4-20210823:~# date
Wed Jul 14 03:05:09 CST 2021
root@rpi4-20210823:~# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 203.107.6.88    .INIT.          16 u    - 1024    0    0.000    0.000   0.000
  1. 我的操作系统如下
root@rpi4-20210823:~# cat /etc/issue
Debian GNU/Linux 11 \n \l

root@rpi4-20210823:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

root@rpi4-20210823:~# hostnamectl
   Static hostname: rpi4-20210823
         Icon name: computer
  Operating System: Debian GNU/Linux 11 (bullseye)
            Kernel: Linux 5.10.0-8-arm64
      Architecture: arm64

我很想知道如何解决这个问题,非常感谢:) 如果您有任何问题,请留言并与我们交流。

【问题讨论】:

    标签: linux debian ntp


    【解决方案1】:

    您发布的错误消息似乎与您的问题无关,因为它看起来像是一个 apt-get 错误。 你是从哪里提取的?

    话虽如此,您可以手动与 ntpdate 同步时间吗? 您可以尝试这样做:

    # apt install ntpdate
    # ntpdate -v ntp.on.br
    

    如果您遇到网络问题/限制阻止您访问您的 NTP 服务器,这将清楚地显示出来。

    【讨论】:

    • 我按照您的建议输入了命令。我收到了这个ntpdate[1396]: ntpdate 4.2.8p12@1.3728-o (1)ntpdate[1396]: the NTP socket is in use, exiting
    • 由于我来自中国的一所大学,我认为123端口可能被学校的网络服务器禁止。所以我想找一些其他的方式来同步时间,比如 WSL
    • 确保在尝试手动与 ntpdate 同步之前停止 ntpd 守护进程:sudo systemctl stop ntpd 应该这样做。
    • 如果你的本地网络禁止了UDP 123端口,恐怕也没什么好做的了。但是,您的本地网络可能会提供您可以使用的内部 NTP 服务器。您可以询问您的管理员或尝试查看您的内部 DHCP 服务器是否通告了任何 NTP 服务器。然后,您可以窥探 DHCP 请求(使用 wireshark)或尝试使用 chrony(使用网络管理器,用于代替 ntpd)报告 DHCP 通告的 NTP 服务器:chronyc sources
    • 我终于通过向我的网络管理员询问 NTP 地址解决了这个问题,但我仍然想知道 WSL 是如何同步时间的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2013-11-16
    • 1970-01-01
    • 2013-01-01
    • 2023-03-14
    • 2013-07-20
    相关资源
    最近更新 更多