23

I have an old computer and BIOS counts the time slower than real ;)

So, how can I set my OS to update the time automatically using the internet?

If it updated the time only during booting, it would be enough.

slhck
  • 235,242
kravemir
  • 2,704

5 Answers5

29

If you have systemd in version greater than 213 (check: systemd --version), you don't have to install ntp package to synchronize system time.

systemd provides systemd-timesyncd daemon which implements SNTP (Simple NTP) client.

To start and enable SNTP synchronization:

timedatectl set-ntp true

To show current settings of the system clock and RTC:

timedatectl status

Configuration of systemd-timesyncd daemon is in /etc/systemd/timesyncd.conf file. You can provide your NTP servers there. By default all servers are commented out and NTP servers are obtained from systemd-networkd.service(8) configuration or via DHCP.

If you have installed Windows alongside Linux, you may struggle with dual-boot system time issues. The reason is simple: Windows keeps hardware clock in local time and Linux in UTC time (timedatectl set-local-rtc 1 may be helpful but is not recommended; you'd better change Windows time settings to force keeping hardware clock in UTC).

patryk.beza
  • 1,661
16

You can set the time during system boot actually, and from the Debian Documentation they even specify it for use on hardware that doesn't keep track of time properly. I recommend using NTP though. You can set it up to connect to an NTP server. First install NTP though, using

$ sudo apt-get install ntp

Once it's installed, navigate to /etc/ntp.conf which you can edit using your favourite text edit. Say, gedit or nano.

$ sudo nano /etc/ntp.conf

I'm not sure if it needs sudo, but you can use it anyway.

You need to know an NTP server to set this. Modify your file to be like so:

 logfile /var/log/xntpd
 driftfile /var/lib/ntp/ntp.drift
 statsdir /var/log/ntpstats/

 statistics loopstats peerstats clockstats
 filegen loopstats file loopstats type day enable
 filegen peerstats file peerstats type day enable
 filegen clockstats file clockstats type day enable

 server ntp.somedomain.something
 server ntp.something.else

Replace the somedomain.something and something.else with NTP servers. You can find some hfrom the NTP server home.

4
sudo apt-get install ntp
sudo systemctl restart ntp
sudo systemctl enable ntp 

That's it. Just run $ date to see if it works.

2

Install ntp and made it run on runlevels 2,3,5. Then it will pull the date and time from well-known sources and will adjust your system gradually.

grs
  • 1,228
0

In Debian 12 you can do this:

  1. sudo apt-get remove ntp chrony openntpd

  2. sudo apt-get install systemd-timesyncd

  3. systemctl status systemd-timesyncd.service should show "Active: active (running)"

  4. timedatectl status should show "System clock synchronized: yes" and "NTP service: active"

  5. sudo lsof -i shouldn't show any ntp connections anymore

  6. If you're using a restrictive nftables firewall, you also need to add nftables firewall rules similar to those below:

    udp sport ntp counter packets 0 bytes 0 accept
    in chain INPUT and this in chain OUTPUT:
    udp dport ntp counter packets 0 bytes 0 accept
    (you can edit the rules with kwrite /etc/nftables.conf after which you need to run sudo nft -f /etc/nftables.conf)

  7. If you're using KDE, right click the clock in the bottom right (in the traybar), click "Adjust Date and Time..." and make sure "Set date and time automatically" is enabled.

Previously, I had to use openntpd as described here which stopped working after upgrading to Debian12 and it often had problems before. Ntp didn't work and the default clock was off by a couple minutes on multiple machines. I think Debian/KDE should come with a reliably working clock by default without any such tinkering.