Skip to content

27. Time Sync & Network Services

Production servers rely on essential network services to coordinate state, share files, synchronize timestamps, and replicate data across distributed systems. In distributed databases (Cassandra, etcd, CockroachDB) and security protocols (Kerberos, TLS certificates, token authentication), a clock drift of even a few seconds will cause cluster failure or invalid token rejections.

This chapter covers Time Synchronization, core Network File Sharing Services (NFS, Samba, rsync), Mail Relay basics, and DHCP Server Administration.

27.1 Clocks: System Clock vs Hardware Clock

Section titled “27.1 Clocks: System Clock vs Hardware Clock”

Linux systems maintain two separate clocks:

  1. Hardware Clock (Real-Time Clock / RTC): A battery-backed chip on the physical motherboard that tracks time even when the machine is powered off.
  2. System Clock (Software Clock): Managed by the Linux kernel. When the machine boots, the kernel reads the hardware clock to initialize the system clock, and then ticks independently based on CPU timer interrupts.
Terminal window
# Read hardware clock directly
sudo hwclock --show
# Sync system clock to hardware clock
sudo hwclock --systohc
# Sync hardware clock to system clock
sudo hwclock --hctosys

27.2 Managing Time & Timezones: timedatectl

Section titled “27.2 Managing Time & Timezones: timedatectl”

timedatectl (part of systemd) is the modern tool to inspect and adjust the system clock, RTC, and timezones.

Terminal window
# Check current time status, timezone, and NTP sync status
timedatectl status

Example output:

Local time: Sat 2026-10-03 16:05:12 UTC
Universal time: Sat 2026-10-03 16:05:12 UTC
RTC time: Sat 2026-10-03 16:05:12
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Terminal window
# List available timezones
timedatectl list-timezones | grep -i new_york
# Set system timezone (Always use UTC in cloud production!)
sudo timedatectl set-timezone UTC
# Enable or disable network time synchronization (NTP)
sudo timedatectl set-ntp true

[!TIP] Production Best Practice: Always set server operating systems and database timestamps to UTC. Never configure servers to local daylight-saving time zones; convert timestamps to local user time only in the UI/client layer.

NTP (Network Time Protocol) is the networking protocol used to synchronize clocks over variable-latency packet-switched networks.

In modern Linux distributions (RHEL, Ubuntu, Debian), Chrony has replaced the older ntpd daemon because it synchronizes much faster, handles intermittent connections, and maintains accuracy in virtualized environments with unstable clock frequencies.

  • Ubuntu / Debian:
    Terminal window
    sudo apt install chrony -y
    sudo systemctl enable --now chrony
  • RHEL / AlmaLinux / Rocky:
    Terminal window
    sudo dnf install chrony -y
    sudo systemctl enable --now chronyd

Configuring Chrony (/etc/chrony/chrony.conf or /etc/chrony.conf)

Section titled “Configuring Chrony (/etc/chrony/chrony.conf or /etc/chrony.conf)”
# Use public NTP pool servers
pool pool.ntp.org iburst
# In private cloud VPCs, use cloud provider local time servers (near 0ms latency):
# AWS:
# server 169.254.169.123 prefer iburst
# Google Cloud:
# server metadata.google.internal prefer iburst
# Record drift rate in driftfile
driftfile /var/lib/chrony/drift
# Allow the system clock to be stepped in the first 3 updates if offset > 1 sec
makestep 1.0 3
# Log tracking measurements
logdir /var/log/chrony

Verification & Troubleshooting with chronyc

Section titled “Verification & Troubleshooting with chronyc”
Terminal window
# View active NTP sources and offset/jitter
chronyc sources -v
# View tracking statistics (stratum, reference ID, system time offset)
chronyc tracking

When multiple application nodes need concurrent access to a shared directory (e.g., shared user uploads, persistent media storage), network file shares are used. NFS is the native Unix/Linux network file sharing protocol. It allows remote clients to mount a server directory over the network as if it were a local filesystem.

  1. Install NFS server packages:
    Terminal window
    sudo apt install nfs-kernel-server -y # Debian/Ubuntu
    # or
    sudo dnf install nfs-utils -y # RHEL/Alma
  2. Create the export directory:
    Terminal window
    sudo mkdir -p /srv/nfs/shared_data
    sudo chown nobody:nogroup /srv/nfs/shared_data # or nfsnobody on RHEL
    sudo chmod 777 /srv/nfs/shared_data
  3. Define exports in /etc/exports:
    # Export to 192.168.1.0/24 subnet with Read/Write, Sync, and No Root Squash
    /srv/nfs/shared_data 192.168.1.0/24(rw,sync,no_subtree_check,no_root_squash)
    • rw: Read and write access.
    • sync: Changes are committed to disk before responding (prevents data corruption).
    • no_root_squash: Allows client root users to operate as root on the export (use with caution).
  4. Apply exports and start service:
    Terminal window
    sudo exportfs -rav
    sudo systemctl restart nfs-kernel-server # or nfs-server on RHEL
