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 →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.
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
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.
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.
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.
Know, When & Execute
- Know:
MUA(Mail User Agent = Thunderbird/Outlook) talks toMTA(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.
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).
| 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.
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.
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).
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.
Comparing Common Logging Tools
rsyslog (Classic)
Built into almost every Linux distro. Forwards system logs over TCP/TLS (Port 6514) or UDP (Port 514) with minimal CPU overhead.
Grafana Loki
Modern cloud-native log aggregator. Indexes only labels (like host and
service), making it fast and cheap to store.
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!