📘 Visual Posts About Contact
Explore 📋 Cheat Sheets ✏️ Practice 🎮 Games 🎬 Simulations 🃏 Flashcards 🎯 Interactive Layers 📖 Storytelling
💜 Support my site
Module 16 · A-to-Z Server Course Core Infrastructure

Email, NTP Time Sync & Centralized Logging

Every production server fleet relies on three quiet infrastructure pillars: Email to deliver alerts and messages reliably, NTP so every machine agrees on the exact millisecond, and Centralized Logs so evidence survives crashes and attacks.

Start Module 16 →
Production Server app-01.prod.internal Email & Trust SMTP 587/25 · SPF/DKIM/DMARC NTP Time Sync (chrony) UDP 123 · ±0.5ms drift Centralized Logs rsyslog · SIEM · Loki

01 How Email Servers Work (SMTP vs IMAP)

Define: Email does not travel directly from your laptop to your friend's phone. Instead, specialized servers pass the message along using two completely different jobs: SMTP (Simple Mail Transfer Protocol) for sending and relaying, and IMAP (Internet Message Access Protocol) for reading and organizing your inbox.

Analogy — The Post Office & Your Letterbox:
Think of SMTP as the postal trucks and sorting hubs that carry a letter from your local postbox to the recipient's town post office. Think of IMAP as the key to your personal P.O. Box—you unlock it from your phone or laptop to read, star, or delete mail while keeping everything synced on the server.

Understand: The 3 Ports Every Admin Must Know

587

SMTP Submission (STARTTLS)

Used by mail clients & apps (Outlook, Thunderbird, web apps) to hand an outgoing email to your own mail server after logging in with a username and password.

25

SMTP Server-to-Server Relay

