Sub topic 11
Time Sync and Host Identity
This chapter assumes that you can use the Linux command line, run commands with sudo, inspect systemd units, and understand basic hostnames and TCP networking.
Central logging depends on two kinds of consistency:
- Time consistency: events from different servers must use clocks that are close enough for their order to make sense.
- Identity consistency: every message must clearly identify the server that produced it.
Without these, an incident can appear to happen in the wrong order or appear to come from the wrong machine.
Synchronizing server clocks
A server clock is maintained by a time synchronization service. Common Linux choices include chrony and systemd-timesyncd. The Network Time Protocol (NTP) lets a host compare its clock with trusted time servers and gradually correct the difference.
A clock difference is called clock skew. Even a few minutes of skew can make authentication failures, outages, and log events difficult to correlate. Use Coordinated Universal Time (UTC) for stored and transmitted timestamps. Convert to local time only when presenting results to people.
Check the current clock state with:
timedatectl
chronyc tracking
chronyc sources -vtimedatectl shows whether the system clock is synchronized. chronyc tracking reports the estimated offset from the reference clock. chronyc sources -v shows the time sources that chrony can use.
Configure all servers to use the same approved time sources. An internal time server is often preferable because it gives the whole environment one reference and reduces dependence on external services. Allow NTP traffic, normally UDP port 123, only where required.
Preserving host identity
A hostname is the name assigned to a machine. A fully qualified domain name (FQDN) includes the host and its DNS domain, such as web-01.example.com.
Set a stable hostname on each server:
sudo hostnamectl set-hostname web-01.example.com
hostnamectl --static
getent hosts web-01.example.comThe name must resolve consistently in DNS or in /etc/hosts. Forward and reverse DNS should agree where possible. Avoid names that change when a server receives a new address, because changing names can split one machine's logs across several identities.
Rsyslog commonly uses the message hostname in a file template such as %HOSTNAME%. The receiver may therefore create separate directories for web-01.example.com, web-01, and an IP address if clients identify themselves inconsistently.
| Problem | Result | Prevention |
|---|---|---|
| Clock skew | Events appear out of order | Synchronize with chrony or another approved NTP service |
| Changing hostname | One server's logs are split | Use a stable FQDN |
| Missing DNS record | Receiver cannot resolve the sender | Maintain forward and reverse records |
| Duplicate hostname | Logs from two servers are mixed | Enforce unique hostnames |
How time and identity work together
A synchronized clock makes timestamps comparable. A stable hostname lets the receiver place each message in the correct per-host destination. Both should be checked before investigating forwarding failures.
Exercise
A central receiver has files for both db-01 and 10.20.4.18, but both names refer to one server. What should you check first?
Show answer
Check the client's hostname configuration, DNS records, and rsyslog identity settings. Make the client use one stable FQDN, then verify that new messages consistently use that name.