千家信息网

linux中怎么配置ntp服务器

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,本文小编为大家详细介绍"linux中怎么配置ntp服务器",内容详细,步骤清晰,细节处理妥当,希望这篇"linux中怎么配置ntp服务器"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习
千家信息网最后更新 2026年11月03日linux中怎么配置ntp服务器

本文小编为大家详细介绍"linux中怎么配置ntp服务器",内容详细,步骤清晰,细节处理妥当,希望这篇"linux中怎么配置ntp服务器"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

一.安装ntp软件

1.检查是否安装了ntp相关包。
rpm -qa | grep ntp

2.安装ntp软件。
yum -y install ntp

二.参数讲解

ignore :关闭所有的 ntp 联机服务

nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。

notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网

noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器

notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。

nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟

kod : 访问违规时发送 kod 包。

三.修改配置文件

1.查看未修改的配置文件

# grep ^[^#] /etc/ntp.conf  driftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict ::1server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor

1.设置允许任何ip的客户机都可以进行时间同步(修改后的配置文件)

# grep ^[^#] /etc/ntp.conf  driftfile /var/lib/ntp/driftrestrict default nomodify notraprestrict 127.0.0.1restrict ::1server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor

2.只允许192.168.1.0网段的客户机进行时间同步(修改后的配置文件)

# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict ::1restrict 192.168.1.0 mask 255.255.255.0 nomodify notrapserver 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor

四.启动ntp服务和防火墙

systemctl start ntpd
systemctl enable ntpd
iptables -a input -p udp -i eno16777736 -s 192.168.1.0/24 --dport 123 -j accept
setsebool -p ntp_disable_trans 1#selinux设置
vi /etc/sysconfig/ntpd#允许bios与系统时间同步,添加下面一行。
sync_hwclock=yes

五.检测ntp

1.检测ntp服务是否运行

# netstat -tlunp | grep ntpudp    0   0 192.168.1.101:123    0.0.0.0:*              2563/ntpd     udp    0   0 127.0.0.1:123      0.0.0.0:*              2563/ntpd     udp    0   0 0.0.0.0:123       0.0.0.0:*              2563/ntpd     udp6    0   0 fe80::20c:29ff:fe7b:123 :::*                2563/ntpd     udp6    0   0 ::1:123         :::*                2563/ntpd     udp6    0   0 :::123         :::*                2563/ntpd

2.查看ntp服务器有无和上层ntp连通

# ntpstatsynchronised to ntp server (120.25.108.11) at stratum 3  time correct to within 99 ms  polling server every 64 s

3.查看ntp服务器与上层ntp的状态

# ntpq -p   remote      refid   st t when poll reach  delay  offset jitter============================================================================== news.neu.edu.cn .init.     16 u  -  64  0  0.000  0.000  0.000x202.118.1.130  202.118.1.47   2 u  7  64 377 153.659  9.605 19.941*time4.aliyun.co 10.137.38.86   2 u  10  64 377  39.666 -47.661 15.944remote  - 本机和上层ntp的ip或主机名,"+"表示优先,"*"表示次优先refid  - 参考上一层ntp主机地址st    - stratum阶层when   - 多少秒前曾经同步过时间poll   - 下次更新在多少秒后reach  - 已经向上层ntp服务器要求更新的次数delay  - 网络延迟offset  - 时间补偿jitter  - 系统时间与bios时间差

六.配置时间同步客户机

1.执行ntpdate命令:

ntpdate 192.168.1.101 #192.168.1.101为ntp服务器ip地址

2.写入bios

hclock -w

3.crond服务

vi /etc/crontab
30 8 * * * root /usr/sbin/ntpdate 192.168.1.101; /sbin/hwclock -w

4.重启crond服务

service crond restart

读到这里,这篇"linux中怎么配置ntp服务器"文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注行业资讯频道。

服务 服务器 配置 客户 时间 同步 主机 客户端 文件 上层 客户机 文章 控制 内容 参数 命令 地址 消息 端的 系统 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 咖啡网 互联网科技名片 蓝思科技飞鸽互联网 江苏根荣互联网科技 智能科技公司是互联网公司吗 网络科技有限互联网 深圳科技互联网 云电互联网科技 碳银互联网科技有限公司 互联网科技股有哪些 福州新华互联网科技学校 知乎 中国航天科技大学国际工业互联网 链环科技传统企业怎么转型互联网 科技类公司包括互联网吗 长沙互联网科技 中天科技中国工业互联网 广州百诚互联网科技有限公司官网 北京天晋互联网科技有限公司 悟空问答互联网科技 现代科技的标志之一的互联网 互联网科技垄断 碳银互联网科技有限公司 剑昆互联网络科技有限公司临桂 互联网系的金融科技公司 宜昌元轩互联网科技有限公司 洛阳昕诺飞互联网科技有限公司 中科明德北京互联网科技 张召忠谈中国互联网科技 科技互联网行业投资研究 恒生科技互联网指数十大成分股
0