NTP配置注意

ntp可以搭建两种方式:
1.只配置client端
centos默认的server端,在配置文件/etc/ntp.conf里已经配置好了
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

2.自己搭建server端和client端

client:
step1:
/etc/ntp.conf
server 192.168.0.163 #配置上游时间服务器为本地的ntpd Server服务器
restrict 192.168.0.163 nomodify notrap noquery #配置允许上游时间服务器主动修改本机的时间
step2:
与本地ntpd Server同步一下
]# ntpdate -u 192.168.0.163
step3:
启动ntp服务/开机自启
]# systemctl start/enable ntpd
step4:
]# ntpq -p #查看状态

为了操作方便,整理了一下相关的简单命令:
]#ntpstate
synchronised to NTP server (185.216.231.25) at stratum 3
time correct to within 90 ms
polling server every 64 s
##查看ntp的server端的IP,synchronised 显示已同步就是ntp–>ok

]#ntpdate -d -b 10.43.201.251 #手动更新时间,对应server ip
-d: 指定调试方式。判断ntpdate命令会产生什么结果(不产生实际的结果)。结果再现在屏幕上。这个标志使用无特权的端口
-b: 通过调用settimeofday子例程来增加时钟的时间

]#ntpq -p #查看网络中的NTP服务器

#########################
server:
如果要配置serve端
/etc/ntp.conf
step1:
restrict 192.168.111.0 mask 255.255.255.0 nomodify notrap

#允许特定网段能同步时间,允许内网其他机器同步时间,如果不添加该约束默认允许所有IP访问本机同步服务
权限的设定主要以 restrict 这个参数来设定,主要的语法为: 
restrict IP地址 mask 子网掩码 参数
参数有以下几个: 
ignore :关闭所有的 NTP 联机服务 
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。 
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网 
noquery :不提供客户端的时间查询

step2:
注释以下网络时间服务地址几行:
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
step3:
#配置和上游标准时间同步
server 101.201.72.121 # 中国国家授时中心
server 133.100.11.8 #日本[福冈大学]
server 3.cn.pool.ntp.org
server 1.asia.pool.ntp.org
server 3.asia.pool.ntp.org
#配置允许上游时间服务器主动修改本机(内网ntp Server)的时间
restrict 101.201.72.121 nomodify notrap noquery
restrict 133.100.11.8 nomodify notrap noquery
restrict 3.cn.pool.ntp.org nomodify notrap noquery
restrict 1.asia.pool.ntp.org nomodify notrap noquery
restrict 3.asia.pool.ntp.org nomodify notrap noquery
————————————————
server 127.127.1.0
Fudge 127.127.1.0 stratum 10
#如果网络时间同步服务器不可以用,就以本地时间为标准想客户端提供服务。127.127.1.0–本地时间IP就是这个。

step4:
systemctl start ntpd
systemctl enable ntpd
启动后5-10分钟内自动进行同步。

注意:防火墙配置
由于NTP服务需要使用到UDP端口号123,所以当系统的防火墙(Iptables)启动的情况下,必须开放UDP端口号123
]# firewall-cmd --permanent --add-port=123/udp
]# firewall-cmd --reload
查看防火墙已打开端口
]# iptables -L -n

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值