您好,欢迎进入北京泰福特电子科技有限公司官网

咨询服务热线

400-015-1230

NTP服务配置ubuntu系统

发布时间:2022-04-12 09:36:15

NTP即是服务器,又是客户端,只需要通过配置即可。

准备两台机器分别作为服务端(IP地址设为192.168.10.10)和客户端(IP地址设为192.168.10.12)。

服务器:NTPD服务,负责与外部公共NTPD服务同步标准时间,作为内外网络的NTPD服务。

客户端:NTPclient,与服务器同步时间。

ubuntu系统

1.安装ntp,因为ntp服务既是服务器,又是客户端,因此两端安装方式一样

sudo apt-get install ntp

2.配置NTP-Server

# vim /etc/ntp.conf

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.

#statsdir /var/log/ntpstats/

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

# You do need to talk to an NTP server or two (or three).

#server ntp.your-provider.example

#NTP服务

server 210.72.145.44 perfer # 中国国家受时中心

# 外部时间server不可用时,以本地时间作为时间服务

server 127.127.1.0 # local clock

fudge 127.127.1.0 stratum 10

# 同意上层时间server主动改动本机时间

restrict 210.72.145.44 nomodify notrap noquery

# 同意内网其它机器同步时间

restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will

# pick a different set every time it starts up. Please consider joining the

# pool: <http://www.pool.ntp.org/join.html>

pool 0.debian.pool.ntp.org iburst

pool 1.debian.pool.ntp.org iburst

pool 2.debian.pool.ntp.org iburst

pool 3.debian.pool.ntp.org iburst

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for

# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>

# might also be helpful.

#

# Note that "restrict" applies to both servers and clients, so a configuration

# that might be intended to block requests from certain clients could also end

# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.

restrict -4 default kod notrap nomodify nopeer noquery limited

restrict -6 default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

# Needed for adding pool entries

restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if

# cryptographically authenticated.

#restrict 192.168.123.0 mask 255.255.255.0 notrust

# If you want to provide time to your local subnet, change the next line.

# (Again, the address is an example only.)

#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the

# next lines. Please do this only if you trust everybody on the network!

#disable auth

#broadcastclient

配置文件改动完毕,保存退出。重启服务。

# service ntpd restart

查看服务状态

#service ntpd status

查看服务连接和监听

# netstat -tlunp | grep ntp

ntpq -p 查看网络中的NTPserver

#ntpd -p

3.配置NTP-Clients

# vim /etc/ntp.conf

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.

#statsdir /var/log/ntpstats/

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

# You do need to talk to an NTP server or two (or three).

#server ntp.your-provider.example

server 192.168.10.10

# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will

# pick a different set every time it starts up. Please consider joining the

# pool: <http://www.pool.ntp.org/join.html>

pool 0.debian.pool.ntp.org iburst

pool 1.debian.pool.ntp.org iburst

pool 2.debian.pool.ntp.org iburst

pool 3.debian.pool.ntp.org iburst

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for

# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>

# might also be helpful.

#

# Note that "restrict" applies to both servers and clients, so a configuration

# that might be intended to block requests from certain clients could also end

# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.

restrict -4 default kod notrap nomodify nopeer noquery limited

restrict -6 default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

# Needed for adding pool entries

restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if

# cryptographically authenticated.

#restrict 192.168.123.0 mask 255.255.255.0 notrust

# If you want to provide time to your local subnet, change the next line.

# (Again, the address is an example only.)

#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the

# next lines. Please do this only if you trust everybody on the network!

#disable auth

#broadcastclient

 配置文件改动完毕,保存退出。重启服务。

# service ntpd restart

 查看服务状态

#service ntpd status

 配置完成,可以手动修改客户端时间,然后静置10几分钟,客户端就会跟服务器同步


  • 联系方式
  • 传 真:86-10-82782026
  • 电 话:400-015-1230
  • 地 址:北京市海淀区北清路68号院用友软件园北区17号楼三层
在线咨询

咨询电话:

400-015-1230

  • 微信扫码 关注我们

Copyright © 2002-2035 北京泰福特电子科技有限公司 版权所有 备案号:京ICP备12028220号-1
京公网安备 11010802025976号

扫一扫咨询微信客服

18519396506
Powered by RRZCMS