Used only between mail servers (e.g., your Postfix server talking to Gmail's MX server). Cloud providers often block outbound Port 25 by default to stop spam.

993

IMAPS (Encrypted Mailbox)

Used by your phone or laptop to read and sync your inbox over TLS encryption. Legacy unencrypted IMAP (143) and POP3 (110) are avoided in modern setups.

End-to-End Email Delivery Flow Sender Client [email protected] MUA (App) 587 Submit Sender MTA mail.acme.io Postfix DNS MX Lookup 25 Relay Recipient Server mx.example.com MTA + Dovecot 993 IMAPS Bob Reads Mail Key Rule: Users submit mail on Port 587 and read mail on Port 993. Only Mail Transfer Agents (MTAs) talk to each other over Port 25 after checking DNS MX records.

Know, When & Execute

  • Know: MUA (Mail User Agent = Thunderbird/Outlook) talks to MTA (Mail Transfer Agent = Postfix/Exchange) on Port 587. MDA (Mail Delivery Agent = Dovecot) stores messages so users can fetch them via IMAPS 993.
  • When to self-host vs relay: Most application servers do not run a full inbox server. Instead, they send alerts/receipts through an authenticated SMTP relay (e.g., Postmark, SES, or corporate relay) on Port 587 so messages don't land in spam.
  • Execute: Never leave Port 25 open as an "open relay" (accepting mail from anyone to anywhere)—spammers will find it within minutes and get your server IP blacklisted.

Memory Trick: "5-8-7 Sends It Great, 2-5 Server Drive, 9-9-3 Read for Me"

587 = User submits outgoing mail. 25 = Server-to-server highway. 993 = Encrypted IMAP reading.

02 Email Trust: SPF, DKIM & DMARC

Define: By default, SMTP lets anyone write From: [email protected] on an envelope—just like writing a fake return address on a paper letter. To stop phishing and spoofing, email relies on three DNS-backed security layers: SPF, DKIM, and DMARC.

Analogy — ID Badge, Wax Seal & Building Guard:
1. SPF (ID Badge List): A public guest list in DNS stating which server IPs are allowed to carry mail for your domain.
2. DKIM (Tamper-Proof Wax Seal): A cryptographic signature stamped on the email headers and body so nobody can alter the message in transit.
3. DMARC (Guard Policy): Instructions telling the receiving mail server what to do if SPF and DKIM fail—monitor (p=none), quarantine to spam (p=quarantine), or block (p=reject).
The Email Trust Trio: How Receiving Servers Verify Mail 1. SPF (ID Badge) Checks Sender IP vs DNS TXT v=spf1 ip4:203.0.113.5 -all Stops unauthorized servers from sending as your domain 2. DKIM (Wax Seal) Verifies Crypto Signature Private Key signs mail Public Key in DNS TXT Proves body & headers were not tampered with in transit 3. DMARC (Guard Policy) Alignment + Action Rule v=DMARC1; p=reject; rua=mailto:dmarc@... Rejects fakes & sends XML reports back to domain owner PASS (SPF or DKIM aligned) → Delivered to Inbox FAIL (Both unaligned) → Quarantined to Spam or Rejected
Mechanism DNS Record Location What It Proves
SPF yourdomain.com (TXT) The sending server's IP address is authorized by the domain owner.
DKIM selector._domainkey.yourdomain.com (TXT) The email was cryptographically signed by the domain and wasn't altered.
DMARC _dmarc.yourdomain.com (TXT) The visible From: header matches SPF/DKIM, plus what to do on failure.

Checkpoint: Email Delivery & Trust

  • Do you know why Port 587 is for clients while Port 25 is for server-to-server relay?
  • Can you explain how SPF (IP list), DKIM (signature), and DMARC (policy) work together?

03 Why Time Sync (NTP / chrony) Is Critical

Define: NTP (Network Time Protocol, UDP Port 123) keeps every server's clock synchronized to atomic time within milliseconds. On modern Linux systems, the default NTP daemon is chrony (replacing the older ntpd), while Windows domains use W32Time.

Why Clock Drift Causes Silent Outages:
Computer clocks naturally drift by several seconds per week. If your servers disagree on the current time by even a few minutes, critical security systems break immediately:
  • Kerberos / Active Directory Auth Fails: Kerberos tickets have a strict 5-minute skew limit. If a server's clock drifts more than 5 minutes, users get locked out with cryptic authentication errors.
  • TLS / HTTPS Certificates Look Expired or "Not Yet Valid": A server with the wrong year or day will reject valid SSL/TLS certificates, breaking APIs and databases.
  • Distributed Log Correlation Becomes Impossible: When debugging a crash across 5 servers, out-of-order timestamps make it look like the database crashed before the user even clicked the button.
NTP Stratum Hierarchy & Why Milliseconds Matter Stratum 0: Atomic / GPS Clocks Reference Hardware Stratum 1: Primary Time Servers time.cloudflare.com · pool.ntp.org Web Server (chrony) Stratum 2 · +0.3ms Auth / AD (Kerberos) Stratum 2 · +0.1ms Database Server Stratum 2 · +0.4ms Always store server clocks in UTC! Local timezones belong only in the user's browser or dashboard.

Know & Execute: Smooth Slewing vs Stepping

If a clock is slightly off, chrony gently speeds up or slows down the clock (slewing) so running databases never see time jump backward. It also logs in UTC (Coordinated Universal Time) so Daylight Saving Time never creates duplicate or missing hours in your logs.

04 Centralized Logging (rsyslog, SIEM & Loki)

Define: By default, Linux servers write logs locally to /var/log/ and journald. Centralized logging streams those logs in real time over the network to a dedicated, tamper-resistant log server (such as a Syslog collector, a SIEM like Wazuh/Elastic, or Grafana Loki).

Analogy — An Airplane's Black Box Flight Recorder:
If a plane crashes, investigators don't rely on a sticky note taped to the cockpit window—they recover the hardened black box. Similarly, if a server's hard drive dies or an attacker runs rm -rf /var/log/* to cover their tracks, your centralized log server still holds every login, firewall block, and crash message safely off-box.
Centralized Logging: Shipping Logs Off-Box in Real Time Web Server (Nginx) rsyslog / Promtail Auth / SSH Host /var/log/auth.log Database Server journald → forward TLS 6514 Central Log Hub rsyslog / Loki / SIEM Append-Only Storage UTC Timestamps Fast Search 1 query across 50 hosts SIEM Alerts Brute-force / 500 errors

Comparing Common Logging Tools

SYS

rsyslog (Classic)

Built into almost every Linux distro. Forwards system logs over TCP/TLS (Port 6514) or UDP (Port 514) with minimal CPU overhead.

LOKI

Grafana Loki

Modern cloud-native log aggregator. Indexes only labels (like host and service), making it fast and cheap to store.

SIEM

SIEM (Wazuh / Elastic)

Combines centralized logs with security rules—automatically alerting on failed SSH logins, sudo abuse, or malware indicators.

05 Practical Verification Commands

Never assume email trust, time sync, or logging is working—verify all three from the terminal in under 60 seconds.

# 1. Verify Email Trust Records (SPF & DMARC) via DNS
dig +short TXT example.com
# Expected: "v=spf1 include:_spf.example.com -all"

dig +short TXT _dmarc.example.com
# Expected: "v=DMARC1; p=reject; rua=mailto:[email protected]"

# 2. Verify NTP Time Sync with chrony
chronyc tracking
# Check: "System time : 0.000124 seconds fast of NTP time"
# Check: "Leap status : Normal"

chronyc sources -v
# Look for "^*" next to your active upstream NTP server

# 3. Test Centralized Logging Pipeline End-to-End
logger -p user.notice "SHEKHARIT-LOG-TEST: verifying rsyslog forwarding"
tail -n 5 /var/log/syslog   # Confirm local write, then search your Central Log Server

Practice Scenario: Troubleshooting a Mysterious Morning Outage

Users report they cannot log in to an internal web app at 09:05 AM. You run chronyc tracking on the web server and see: System time : 412.500 seconds slow of NTP time. Meanwhile, no logs appear in your central SIEM for that server. What are the two most likely root causes?

Show Solution

1. Clock Skew Exceeded 5 Minutes (412.5s > 300s): Kerberos / token authentication and TLS validation reject requests when clocks drift more than 5 minutes. Fix by ensuring chronyd is running and UDP Port 123 outbound is allowed.

2. Log Forwarding Blocked or Failing: Either rsyslog/Promtail stopped, or the firewall is blocking outbound Port 6514 (TLS Syslog). Also note that even if logs arrived, a 412-second clock offset would sort them in the wrong order until NTP is fixed!

✓ Knowledge Check

Test your mastery of Email, NTP & Centralized Logging: Score: 0 / 4

1. Which port should a web application or mail client use to submit outgoing email to its own mail server with authentication?

Port 25 (SMTP Relay)❌
Port 587 (SMTP Submission)✅
Port 993 (IMAPS)❌

2. Which DNS-based email control attaches a cryptographic signature to prove an email was not altered in transit?

SPF (Sender Policy Framework)❌
DKIM (DomainKeys Identified Mail)✅
DMARC❌

3. Why does a 7-minute clock drift on an application server cause sudden login failures in an Active Directory / Kerberos environment?

Kerberos rejects tickets when clock skew exceeds 5 minutes✅
Because chrony shuts down the network card after 5 minutes❌
Because UTC timezones are incompatible with Kerberos❌

4. What is the biggest security advantage of shipping logs off-box to a centralized collector (rsyslog, SIEM, or Loki)?

It automatically encrypts all local user home directories❌
It eliminates the need for NTP time synchronization❌
Logs survive local disk failure and cannot be erased by an attacker on the host✅