ntpd
实验条件:两台云服务器
系统环境:centos 7.0
地址信息:
Server - 公网地址:106.13.52.79
Server - 私网地址:172.16.0.4/20
Client - 公网地址:106.13.27.31
Client - 私网地址:172.16.16.4/20
服务端配置
[root@bcc28 ~]# rpm -q ntp
ntp-4.2.6p5-29.el7.centos.x86_64
[root@bcc28 ~]#
[root@bcc28 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@bcc28 ~]#
[root@bcc28 ~]# systemctl start ntpd
[root@bcc28 ~]# vim /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict 0.0.0.0 # 这里表示允许公网的设备过来获取ntp服务
restrict ::1
重启服务
[root@bcc28 ~]# systemctl restart ntpd
客户端配置
安装ntp
[root@bcc28 ~]# rpm -q ntp
ntp-4.2.6p5-29.el7.centos.x86_64
[root@bcc28 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@bcc28 ~]# systemctl start ntpd
编辑配置文件(vim /etc/ntp.conf),配置ntp服务地址
[root@bcc11 ~]# vim /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.centos.pool.ntp.org iburst
server 106.13.52.79 ## 在这里添加Server的公网地址
systemctl enable ntpd
systemctl start ntpd