Terminal window
# Install client package
sudo apt install nfs-common -y # or dnf install nfs-utils
# Temporary mount
sudo mkdir -p /mnt/nfs_share
sudo mount -t nfs 192.168.1.10:/srv/nfs/shared_data /mnt/nfs_share
# Permanent mount in /etc/fstab:
# 192.168.1.10:/srv/nfs/shared_data /mnt/nfs_share nfs defaults,_netdev 0 0

[!IMPORTANT] The _netdev mount option in /etc/fstab instructs Linux to wait until the network interface is online before attempting to mount the share during boot.

Samba implements the SMB (Server Message Block) protocol, enabling file and print sharing across Linux, Windows, and macOS with Active Directory / user-level authentication.

Terminal window
sudo apt install samba -y # or dnf install samba

Add share definition to /etc/samba/smb.conf:

[corp_share]
path = /data/samba/corp
browsable = yes
writable = yes
valid users = @devops
create mask = 0660
directory mask = 0770

Create Samba user and password (separate from Linux shell password):

Terminal window
sudo smbpasswd -a alice
sudo systemctl restart smbd

rsync (Remote Sync) is the industry standard for backing up and mirroring files locally or across the network.

  • Delta-Transfer Algorithm: Only transfers the differences (changed bytes) between files rather than copying entire files again.
  • Resumable: Can pick up interrupted transfers.
  • Preserves Metadata: Preserves permissions, timestamps, symlinks, and ownership.
  • -a (Archive mode): Equivalent to -rlptgoD (recursive, copy symlinks, preserve permissions, times, owner, group).
  • -v (Verbose): Prints file transfer progress.
  • -z (Compress): Compresses data during transit over network.
  • -P: Shows progress bar and keeps partially transferred files (--partial --progress).
  • --delete: Deletes files in the destination that no longer exist in the source (true mirror).
Terminal window
# Local directory backup
rsync -avP /var/www/html/ /backups/html/
# Sync to a remote server over SSH
rsync -avzP -e 'ssh -p 2222' /opt/data/ deploy@192.168.1.50:/opt/data/
# Perfect mirror (deletes extraneous files on remote) with dry-run test (-n)
rsync -avzP --delete -n /source/ user@remote:/dest/

[!WARNING] The Trailing Slash Rule:

  • rsync -a /src/ /dest/ copies the contents of /src into /dest.
  • rsync -a /src /dest/ copies the directory itself, resulting in /dest/src/.

Even in the cloud era, Linux servers must send automated email notifications (cron failure alerts, security warnings from fail2ban or logwatch, monitoring alerts).

  • MUA (Mail User Agent): The client program used to read/send mail (e.g., mail, mutt, Thunderbird).
  • MTA (Mail Transfer Agent): The server daemon responsible for routing and sending email via SMTP (Port 25 or 587) (e.g., Postfix, Sendmail, Exim).
  • MDA (Mail Delivery Agent): Delivers incoming email to the user’s local mailbox (e.g., Dovecot).

Postfix as a Local Satellite / Relay Agent

Section titled “Postfix as a Local Satellite / Relay Agent”

To prevent your cloud server IP from being blacklisted for spam, configure Postfix as a relay host to forward outgoing mail through an authorized transactional provider (SendGrid, AWS SES, Mailgun).

  1. Install Postfix:
    Terminal window
    sudo apt install postfix mailutils -y # or dnf install postfix
  2. Configure /etc/postfix/main.cf:
    myhostname = srv01.example.com
    relayhost = [smtp.sendgrid.net]:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_tls_security_level = encrypt
  3. Test sending an email:
    Terminal window
    echo "Disk full on srv01" | mail -s "ALERT: Disk Space Warning" admin@example.com

DHCP (Dynamic Host Configuration Protocol) automates the assignment of IP addresses, subnet masks, default gateways, DNS servers, NTP servers, and domain suffixes to network clients. Without DHCP, each host must be manually configured with static network parameters.

DHCP uses a four-step handshake over UDP ports 67 (server) and 68 (client):

Client (Port 68) Server (Port 67)
│ │
│─────── 1. DHCPDISCOVER (Broadcast) ───────────►│ (0.0.0.0:68 -> 255.255.255.255:67)
│ │
│◄────── 2. DHCPOFFER (Unicast/Broadcast) ───────│ (Offers IP, subnet mask, lease)
│ │
│─────── 3. DHCPREQUEST (Broadcast) ────────────►│ (Confirms accepted offer to all servers)
│ │
│◄────── 4. DHCPACK (Unicast/Broadcast) ─────────│ (Acknowledges and finalizes parameters)
│ │
  1. DHCPDISCOVER: The client boots up without an IP. It broadcasts a discover message looking for available DHCP servers on the local broadcast domain (255.255.255.255).
  2. DHCPOFFER: Any listening DHCP server reserves an IP from its pool and sends back an offer containing the proposed IP, subnet mask, lease duration, and server identifier.
  3. DHCPREQUEST: The client accepts one offer (usually the first received) and broadcasts a request message indicating the chosen IP and server, notifying other DHCP servers to release their reserved offers.
  4. DHCPACK: The server acknowledges the request, commits the lease to /var/lib/dhcpd/dhcpd.leases, and delivers configuration parameters (default gateway, DNS, domain name).
  • T1 Timer (Renewal - 50% of lease): Client attempts unicast DHCPREQUEST directly to the issuing server to extend its lease.
  • T2 Timer (Rebinding - 87.5% of lease): If the original server does not answer, the client broadcasts DHCPREQUEST to any reachable DHCP server on the segment.
  • Lease Expiration (100%): If no server responds, the client drops the IP address immediately and restarts the full DORA sequence.

