搭建ntp服务器
1.同步网络时间#
先关闭掉ntp服务,使用ntpd同步网络时间。
/etc/init.d/ntpd stop
ntpdate 2.hk.pool.ntp.org
网络时间可以从http://www.pool.ntp.org中获取离自己最近的区域,我这里选的香港
2. 配置/etc/ntp.conf#
更改server
1 2 3 | server 2.hk .pool.ntp.org server 0.asia .pool.ntp.org server 3.asia .pool.ntp.org |
设置权限:
参数有以下几个:
ignore :关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
1 2 3 | restrict default kod nomodify notrap nopeer noquery restrict 127.0 . 0.1 restrict 192.168 . 0.0 mask 255.255 . 255.0 nomodify |
3. 开放端口123
1 2 | iptables - A INPUT - p udp - - dport 123 - j ACCEPT / etc / init.d / iptables save |
4. 客户端设施
我们在客户机上同步刚才搭建的时间服务器了,192.168.0.80就是我刚搭建的。
1 2 3 4 5 | server 192.168 . 0.80 prefer server 0.centos .pool.ntp.org iburst server 1.centos .pool.ntp.org iburst server 2.centos .pool.ntp.org iburst server 3.centos .pool.ntp.org iburst |
查看效果
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了