[Linux] centos 下 NTP配置局域网本地服务器时间同步

服务器端

1.修改配置文件/etc/ntp.conf

# 允许内网其他机器同步时间
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
  1. 重启ntp服务
    service ntpd restart

客户端

  1. 停掉NTP服务
    service ntpd stop

  2. 修改配置文件/etc/ntp.conf

#配置本地的时间同步服务器,并允许该服务器修改本机时间
server 192.168.2.11
restrict 192.168.2.11 nomodify notrap noquery
  1. 手工同步一次时间
    ntpdate 192.168.2.11

  2. 重启NTP服务
    service ntpd restart

一些命令

systemctl restart ntpd              # 重启ntpd服务
systemctl enable ntpd               # 将ntpd服务加入开机自启动

ntpstat                             # 查看ntp服务
ntpq -p                             # 查看ntp Server状态

iptables -A INTPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT      # 防火墙放行udp 123端口的报文

一些参数

restrict格式
restrict IPADDR mask MASK 参数
参数:
    ignore: 关闭所有NTP联机服务
    nomodify: 客户端不能更改服务器端的时间参数,但是可以通过服务端进行网络校时。
    notrust: 客户端除非通过认证,否则客户端来源将视为不信任子网
    noquery:不提供客户端的时间查询
    notrap:
ntpq -p参数

你可能感兴趣的:([Linux] centos 下 NTP配置局域网本地服务器时间同步)