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:
- Hardware Clock (Real-Time Clock / RTC): A battery-backed chip on the physical motherboard that tracks time even when the machine is powered off.
- 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.
# Read hardware clock directlysudo hwclock --show
# Sync system clock to hardware clocksudo hwclock --systohc
# Sync hardware clock to system clocksudo hwclock --hctosys27.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.
# Check current time status, timezone, and NTP sync statustimedatectl statusExample 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# List available timezonestimedatectl 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.
27.3 NTP & Chrony
Section titled “27.3 NTP & Chrony”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.
Installing Chrony
Section titled “Installing Chrony”- Ubuntu / Debian:
Terminal window sudo apt install chrony -ysudo systemctl enable --now chrony - RHEL / AlmaLinux / Rocky:
Terminal window sudo dnf install chrony -ysudo 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 serverspool 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 driftfiledriftfile /var/lib/chrony/drift
# Allow the system clock to be stepped in the first 3 updates if offset > 1 secmakestep 1.0 3
# Log tracking measurementslogdir /var/log/chronyVerification & Troubleshooting with chronyc
Section titled “Verification & Troubleshooting with chronyc”# View active NTP sources and offset/jitterchronyc sources -v
# View tracking statistics (stratum, reference ID, system time offset)chronyc tracking27.4 NFS File Sharing
Section titled “27.4 NFS File Sharing”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.
Setting up an NFS Server
Section titled “Setting up an NFS Server”- Install NFS server packages:
Terminal window sudo apt install nfs-kernel-server -y # Debian/Ubuntu# orsudo dnf install nfs-utils -y # RHEL/Alma - Create the export directory:
Terminal window sudo mkdir -p /srv/nfs/shared_datasudo chown nobody:nogroup /srv/nfs/shared_data # or nfsnobody on RHELsudo chmod 777 /srv/nfs/shared_data - 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).
- Apply exports and start service:
Terminal window sudo exportfs -ravsudo systemctl restart nfs-kernel-server # or nfs-server on RHEL
Mounting NFS on Client Machines
Section titled “Mounting NFS on Client Machines”# Install client packagesudo apt install nfs-common -y # or dnf install nfs-utils
# Temporary mountsudo mkdir -p /mnt/nfs_sharesudo 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
_netdevmount option in/etc/fstabinstructs Linux to wait until the network interface is online before attempting to mount the share during boot.
27.5 Samba (SMB/CIFS)
Section titled “27.5 Samba (SMB/CIFS)”Samba implements the SMB (Server Message Block) protocol, enabling file and print sharing across Linux, Windows, and macOS with Active Directory / user-level authentication.
Quick Setup (/etc/samba/smb.conf)
Section titled “Quick Setup (/etc/samba/smb.conf)”sudo apt install samba -y # or dnf install sambaAdd 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 = 0770Create Samba user and password (separate from Linux shell password):
sudo smbpasswd -a alicesudo systemctl restart smbd27.6 High-Performance Data Sync (rsync)
Section titled “27.6 High-Performance Data Sync (rsync)”rsync (Remote Sync) is the industry standard for backing up and mirroring files locally or across the network.
Why rsync is Better Than cp or scp
Section titled “Why rsync is Better Than cp or scp”- 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.
Essential rsync Flags
Section titled “Essential rsync Flags”-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).
Common Production Commands
Section titled “Common Production Commands”# Local directory backuprsync -avP /var/www/html/ /backups/html/
# Sync to a remote server over SSHrsync -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/srcinto/dest.rsync -a /src /dest/copies the directory itself, resulting in/dest/src/.
27.7 Mail (SMTP & Postfix)
Section titled “27.7 Mail (SMTP & Postfix)”Even in the cloud era, Linux servers must send automated email notifications (cron failure alerts, security warnings from fail2ban or logwatch, monitoring alerts).
Core Mail Terminology
Section titled “Core Mail Terminology”- 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).
- Install Postfix:
Terminal window sudo apt install postfix mailutils -y # or dnf install postfix - Configure
/etc/postfix/main.cf:myhostname = srv01.example.comrelayhost = [smtp.sendgrid.net]:587smtp_sasl_auth_enable = yessmtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdsmtp_sasl_security_options = noanonymoussmtp_tls_security_level = encrypt - Test sending an email:
Terminal window echo "Disk full on srv01" | mail -s "ALERT: Disk Space Warning" admin@example.com
27.8 DHCP Server Administration
Section titled “27.8 DHCP Server Administration”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.
The DORA Process
Section titled “The DORA Process”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) │ │- 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). - 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.
- 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.
- DHCPACK: The server acknowledges the request, commits the lease to
/var/lib/dhcpd/dhcpd.leases, and delivers configuration parameters (default gateway, DNS, domain name).
Lease Timers and Renewal
Section titled “Lease Timers and Renewal”- T1 Timer (Renewal - 50% of lease): Client attempts unicast
DHCPREQUESTdirectly 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
DHCPREQUESTto 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.
Installing ISC DHCP Server
Section titled “Installing ISC DHCP Server”| 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 |
Installation Commands
Section titled “Installation Commands”# RHEL / Rocky / AlmaLinux 8 & 9sudo dnf install dhcp-server -y
# Ubuntu / Debiansudo apt updatesudo apt install isc-dhcp-server -yBinding DHCP to Network Interfaces
Section titled “Binding DHCP to Network Interfaces”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:
# Global parameters applied across all subnetsoption domain-name "corp.internal";option domain-name-servers 192.168.10.10, 1.1.1.1;default-lease-time 86400; # 24 hours in secondsmax-lease-time 172800; # 48 hours maximum
# Declare authoritative server for this networkauthoritative;
# Log facility for rsyslog trackinglog-facility local7;
# Dynamic Pool Subnet Definitionsubnet 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;}Validating, Starting, and Managing DHCP
Section titled “Validating, Starting, and Managing DHCP”Always validate configuration syntax before starting or reloading the daemon:
# Validate configuration syntaxsudo dhcpd -t -cf /etc/dhcp/dhcpd.conf
# Start and enable the service# On RHEL:sudo systemctl enable --now dhcpdsudo systemctl status dhcpd
# On Ubuntu:sudo systemctl enable --now isc-dhcp-serversudo systemctl status isc-dhcp-serverFirewall Rules
Section titled “Firewall Rules”Open UDP port 67 on the server firewall:
# Firewalld (RHEL / Rocky / AlmaLinux)sudo firewall-cmd --permanent --add-service=dhcpsudo firewall-cmd --reload
# UFW (Ubuntu / Debian)sudo ufw allow 67/udp comment "DHCP Server"sudo ufw statusInspecting Active Leases and Client Operations
Section titled “Inspecting Active Leases and Client Operations”Viewing Active Leases
Section titled “Viewing Active Leases”The server tracks active bindings, expiration timestamps, and client hardware MAC addresses in the lease database:
# View active leases on RHEL:cat /var/lib/dhcpd/dhcpd.leases
# View active leases on Ubuntu:cat /var/lib/dhcp/dhcpd.leasesExample 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";}Client Verification and Release Commands
Section titled “Client Verification and Release Commands”On client Linux nodes, you can force release or renewal using dhclient:
# Release current IP leasesudo dhclient -r -v eth0
# Request a new lease from DHCPsudo dhclient -v eth0
# Check assigned IP and gatewayip route show defaultip -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
DHCPOFFERandDHCPACKpackets.