Linux 配置NTP时间同步服务

1.安装[可选,如已安装则跳过]

apt install ntp

2.启动NTP服务

systemctl start ntpd
systemctl enable ntpd

3.查看NTP服务运行状态

systemctl status ntpd

4.修改配置文件

vi /etc/ntpsec/ntp.conf

查找配置文件命令

find / -name ntp.conf

1.使用第三方NTP地址进行时间同步

1.将默认的pool配置注释掉,前面加#号代表注释
2.添加如下内容
server ntp.aliyun.com iburst
3.重启NTP服务
systemctl restart ntpd
4.查看同步状态
ntpq -pn

2.配置为内网 NTP Server

1.将默认的pool配置注释掉,前面加#号代表注释
2.添加如下内容
# 表示网关为192.168.58.1,子网掩码为255.255.255.0的机器可通过该服务端时间校准
restrict 192.168.58.1 mask 255.255.255.0 nomodify notrap
# 默认的一个内部时钟数据,在没有外部NTP服务器时,它为局域网用户提供服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10 #一般都设置为第10层
3.重启NTP服务
systemctl restart ntpd
4.查看同步状态
ntpq -pn

3.配置为内网 NTP Client

使用第三方NTP地址进行时间同步配置方法一致,将server指定为内网NTP Server地址即可。

4.其他的一些配置【可选】

# 不允许来自公网上ipv4和ipv6客户端的访问
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
posted @ 2023-12-09 17:49  SpringCore  阅读(3640)  评论(0编辑  收藏  举报