ntp源设置

本文介绍了如何配置一级和多级NTP源。主要内容包括修改/etc/resolv.conf和/etc/ntp.conf文件,开放NTP默认端口123,调整时区,并列举了国内外常用的NTP服务器IP地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.配置一级ntp源
修改/etc/resolv.conf文件如下(NTP默认端口123,需要开放):

# Generated by NetworkManager
nameserver 8.8.8.8  #google全球通用的DNS,114.114.114.114是国内常用DNS

修改/etc/ntp.conf文件如下:

#修改如下文件内容
restrict 127.0.0.1
restrict 172.0.0.0 mask 255.0.0.0  nomodify notrap
restrict 10.0.0.0 mask 255.0.0.0  nomodify notrap
#允许那些网段或者IP同步,不做限制则0.0.0.0 mask 0.0.0.0.需要注意的是4.2版本的ntpd的restrict参数不要加notrust否则客户端会同步不了。
server ntp1.aliyun.com
server 127.127.1.0
#一级NTP源时间来源,阿里云 or 本机时间
fudge 127.127.1.0 stratum 10 # 表示1级NTP源下最多有几层NTP链接

启动NTP

service ntpd restart #CentOS6.* 版本命令
service ntpd status #查看ntp状态
systemctl restart ntpd #CentOS7.* 版本命令
systemctl status ntpd #查看ntp状态

通过如下命令之后查看本机继承哪个IP的时间:

[root@ISOP610 yum.repos.d]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 172.19.97.158   172.19.97.153    4 u   19   64    3    0.320  280079.   3.242

以上命令每一列的含义如下所示:

◆ remote: 远程NTP服务器的IP地址或域名,带 “*” 的表示本地NTP服务器与该服务器同步。

◆ refid: 远程NTP服务器的上层服务器的IP地址或域名。

◆ st: 远程NTP服务器所在的层数。

◆ t: 本地NTP服务器与远程NTP服务器的通信方式,u: 单播; b: 广播; l: 本地。

◆ when: 上一次校正时间与现在时间的差值。

◆ poll: 本地NTP服务器查询远程NTP服务器的时间间隔。

◆ reach: 是一种衡量前8次查询是否成功的位掩码值,377表示都成功,0表示不成功。

◆ delay: 网络延时,单位是10的-6次方秒。

◆ offset: 本地NTP服务器与远程NTP服务器的时间偏移。

◆ jitter: 查询偏差的分布值,用于表示远程NTP服务器的网络延时是否稳定,单位为10的-6次方秒。

修改之后,某些时候是不会成功的,需要查看本机的时区:

[root@localhost ~]# timedatectl
      Local time: Sat 2018-03-31 01:11:46 UTC
  Universal time: Sat 2018-03-31 01:11:46 UTC
        RTC time: Sat 2018-03-31 01:11:36
       Time zone: Universal (UTC, +0000)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

当时区有问题时,如下命令修改时区为Asia/Shanghai:

[root@localhost ~]# timedatectl  set-timezone Asia/Shanghai

查看修改后的结果:

[root@localhost ~]# timedatectl
      Local time: Sat 2018-03-31 09:13:21 CST
  Universal time: Sat 2018-03-31 01:13:21 UTC
        RTC time: Sat 2018-03-31 01:13:11
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

2.配置多级ntp源
修改/etc/ntp.conf文件如下,重启NTP生效就行:

server 上述的NTP源IP

附:国内常用NTP服务器:
210.72.145.44 (国家授时中心服务器IP地址)
133.100.11.8 日本 福冈大学
time-a.nist.gov 129.6.15.28 NIST, Gaithersburg, Maryland
time-b.nist.gov 129.6.15.29 NIST, Gaithersburg, Maryland
time-a.timefreq.bldrdoc.gov 132.163.4.101 NIST, Boulder, Colorado
time-b.timefreq.bldrdoc.gov 132.163.4.102 NIST, Boulder, Colorado
time-c.timefreq.bldrdoc.gov 132.163.4.103 NIST, Boulder, Colorado
utcnist.colorado.edu 128.138.140.44 University of Colorado, Boulder
time.nist.gov 192.43.244.18 NCAR, Boulder, Colorado
time-nw.nist.gov 131.107.1.10 Microsoft, Redmond, Washington
nist1.symmetricom.com 69.25.96.13 Symmetricom, San Jose, California
nist1-dc.glassey.com 216.200.93.8 Abovenet, Virginia
nist1-ny.glassey.com 208.184.49.9 Abovenet, New York City
nist1-sj.glassey.com 207.126.98.204 Abovenet, San Jose, California
nist1.aol-ca.truetime.com 207.200.81.113 TrueTime, AOL facility, Sunnyvale, California
nist1.aol-va.truetime.com 64.236.96.53 TrueTime, AOL facility, Virginia
————————————————————————————————————
ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)
s1a.time.edu.cn 北京邮电大学
s1b.time.edu.cn 清华大学
s1c.time.edu.cn 北京大学
s1d.time.edu.cn 东南大学
s1e.time.edu.cn 清华大学
s2a.time.edu.cn 清华大学
s2b.time.edu.cn 清华大学
s2c.time.edu.cn 北京邮电大学
s2d.time.edu.cn 西南地区网络中心
s2e.time.edu.cn 西北地区网络中心
s2f.time.edu.cn 东北地区网络中心
s2g.time.edu.cn 华东南地区网络中心
s2h.time.edu.cn 四川大学网络管理中心
s2j.time.edu.cn 大连理工大学网络中心
s2k.time.edu.cn CERNET桂林主节点
s2m.time.edu.cn 北京大学

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值