| Distribution | Package Name | Service Name | Configuration File | ||||| | RHEL / Rocky / AlmaLinux | dhcp-server | dhcpd | /etc/dhcp/dhcpd.conf | | Ubuntu / Debian | isc-dhcp-server | isc-dhcp-server | /etc/dhcp/dhcpd.conf |

Terminal window
# RHEL / Rocky / AlmaLinux 8 & 9
sudo dnf install dhcp-server -y
# Ubuntu / Debian
sudo apt update
sudo apt install isc-dhcp-server -y

DHCP servers should only listen on designated internal/LAN interfaces to avoid conflicting with external networks or cloud VPC gateways.

  • RHEL / AlmaLinux / Rocky (/etc/sysconfig/dhcpd):
    Terminal window
    DHCPDARGS="eth1"
  • Ubuntu / Debian (/etc/default/isc-dhcp-server):
    Terminal window
    INTERFACESv4="eth1"
    INTERFACESv6=""

DHCP Server Configuration (/etc/dhcp/dhcpd.conf)

Section titled “DHCP Server Configuration (/etc/dhcp/dhcpd.conf)”

Here is an enterprise production configuration demonstrating global options, subnet pools, dynamic ranges, and static MAC-based IP reservations:

/etc/dhcp/dhcpd.conf
# Global parameters applied across all subnets
option domain-name "corp.internal";
option domain-name-servers 192.168.10.10, 1.1.1.1;
default-lease-time 86400; # 24 hours in seconds
max-lease-time 172800; # 48 hours maximum
# Declare authoritative server for this network
authoritative;
# Log facility for rsyslog tracking
log-facility local7;
# Dynamic Pool Subnet Definition
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200;
option routers 192.168.10.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.10.255;
option ntp-servers 192.168.10.5;
}
# Static IP Reservation by MAC Address
# Ideal for critical infrastructure (printers, VoIP phones, IPMI/iDRAC)
host storage01 {
hardware ethernet 00:1a:2b:3c:4d:5e;
fixed-address 192.168.10.20;
option host-name "storage01.corp.internal";
}
host prod-printer01 {
hardware ethernet 52:54:00:12:34:56;
fixed-address 192.168.10.25;
}

Always validate configuration syntax before starting or reloading the daemon:

Terminal window
# Validate configuration syntax
sudo dhcpd -t -cf /etc/dhcp/dhcpd.conf
# Start and enable the service
# On RHEL:
sudo systemctl enable --now dhcpd
sudo systemctl status dhcpd
# On Ubuntu:
sudo systemctl enable --now isc-dhcp-server
sudo systemctl status isc-dhcp-server

Open UDP port 67 on the server firewall:

Terminal window
# Firewalld (RHEL / Rocky / AlmaLinux)
sudo firewall-cmd --permanent --add-service=dhcp
sudo firewall-cmd --reload
# UFW (Ubuntu / Debian)
sudo ufw allow 67/udp comment "DHCP Server"
sudo ufw status

Inspecting Active Leases and Client Operations

Section titled “Inspecting Active Leases and Client Operations”

The server tracks active bindings, expiration timestamps, and client hardware MAC addresses in the lease database:

Terminal window
# View active leases on RHEL:
cat /var/lib/dhcpd/dhcpd.leases
# View active leases on Ubuntu:
cat /var/lib/dhcp/dhcpd.leases

Example lease record:

lease 192.168.10.145 {
starts 2 2026/10/15 08:30:00;
ends 3 2026/10/16 08:30:00;
tstp 3 2026/10/16 08:30:00;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:4f:8e:33;
client-hostname "workstation-07";
}

On client Linux nodes, you can force release or renewal using dhclient:

Terminal window
# Release current IP lease
sudo dhclient -r -v eth0
# Request a new lease from DHCP
sudo dhclient -v eth0
# Check assigned IP and gateway
ip route show default
ip -br addr show eth0

[!WARNING] Rogue DHCP Server Risks: A rogue or misconfigured DHCP server connected to an enterprise switch segment can broadcast fraudulent default gateways (Man-In-The-Middle attacks) or hand out invalid IP ranges. Enterprise managed switches must be configured with DHCP Snooping on non-trunk client ports to block unauthorized DHCPOFFER and DHCPACK packets.