Linux下搭建ntp时间同步服务器

1、ntpd软件安装(略过)

2、修改ntp.conf配置文件

vi /etc/ntp.conf

第一种配置:允许任何IP的客户机都可以进行时间同步
将“restrict default kod nomodify notrap nopeer noquery”这行修改成:

restrict default nomodify

第二种配置:只允许192.168.18.***网段的客户机进行时间同步
在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:

restrict 192.168.18.0 mask 255.255.255.0 nomodify

配置文件示例:/etc/ntp.conf

3、以守护进程启动ntpd

/usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid
service ntpd start

4、ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。

restrict default  nomodify
server ntp.api.bz
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.