Jump to content

NTP: Difference between revisions

m
Add link to chrony article
imported>Tobias.bora
No edit summary
m (Add link to chrony article)
 
(4 intermediate revisions by 2 users not shown)
Line 20: Line 20:
* for '''ntpd''', use <code>services.ntp.enable = true;</code>
* for '''ntpd''', use <code>services.ntp.enable = true;</code>
* for '''openntpd''', use <code>services.openntpd.enable = true;</code>
* for '''openntpd''', use <code>services.openntpd.enable = true;</code>
* for '''chrony''', use <code>services.chrony.enable = true;</code>
* for '''[[chrony]]''', use <code>services.chrony.enable = true;</code>


== Set NTP from DHCP servers ==
== Set NTP from DHCP servers ==


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>
<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>
<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>
<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>
<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>
Line 126: Line 128:
</li>
</li>
</ol>
</ol>
[[Category:Server]]
[[Category:Cookbook]]
2

edits