ntp 服务器默认端口是123,如果防火墙是开启状态,在一些操作可能会出现错误,所以要记住关闭防火墙。
先执行以下命令查看是否安装 ntp:
rpm -q ntp
若没有安装则安装 ntp:
yum install ntp
完成后,配置开机自启:
chkconfig ntpd on
检查是否设置成功:
chkconfig ntpd --list
若 5 为 on 则表示开机自启:
NTP 配置文件:
driftfile /var/lib/ntp/drift # 系统时间与 BIOS 事件的偏差记录
restrict default kod nomodify notrap nopeer noquery # 拒绝 IPv4 的用户
restrict -6 default kod nomodify notrap nopeer noquery # 拒绝 IPv6 的用户
restrict 127.0.0.1 # 放行本机来源
restrict -6 ::1
# restrict 192.168.21.0 mask 255.255.255.0 nomodify # 放行局域网用户来源
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap # 允许任何主机都能访问这个 ntp 服务器
server 210.72.145.44
server 127.127.1.0
# 如果配置的server 210.72.145.44 无效时,则 NTP 服务器会根据这里的配置,把自己的时间做为 NTP 服务器的时间,即和自己同步。考虑到这里是局域网里不可以访问外网,所有这里需要把这个配置项用上。
fudge 127.127.1.0 stratum 10 #设