Synchronize Your Computer Time with NTP

0
96
Synchronize Your Computer Time with NTP

Dit bericht verscheen eerder bij FOSSlife

Setting the Hardware Clock

In addition to the software clock, your computer has another timekeeper, and this one will continue to count down the days when your computer is switched off and even when it is not plugged in.

To ensure uninterrupted timekeeping, computer mainboards have a battery-buffered clock, referred to as the CMOS clock, RTC (Real-Time Clock), BIOS clock, or even hardware clock.

The hwclock program lets you read and set the hardware clock; the commands all require root privileges. When used in combination with the -r ­option, you can display the local hardware time:

# hwclock -r
2019-02-19 15:44:09.49830-0500

Additionally, hwclock has options for setting the system time to reflect the hardware clock time (hwclock -s) or vice versa (hwclock -w).

A combination of –set and –date sets a specific time. You need to enter a string to describe the new date and time after the –date parameter. The format is exactly the same as the date program’s -s option. The command

# hwclock --set --date="+2 hours"

sets the hardware clock to a time two hours in the future.

Automated!

Network Time Protocol (NTP) is a standard for automating the synchronization of clocks in computer systems. The time signal propagates over the network from an NTP server to a client, and you can configure the point in time when your Linux machine’s NTP client contacts a server on the network. This could be at boot time or when you get onto the Internet, or you could use a manual command in the shell.

In the pre-Systemd era, most major Linux distributions had packages available for enabling NTP support. Many of those packages still exist – see the documentation for your own Linux distribution to learn about NTP package options.

Systemd provides a built-in systemd‑timesyncd service that performs basic time synchronization duties. To check whether the service is running on your system, enter:

systemctl status systemd‑timesyncd.service

The systemd‑timesyncd service is like other Systemd services. You can start, stop, or restart it using a variation of the systemctl command:

systemctl restart systemd‑timesyncd.service

See the article on Systemd elsewhere in this issue, or consult the systemctl man page, for more on managing Systemd services.

This article originally appeared in the Linux Shell Handbook and is reprinted here with permission.

Dit bericht verscheen eerder bij FOSSlife

Vorig artikelMCU processor — Bluespec Inc.
Volgend artikelIT Sustainability Think Tank: Keeping one step ahead of regulation