ntp server搭建–centos7
一.ntp server搭建
1.下载ntp服务
yum install ntp -y
yum install ntpdate -y
2.关闭防火墙或者设置白名单(桥接的虚拟机把windows防火墙关了)
#systemctl stop firewalld.service
#systemctl status firewalld.service
3.然后进入/etc/ntp.conf文件加入restrict 19.168.10.0 mask 255.255.255.0 nomodify
意思是允许19.168.10.0/24的网段的ip进行同步,但不允许修改本机时间,也可以设成单个ip或者某个路由器ip,如restrict 10.168.10.1或restrict 10.168.10.233
重启ntp服务
systemctl restart ntpd
二:同步远程ntp server
1.下载ntp服务
yum install ntp -y
yum install ntpdate -y
2.用ntpstat或ntpq -p查看与上层ntp server同步状况
3.l临时修改:ntpdate 【ntp server ip】
如 ntpdate 202.112.0.7
4.永久修改:vi /etc/ntp.conf
加入 server 202.112.0.7 prefer
重启服务 systemctl restart ntpd
5.用ntpq -p/ntpstat/date查询
6.设置硬件时间与系统一致并校准
/sbin/hwclock --systohc