查看:date
修改时间:date -s 11:11:11
修改日期:date -s 2021-10-09
修改日期和时间: date -s '2021-10-09 11:11:11'
时间同步软件ntp
从外部服务器同步时间:
ntpdate cn.ntp.org.cn
从本地服务器同步时间:
ntpdate 192.168.1.14
本地时间同步服务
需要先开启服务ntpd:service ntpd start
如果开启服务的机器防火墙没有开放udp123端口,会导致服务报错:no server suitable for synchronization found
配置文件:/etc/ntp.conf
# 权限控制
restrict default kod nomodify notrap nopeer noquery # 拒绝ipv4用户
restrict -6 default kod nomodify notrap nopeer noquery # 拒绝ipv6用户
restrict 210.72.145.44 # 授权国家授时中心服务器访问本地NTP
restrict IP # 授权指定IP访问本地NTP
restrict 127.0.0.1
restrict -6 ::1
restrict 127.0.0.1
restrict 192.168.188.2 mask 255.255.255.0 nomodify #本地网段授权访问
# 源服务器
server cn.ntp.org.cn prefer # 指定上级更新时间服务器,优先使用这个地址
# 差异分析
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys