L29※ubuntu搭建NTP Server

1> 寻找NTP SERVER

http://www.pool.ntp.org是NTP的官方网站,这里可以查询最近的NTP Server。

ntp1.aliyun.com
ntp.tencent.com
ntp.ntsc.ac.cn
# 中国NTPserver
server 0.cn.pool.ntp.org 
server 1.cn.pool.ntp.org 
server 2.cn.pool.ntp.org 
server 3.cn.pool.ntp.org

# 国内阿里云ntp
server ntp.aliyun.com iburst minpoll 4 maxpoll 10
server ntp1.aliyun.com iburst minpoll 4 maxpoll 10
server ntp2.aliyun.com iburst minpoll 4 maxpoll 10
server ntp3.aliyun.com iburst minpoll 4 maxpoll 10

#国外apple(苹果)公司提供
server time2.apple.com iburst minpoll 4 maxpoll 10
server time3.apple.com iburst minpoll 4 maxpoll 10
server time4.apple.com iburst minpoll 4 maxpoll 10
server time5.apple.com iburst minpoll 4 maxpoll 10

2> 安装NTP服务

# 安装前检查
rpm -qa ntp
# 安装
apt-get install -y ntp

3> 手动同步

ntpdate cn.pool.ntp.org

4> 修改配置文件

~# vim /etc/ntp.conf

driftfile /var/lib/ntp/ntp.drift  # 这是预设时间差异分析文件,我们暂时用不到,就这样留着就好啦
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# pool 0.ubuntu.pool.ntp.org iburst
# pool 1.ubuntu.pool.ntp.org iburst
# pool 2.ubuntu.pool.ntp.org iburst
# pool 3.ubuntu.pool.ntp.org iburst
# pool ntp.ubuntu.com

server 0.cn.pool.ntp.org prefer iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst

restrict -4 default kod notrap nomodify nopeer noquery limited  # 拒绝ipv4的用户
restrict -6 default kod notrap nomodify nopeer noquery limited  # 拒绝ipv6的用户
restrict 127.0.0.1   # 放行本机来源
restrict ::1  # 放行本机 ipv6 来源
restrict source notrap nomodify noquery

restrict [IP地址] mask [子网掩码] [parameter]

参数说明
ignore拒绝所有类型的ntp连接
nomodify用户端不能使用ntpc和ntpq修改服务器的时间参数,但是可以通过这台主机进行网络校时
noquery 用户端不能使用ntpc和ntpq等指令来查询时间服务器,等于不提供ntp校时服务
notrap不提供trap远程登录
notrust拒绝没有认证的用户端

5> 放开udp协议的123端口

vps开放端口

6> 启动服务

systemctl start  ntp
netstat -tunpl | grep ntp #检查下端口,主要是123端口

7> 客户端主机与NTP服务器同步

ntpdate 1.1.1.1
*/15 * * * *  root   /usr/sbin/ntpdate 1.1.1.1  # crontab -e 

8> windows 客户端测试ntp服务

C:\Users\Administrator> w32tm /stripchart /computer:192.168.1.1

返回 “11:11:01 error: 0x80072746” 表示NTP服务器不可用。

返回 “11:11:11 d:+00.0538300s o:+00.0323716s [ * ]” 表示NTP服务器正常。

9> windows 客户端连接linux中的ntp服务

① 以管理员身份运行命令提示符

net stop w32time  # 停止Windows Time服务

w32tm /unregister  # 取消注册Windows Time服务

w32tm /register  # 重新注册Windows Time服务

net start w32time  # 重新启动Windows Time服务

w32tm /resync /nowait  # 重新进行Windows时间同步

② windows time 服务设置成自动

图片[1]-L29※ubuntu搭建NTP Server-霜林轩

③ 更改组策略

运行中输入 gpedit.msc,找到计算机管理→管理模板→系统→Windows 时间服务→时间提供程序

配置NTP客户端(如下图所示)→ 启用NTP客户端

图片[2]-L29※ubuntu搭建NTP Server-霜林轩

10> 更改windows时间更新频率

修改注册表中的SpecialPollInterval值

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient

重启Windows Time服务

© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享