NTP: Difference between revisions

imported>IgorM
m Fixed syntax highlighting errors by using lang=text where it was omitted
imported>IgorM
m Fixed highlighting in console examples
Line 25: Line 25:


Most of the time the default NTP servers will be reachable. However, sometimes the NTP servers can be blocked by the firewall (for instance most universities block NTP for security reasons). This will be visible in the <code>systemd-timesyncd.service</code>:
Most of the time the default NTP servers will be reachable. However, sometimes the NTP servers can be blocked by the firewall (for instance most universities block NTP for security reasons). This will be visible in the <code>systemd-timesyncd.service</code>:
<syntaxHighlight lang=text>
<syntaxHighlight lang=console>
$ sudo systemctl status systemd-timesyncd.service
$ sudo systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
● systemd-timesyncd.service - Network Time Synchronization
Line 34: Line 34:


You can also test a specific server as follows:
You can also test a specific server as follows:
<syntaxHighlight lang=text>
<syntaxHighlight lang=console>
$ nix-shell -p ntp
$ nix-shell -p ntp
$ ntpdate -q 0.nixos.pool.ntp.org
$ ntpdate -q 0.nixos.pool.ntp.org
Line 41: Line 41:


However, a replacement NTP is usually provided in that case via the DHCP protocol. You can see it for instance if you use Network Manager:
However, a replacement NTP is usually provided in that case via the DHCP protocol. You can see it for instance if you use Network Manager:
<syntaxHighlight lang=text>
<syntaxHighlight lang=console>
$ nmcli connection show 'name-of-the-current-connection' | grep ntp
$ nmcli connection show 'name-of-the-current-connection' | grep ntp
DHCP4.OPTION[8]:                        ntp_servers = 192.168.x.y
DHCP4.OPTION[8]:                        ntp_servers = 192.168.x.y
Line 51: Line 51:


You might also be able to get the actual hostname of the DHCP (if it exists) using:
You might also be able to get the actual hostname of the DHCP (if it exists) using:
<syntaxHighlight lang=text>
<syntaxHighlight lang=console>
$ sudo nmap -sP 192.168.x.y
$ sudo nmap -sP 192.168.x.y
</syntaxHighlight>
</syntaxHighlight>
Line 118: Line 118:


To apply the change, switch to your new configuration and make sure to restart Network Manager:
To apply the change, switch to your new configuration and make sure to restart Network Manager:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=console>
$ sudo systemctl restart NetworkManager.service
$ sudo systemctl restart NetworkManager.service
# Check if the NTP server is used (may need to wait a few minutes)
</syntaxHighlight>
Check if the NTP server is used (may need to wait a few minutes):
<syntaxHighlight lang=console>
$ sudo systemctl status systemd-timesyncd.service
$ sudo systemctl status systemd-timesyncd.service
</syntaxHighlight>
</syntaxHighlight>