Home > System Tutorial > LINUX > How to synchronize time with the Internet under Linux

How to synchronize time with the Internet under Linux

王林
Release: 2024-06-28 07:34:38
Original
1071 people have browsed it

How to synchronize time with the Internet under Linux

1. Install ntp
[root@server-2 ~]# yum install -y ntpdate
Copy after login
2. Synchronization time
// 方式一、使用域名连接,要经过DNS解析,速度慢。
[root@server-2 ~]# ntpdate pool.ntp.org
// 方式二、使用IP连接,超级快。
[root@server-2 ~]# ntpdate 120.24.81.91
Copy after login

http://www.pool.ntp.org is the official website of NTP. On this we can find the NTP Server cn.pool.ntp.org from our country. It has 3 server addresses:
Server 1: 1.cn.pool.ntp.org
Server two: 2.asia.pool.ntp.org
Server three: 3.asia.pool.ntp.org
(There are sometimes problems with using domain names directly. You can ping their IP first and then synchronize it with the IP address)

// The following message appears to indicate success

Feb 21:23:06 ntpdate[62910]: step time server 182.92.12.11 offset -40.589470 sec
Copy after login
3. Write the system time to the system hardware to avoid restarting the server time and overwriting it

//Display hardwareclock system hardware time

[root@server-2 ~]# hwclock
Copy after login

//Write the system time into the system hardware

[root@server-2 ~]# hwclock -w
Copy after login
4. Set scheduled tasks to synchronize network time

The crontab format is as follows:

# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
Copy after login
There are two ways to set crontab scheduled tasks:
1. Write it in /etc/crontab

Code:

11 * * * root ntpdate 210.72.145.44
Copy after login

Synchronize time with China National Time Service Center at 11 o'clock every day
Synchronize time with China National Time Service Center at 11 o'clock every day
Of course the premise is

apt-get install ntpdate
Copy after login

Code is also available

11 * * * root ntpdate us.pool.ntp.org
Copy after login
2. Use the command crontab -e
crontab -e
    10 5 * * * root ntpdate us.pool.ntp.org;hwclock -w
Copy after login

In this way, the network time will be automatically adjusted at 5:10 every day, and the BIOS time will be updated at the same time

The above is the detailed content of How to synchronize time with the Internet under Linux. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template