Linux下使用ntpdate进行时间同步

1.简介

ntpdate是Linux下用于从NTP服务器同步时间的命令行工具。

2.安装

大多数Linux发行版已预装ntpdate。未安装的可使用以下命令:

复制代码
# Ubuntu/Debian `
`sudo apt-get install ntpdate`
`# CentOS/Fedora/RHEL `
`sudo yum install ntpdate

3.手工 同步 网络 时间

执行以下命令,将从time.nist.gov同步时间。

复制代码
# ntpdate time.nist.gov

若上面的时间服务器不可用,也可以选择以下服务器同步时间

time.nist.gov

time.nuri.net

0.asia.pool.ntp.org

1.asia.pool.ntp.org

2.asia.pool.ntp.org

3.asia.pool.ntp.org

4.定时 更新 网络 时间

使用crontab计划任务定时更新网络时间,修改crontab文件,在末尾增加* */1 * * * ntpdate time.nist.gov,每隔1小时同步一次时间。

打开/etc/crontab

复制代码
# vi /etc/crontab

5.查看当前时间

使用date命令查看当前时间。

6.同步到硬件

系统时间同步到硬件,防止系统重启后时间还原。

复制代码
# hwclock --systohc`
`

7.注意事项

ntpdate可能受防火墙限制。确保端口123(NTP)开放。

建议使用systemd-timesyncd替代ntpdate进行时间同步。

相关推荐
小政同学38 分钟前
【NFS故障】共享的文件无法执行
linux·运维·服务器
AI木马人1 小时前
3.【Prompt工程实战】如何设计一个可复用的Prompt系统?(避免每次手写提示词)
linux·服务器·人工智能·深度学习·prompt
ch3nyuyu1 小时前
Ubuntu(乌班图)基础指令
linux·运维·网络
minglie12 小时前
gcc编译器汇总
linux
挽安学长2 小时前
保姆级教程,通过GACCode使用Claude Code Desktop!
运维·服务器
firstacui3 小时前
MGRE实验
运维·服务器·网络
白菜欣3 小时前
Linux —《开发三件套:gcc/g++、gdb、make/Makefile 全解析》
linux·运维
何中应3 小时前
Grafana如何给列表设置别名
运维·grafana·监控
senijusene4 小时前
基于 imx6ull平台按键驱动开发:input子系统+中断子系统+platform总线
linux·驱动开发
MXsoft6184 小时前
运维的尽头,是把“救火”变成“算命”
运维