With what interval ntpsec service requests time from Internet in Linux?
Assistant
NTPsec, like its predecessor NTP (Network Time Protocol), works by polling NTP servers at intervals determined by the settings in its configuration file and the dynamics of the network conditions.
By default, NTPsec uses a dynamically adjusting polling interval. When you start the NTPsec service, it begins with a relatively short interval and increases it as the local clock and the remote servers remain in sync. This is known as the poll interval and is expressed in seconds to the power of 2.
Here’s a typical progression:
User
There are lines not only "server" but also "pool". Is there any difference? Can I set minpoll and maxpoll to "pool" lines also?
Assistant
Yes, there is a difference between the server and pool directives in the NTPsec configuration file, and you can set minpoll and maxpoll for both.
server Directive
The server directive is used to specify a single NTP server. This is the traditional way of defining a time source in NTP configurations.
Example:
server time.example.com
pool Directive
The pool directive, on the other hand, specifies a pool of NTP servers. The NTP client will automatically manage connections to multiple servers from the pool, selecting a subset to use at any given time. This increases reliability and redundancy.
Example:
pool pool.ntp.org
User
Please explain what means "tos maxclock 11", "tos minclock 4 minsane 3" and "iburst" word in /etc/ntpsec/ntp.conf file
Assistant
User
Can I put line "tos minpoll 6 maxpoll 10" into configuration?
Assistant
No, the tos (type of service) directive does not support minpoll and maxpoll parameters. The minpoll and maxpoll parameters are meant to be used within the specific server or pool directives in the NTPsec configuration file.
Here is the proper way to configure minpoll and maxpoll:
For a single server:
server time.example.com minpoll 6 maxpoll 10
User
How ntpsec determine my timezone ?
Assistant
NTPsec, like standard NTP, is primarily concerned with synchronizing your system's time to Coordinated Universal Time (UTC). It does not deal directly with time zones. Time zone management is handled separately by the operating system and its configuration.
User
Where I can change type to use - UTC or local time in Linux?
Assistant
User
Where I can see list of available time zones?
Assistant
You can see a list of available time zones on a Linux system in several ways. Below are some of the common methods:
Using timedatectl
The timedatectl command can be used to list available time zones.
User
Okay. So I have set type to UTC in /etc/adjtime and wrote my timezone into /etc/timezone. I also disabled systemd-timesyncd service and installed ntpsec. Describe full way how operating system gets and sets correct time based on information from NTP servers and my timezone
Assistant
User
How to prevent Linux update hardware clock (deny --systohw)?
Assistant
The minimum poll interval (minpoll) is 64 seconds (2^6).
The maximum poll interval (maxpoll) can go up to 1024 seconds (2^10).
These defaults can be adjusted in the configuration file, typically located at /etc/ntpsec/ntp.conf on many Linux distributions.
For example:
server time.example.com minpoll 6 maxpoll 10
You can specify minpoll and maxpoll for individual servers or pools to adjust their polling intervals as necessary for your specific network requirements.
To check the current server polling intervals and status, you can use the ntpq -p command, which displays the status of NTP peers along with their polling intervals.
ntpq -p
This will give you an output similar to this:
remote refid st t when poll reach delay offset jitter
==============================================================================
*time.example.co .GPS. 1 u 18 64 377 0.798 0.041 0.012
+another-server 10.1.1.1 2 u 46 64 377 1.100 0.110 0.033
In this example, poll represents the current polling interval in seconds to the power of 2 (e.g., 64 means 2^6 seconds).
Remember that NTPsec, by design, aims to minimize network traffic while maintaining time accuracy. The intervals are adjusted to balance this trade-off, starting with frequent polls to establish an accurate time baseline and then lengthening the interval once synchronization is stable.
Using pool has several advantages, such as automatic failover and load distribution, which helps in maintaining consistent time synchronization.
Setting minpoll and maxpoll for pool Directives
Yes, you can set minpoll and maxpoll for pool directives as well. This allows you to specify the polling intervals for all servers within the specified pool.
Example:
pool pool.ntp.org minpoll 6 maxpoll 10
This configuration will apply the specified polling intervals to all servers obtained from the pool.ntp.org pool.
To summarize, both server and pool directives can have minpoll and maxpoll specified, and the primary difference between them is that server defines a single NTP server, while pool defines a collection of servers. Using pool can provide enhanced reliability and load balancing.
In the context of the /etc/ntpsec/ntp.conf file, these directives and options are used to fine-tune the behavior of the NTP daemon. Let’s break down each of these:
tos maxclock 11
tos: This stands for "type of service," and it is used to specify various parameters that control the behavior of the NTP daemon.
maxclock 11: This parameter sets the maximum number of remote servers or peers to be used in the time synchronization process. In this case, 11 indicates that the NTP daemon will consider up to 11 servers or peers when determining the system time.
tos minclock 4 minsane 3
minclock 4: This parameter sets the minimum number of remote servers or peers that must be available and considered reliable before the NTP daemon will synchronize the system clock. In this example, at least 4 servers or peers must be available.
minsane 3: This parameter sets the minimum number of remote servers or peers that must agree with each other (showing consistent time) before the NTP daemon considers them believable (sane). In this example, at least 3 servers or peers must be in agreement.
These settings help ensure that the NTP daemon has enough data from reliable sources to make accurate time synchronization decisions.
iburst
iburst: This option is used with server and pool directives. When specified, it instructs the NTP daemon to send a burst of packets if the server is unreachable, speeding up the initial synchronization process. Instead of the usual one packet, the daemon will send a burst of 8 packets in rapid succession. This helps achieve quicker synchronization when the NTP daemon starts or when a server becomes unreachable and then available again.
Example configuration line with iburst:
server time.example.com iburst
The iburst option is particularly useful when you want to reduce the time it takes to synchronize the clock when the NTP service is initially started or when recovering from network interruptions.
Summary
tos maxclock 11: Use a maximum of 11 servers or peers for synchronization.
tos minclock 4 minsane 3: Require at least 4 servers or peers to be available (minclock) and at least 3 of them to show consistent time before considering the time synchronized (minsane).
iburst: Speeds up initial synchronization by sending a burst of packets if the server is unreachable.
These settings help fine-tune the behavior of the NTP daemon to achieve more reliable and faster time synchronization.
For a pool of servers:
pool pool.ntp.org minpoll 6 maxpoll 10
The minpoll and maxpoll parameters control the minimum and maximum polling intervals (in seconds expressed as a power of 2) between the NTP queries sent to the server(s).
Here’s an example of how a full configuration might look incorporating both tos and minpoll/maxpoll:
# Type of service parameters
tos maxclock 11
tos minclock 4 minsane 3
# Individual servers
server time1.example.com minpoll 6 maxpoll 10 iburst
server time2.example.com minpoll 6 maxpoll 10 iburst
# Pool of servers
pool pool.ntp.org minpoll 6 maxpoll 10 iburst
Explanation:
tos maxclock 11: Use a maximum of 11 servers/peers for synchronization.
tos minclock 4 minsane 3: Require at least 4 servers/peers (minclock) and at least 3 of them to be in agreement (minsane) before considering the time to be synchronized.
server time1.example.com minpoll 6 maxpoll 10 iburst: Configure a specific server with minimum polling interval of 64 seconds (2^6), maximum polling interval of 1024 seconds (2^10), and use the iburst option for faster initial synchronization.
pool pool.ntp.org minpoll 6 maxpoll 10 iburst: Configure a pool of servers with the same polling intervals and iburst option.
So, in short, place the minpoll and maxpoll settings within the server or pool lines. Do not put them in a tos line as it will not work and may result in errors.
Here's how time synchronization and time zone settings typically work together in Linux systems:
System Time and NTPsec:
NTPsec synchronizes the system clock to a highly accurate time source. This synchronization is done in UTC.
The system clock maintains time in UTC, regardless of the local time zone.
Time Zone Configuration:
The time zone configuration determines how the system's local time is displayed to users and applications. This configuration is handled by the operating system, not by NTPsec.
On Linux systems, the local time zone setting is typically managed using the timedatectl utility or by setting symbolic links in /etc:
The local time zone file is usually a symbolic link /etc/localtime pointing to a file in /usr/share/zoneinfo that defines the local time zone rules.
The file /etc/timezone or /etc/localtime contains the name of the configured time zone, such as America/New_York.
Checking and Setting Time Zone with timedatectl
You can check the current time zone setting with:
timedatectl
This will output something like:
Local time: Fri 2023-10-13 12:34:56 EDT
Universal time: Fri 2023-10-13 16:34:56 UTC
RTC time: Fri 2023-10-13 16:34:56
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
You can set the time zone using:
sudo timedatectl set-timezone America/New_York
Summary:
NTPsec synchronizes the system clock to UTC, ensuring high accuracy.
Time zone settings are managed by the operating system, and NTPsec does not interact directly with these settings.
Use timedatectl or appropriate system configuration files to manage and change the local time zone.
By keeping the system clock in UTC and converting to local time as needed, you maintain consistency and avoid issues with time zones, especially when dealing with network-based time synchronization protocols like NTP.
In Linux, the system time is generally maintained in UTC, while conversions to local time are handled according to the configured time zone. However, you can configure your system to store the hardware clock (also known as the Real-Time Clock or RTC) either in UTC or local time. Here’s how you can manage and change these settings:
Using timedatectl
The timedatectl command is a utility provided by systemd for querying and changing the system clock and its settings.
Display Current Settings
You can display the current time settings with:
timedatectl
Setting the System Clock to Use Local Time or UTC
You can specify whether the hardware clock should be kept in local time or UTC. To change this, use the following timedatectl commands:
Set the hardware clock to UTC:
sudo timedatectl set-local-rtc 0
Set the hardware clock to local time:
sudo timedatectl set-local-rtc 1
Manual Configuration
If your system does not use systemd, or if you prefer not to use timedatectl, you can manually set the hardware clock configuration. On many Linux systems, this is controlled by the /etc/adjtime file.
Edit /etc/adjtime
The /etc/adjtime file usually contains something like this:
0.000000 0.000000 0.000000
0
UTC
To set the hardware clock to UTC, ensure the third line reads UTC.
To set the hardware clock to local time, change the third line to LOCAL.
After making the appropriate changes, you may need to update the system clock to reflect these changes. You can synchronize the hardware clock to the system time with:
sudo hwclock --systohc
or set the system time from the hardware clock:
sudo hwclock --hctosys
Summary
Using timedatectl:
To set the hardware clock to UTC: sudo timedatectl set-local-rtc 0
To set the hardware clock to local time: sudo timedatectl set-local-rtc 1
Manual Configuration:
Edit /etc/adjtime and set the last line to UTC or LOCAL.
Synchronize the system and hardware clocks using hwclock.
Note
It is generally recommended to keep the hardware clock in UTC:
Avoids issues with daylight saving time changes.
More consistent across different time zones.
Easier to manage in dual-boot systems with other operating systems, like Windows, which expect the hardware clock to be in local time.
Make sure to reboot or restart the systemd timesyncd service to apply the changes effectively when using these settings.
To list all available time zones, use:
timedatectl list-timezones
This will output a long list of time zones, such as:
Many desktop environments provide graphical tools to manage date and time settings:
GNOME: You can use the "Date & Time" settings accessible from the system settings menu.
KDE Plasma: Similarly, "Date & Time" settings can be accessed from the system settings.
These graphical tools generally provide a user-friendly interface for selecting the time zone from a world map or a list.
Example Workflow with timedatectl
List Time Zones:
timedatectl list-timezones
Set Time Zone:
Suppose you want to set your time zone to America/New_York:
sudo timedatectl set-timezone America/New_York
Confirm the Change:
timedatectl
This will show the current date, time, time zone, and whether the RTC is set to local time or UTC.
Summary
Use timedatectl list-timezones to list available time zones.
Explore /usr/share/zoneinfo to see the time zone files.
Use graphical tools in desktop environments for an easy-to-navigate interface.
After finding the desired time zone, set it using timedatectl set-timezone.
By using these methods, you can easily find and configure the appropriate time zone for your system.
Certainly! Here is a step-by-step breakdown of how a Linux system, configured as you described, gets and sets the correct time based on information from NTP servers and your time zone configuration:
Step-by-Step Process
Hardware Clock (RTC) Configuration:
Your hardware clock is set to UTC, as indicated in /etc/adjtime by the line UTC.
The system reads the hardware clock (RTC) on boot, which is set in UTC.
Time Zone Configuration:
The time zone is specified in /etc/timezone, for example, Europe/London.
The symbolic link /etc/localtime points to the appropriate time zone file in /usr/share/zoneinfo, such as /usr/share/zoneinfo/Europe/London.
NTPsec Service:
Ensure that the NTPsec service (ntpd, provided by ntpsec) is installed and running. This service will synchronize the system clock with NTP servers.
The NTPsec configuration is typically found in /etc/ntpsec/ntp.conf. Make sure it is properly configured to use reliable NTP servers.
Synchronization Process
System Initialization:
When the system boots, the kernel reads the hardware clock (RTC), which is in UTC.
The system clock is set to this value. This initial setting is done by scripts or tools like hwclock.
NTPsec Synchronization:
The NTPsec daemon (ntpd) starts and reads its configuration from /etc/ntpsec/ntp.conf.
It contacts the NTP servers specified in the configuration file to get the accurate current UTC time.
The system clock, which was initially set based on the RTC, is now continuously adjusted and kept accurate by ntpd based on the data from the NTP servers.
Local Time Display:
When you query the current time or when applications request the time, the system converts the UTC time maintained by the kernel to local time based on the time zone information specified by /etc/localtime.
This conversion is handled by the C library (glibc) functions, which read the time zone rules from the file /etc/localtime.
Example Configuration Files
/etc/adjtime
0.000000 0.000000 0.000000
0
UTC
This indicates that the hardware clock is in UTC.
/etc/timezone
Europe/London
This specifies the local time zone.
Ensure /etc/localtime Link
Make sure /etc/localtime is correctly linked to your time zone file:
# Basic NTP configuration example
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst
# Additional options could go here
driftfile /var/lib/ntpsec/ntp.drift
Use ntpq -p to see the status of your NTP peers and ensure synchronization:
ntpq -p
Verify Time Zone and System Time:
Use timedatectl to verify that everything is set correctly:
timedatectl
This command should show you the local time, UTC time, time zone, and NTP synchronization status.
Summary
By following these steps, your Linux system:
Reads the hardware clock in UTC.
Sets the system clock in UTC at boot time.
Uses NTPsec to synchronize the system clock with NTP servers continuously.
Converts UTC to your local time zone for display and application use, based on /etc/localtime.
This ensures that your system time is accurate and correctly reflects your local time zone settings.
On a Linux system, you can prevent the system from updating the hardware clock (RTC) with the system time by controlling how and when hwclock --systohc or equivalent commands are executed. By default, certain services and scripts may synchronize the system time to the hardware clock during shutdown or at regular intervals. To prevent this, follow these steps:
1. Disable Automatic Sync at Shutdown
Depending on your Linux distribution and init system, there might be a service that updates the hardware clock at shutdown. You can disable this service.
For systemd-based Systems
Check for systemd-timesyncd service:
Normally, systemd-timesyncd handles NTP synchronization. If disabled, ensure no other service handles system to hardware clock sync.
sudo systemctl disable systemd-timesyncd
Check for hwclock Service:
Check if a service like hwclock-set is active. It can be part of initramfs or shutdown scripts.
sudo systemctl list-unit-files | grep hwclock
If you find relevant services or timer units (like hwclock-save.service), you can disable them:
sudo systemctl disable hwclock-save.service
Disable persistent hardware clock updates in RTC settings:
Modify /etc/adjtime if there’s a line indicating the system should set the hardware clock:
sudo nano /etc/adjtime
Change any settings indicating LOCAL if you strictly follow UTC:
0.000000 0.000000 0.000000
0
UTC
2. Modify Shutdown Scripts
For non-systemd systems or custom setups, you might need to modify shutdown scripts located in /etc/init.d/, /etc/rc.d/, or other relevant directories.
Example for Debian/Ubuntu (systemd-shim):
In Debian-based systems running with systemd-shim, you might alter /etc/init.d/hwclock.sh.
Identify Shutdown Process:
sudo nano /etc/init.d/hwclock.sh
Comment Out or Remove Sync Commands:
You can comment out the lines responsible for writing system time to the hardware clock:
# Save system time to hardware clock.
# /sbin/hwclock --systohc $NOSYNC
3. Ensure Configuration Consistency
Post changes, reboot the system to ensure they are loaded correctly. You can verify that the hardware clock isn’t updated with the system time via:
sudo hwclock --show
Compare it with your system clock using:
date
They should show visible differences if the hardware clock isn’t updated.
You ensure your Linux system will not update the hardware clock during routine operations like shutdown or system updates. This is crucial for maintaining hardware clock integrity for specific scenarios where UTC precision is paramount.