Linux Mail Server Architecture: SMTP, DNS and the Complete Message Path
A mail server is not one daemon and a successful SMTP banner is not a working mail platform. Delivery crosses public DNS, network policy, Postfix SMTP services, relay controls, identity checks, filters, queues, mailbox delivery and Dovecot access. This first lesson builds a testable map of that path. Every later configuration will attach to a named boundary in this model, so an operator can diagnose the first failing layer instead of restarting services or changing unrelated records.
Prerequisites and inherited lab checkpoint
Use two disposable RHEL 9 or RHEL 10 virtual machines on an isolated network. Name them mail1.example.test and client1.example.test. The reserved example.test namespace prevents accidental public delivery. Keep console access, a snapshot and a second privileged shell before changing network or mail policy.
No Internet-reachable SMTP service is required in this lesson. If the lab later receives public mail, obtain an approved domain, static address, reverse-DNS delegation and abuse contact first. Never copy production credentials, DKIM private keys or customer messages into the lab.
Install and prepare the required components
sudo dnf install -y bind-utils swaks tcpdump
mkdir -p "$PWD/mta-lab-evidence"
date -u --iso-8601=seconds
hostnamectl
cat /etc/redhat-release
ip -brief address
ip route showbind-utilssuppliesdig;swaksis a controlled SMTP test client when available from an approved repository. Ifdnf info swaksfinds no package, useopenssl s_clientand Postfix tools later rather than downloading an unidentified script.tcpdumpis installed for a later packet-level lab. Captures can contain addresses, credentials and message content, so restrict permissions and capture only the required interface, host and port.- The evidence directory is unprivileged in this introductory lab. Later lessons use a root-owned directory because configuration and logs can expose sensitive operational data.
Write the architecture contract before touching Postfix
Create a short design record containing the accepted domains, outbound identities, mailbox format, authentication source, TLS names, delivery method, filtering boundary, monitoring owner and recovery objectives. A component is selected only after its responsibility is clear.
| Flow | Ordered path | Acceptance question |
|---|---|---|
| Inbound | Authoritative DNS -> TCP/25 -> Postfix smtpd -> relay policy -> authentication results -> content policy -> queue -> LMTP -> Dovecot Maildir | Can an unauthenticated remote sender deliver only to a valid local recipient, while relay to a third domain is denied? |
| Authenticated submission | User -> TCP/587 with STARTTLS -> Dovecot SASL -> Postfix cleanup -> DKIM signing -> queue -> remote MX | Can a valid user submit an authorized sender identity while an invalid user and spoofed identity are rejected? |
| Mailbox access | Mail client -> IMAPS/993 -> Dovecot authentication -> index and Maildir | Can the mailbox owner read delivered mail without exposing cleartext credentials? |
| Operations | Logs + queue + DNS + metrics + backups -> alert, diagnosis and recovery | Can the team explain a delayed message by queue ID and restore service without creating an open relay? |
Draw separate trust zones for the public Internet, SMTP edge, local policy daemons, database, mailbox storage and administration network. Mark every socket as TCP or Unix, every process owner, and whether failure should temporarily defer mail, reject it, or permit it. “Accept on error” is not a harmless default when the failed service enforces identity or malware policy.
Verify the working path
dig +short MX example.test
dig +short A mail1.example.test
getent hosts mail1.example.test
ss -lntup
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-all
sudo getenforce
sudo systemctl --failed- The reserved domain should not unexpectedly resolve through public DNS. Local lab resolution must be explicitly documented through a private DNS zone or reviewed hosts entries.
- At this stage there should be no unexplained SMTP, submission, IMAP or POP listener. Record the baseline so later openings are attributable.
- SELinux should remain enforcing. A mail service that works only after disabling SELinux has an unresolved labeling, boolean or policy problem.
- A clean command does not prove end-to-end mail flow. These checks establish the starting state against which later changes are measured.
Production decisions before continuing
| Decision | Choose deliberately | Evidence to retain |
|---|---|---|
| Role separation | Decide whether SMTP edge, mailbox storage, database and filtering share a host. Small labs may combine them; production failure and trust boundaries still need names. | Architecture diagram, data classification and responsible owner |
| Domain authority | List domains accepted as final destination, relayed domains and outbound-only identities. | Approved domain inventory and relay matrix |
| Addressing and DNS | Require stable addressing, forward DNS, matching PTR for outbound hosts and controlled TTLs. | Authoritative lookups from external resolvers |
| Delivery semantics | Choose LMTP or another explicit final-delivery interface and define quota/full-mailbox behavior. | Positive delivery and deliberate temporary/permanent failure tests |
| Recovery objective | Define acceptable queue loss, mailbox loss and restoration time before selecting backup tooling. | RPO, RTO and an isolated restore exercise |
Separate protocol roles and trust decisions
An MTA accepts or relays messages using SMTP. Postfix performs that role and also manages queues. An MDA or local delivery service places accepted mail in the final mailbox; this course uses Dovecot LMTP. Dovecot also provides IMAP access and SASL authentication for message submission. DNS publishes routing and identity assertions, but DNS alone does not authorize relay or prove that a message is wanted.
SMTP has two different public-facing jobs. Port 25 is server-to-server transport and normally does not offer arbitrary user relay. Port 587 is authenticated message submission, requires encryption before credentials and applies sender authorization. Port 465 is implicit-TLS submission when the service is deliberately enabled. Treating all three listeners as one policy is a common route to credential exposure or open relay.
SPF evaluates the SMTP envelope domain against the connecting IP. DKIM verifies a cryptographic signature over selected headers and body content. DMARC asks whether the visible From domain aligns with a passing SPF or DKIM identity and applies the domain owner policy. These controls do not replace recipient validity, rate limits, malware filtering, complaint handling or reputation management.
Understand the component before configuring it
| Layer | Question to answer | Evidence |
|---|---|---|
| DNS and network | Which hostname and address should be reached, in which direction? | A/AAAA, MX, PTR, route, firewall and packet evidence |
| SMTP session | Which peer, envelope sender and recipient were accepted? | Transcript, enhanced status code and Postfix queue ID |
| Policy and identity | Which relay, SPF, DKIM, DMARC or content decision ran? | Ordered restriction/milter logs and Authentication-Results |
| Queue and delivery | Where is the message now, and what is its next hop? | Queue state, next-hop response and Dovecot LMTP result |
| Mailbox access | Can the correct identity retrieve the final message securely? | Dovecot auth, TLS, mailbox path and IMAP test |
Build it step by step
- Start with an envelope. Record connecting IP, HELO, MAIL FROM and RCPT TO separately from visible message headers.
- Resolve the destination. Follow MX preference to A or AAAA records and test reachability to TCP/25 from the actual source network.
- Classify the listener. Decide whether the connection is remote transport or authenticated submission before applying policy.
- Make relay ownership explicit. Accept final local domains, authenticated submission and approved relay clients only; reject every unintended third-party path.
- Attach policy in order. Preserve trustworthy upstream identity, calculate local results, filter content and record which component made each decision.
- Follow the queue ID. Correlate smtpd acceptance, cleanup, queue manager, outbound smtp or LMTP delivery using one identifier.
- Prove final state. Verify the recipient mailbox or remote SMTP response and retain evidence for delay, bounce and complaint analysis.
Operate and inspect the component
dig +noall +answer MX example.net
dig +noall +answer A mail.example.net
dig +noall +answer -x 192.0.2.25
nc -vz mail.example.net 25
openssl s_client -starttls smtp -connect mail.example.net:25 -servername mail.example.net -crlf
sudo tcpdump -ni any 'tcp port 25 or tcp port 587 or tcp port 993'- Use documentation address ranges such as
192.0.2.0/24in examples. Replace values only after the production change is reviewed. openssl s_clientvalidates the TLS negotiation and presented chain; it does not prove relay policy, mailbox delivery or reputation.- Unsafe: packet capture can collect message content and authentication material. Narrow the filter, duration and access, and securely remove the capture after approved retention.
- An SMTP transcript should retain commands, reply codes and queue ID but redact credentials, private message content and customer addresses.
Evidence and acceptance criteria
| Evidence | Healthy result | Failure meaning |
|---|---|---|
| Inbound accepted message | One queue ID links remote peer, recipient, policy results and LMTP success | A gap identifies the layer that lost or deferred the message |
| Relay denial | Unauthenticated third-party sender to third-party recipient receives a permanent relay denial | The server may be an open relay or the test did not reach the intended listener |
| Submission | TLS precedes AUTH; valid user accepted; invalid credentials denied | Credentials may be exposed or SASL boundary is broken |
| DNS identity | Forward, MX and PTR values match the approved design | Remote routing, TLS identity or outbound reputation can be impaired |
Trace one message instead of guessing
A remote system reports a temporary failure for [email protected]. DNS resolves correctly and TCP/25 reaches Postfix. The transcript shows recipient acceptance and returns a queue ID. Postfix logs then show LMTP returning a temporary storage error because the mailbox filesystem is read-only. Restarting Postfix would not repair that condition. The correct response is to protect the queue, investigate the filesystem, restore safe writes, retry one message and verify final delivery before flushing broader traffic.
The same method works outbound. Start with the submitted queue ID, inspect active or deferred state, read the remote enhanced status code, verify the next-hop DNS answer and only then decide whether the cause is local policy, network reachability, remote throttling or a permanent recipient failure.
Troubleshooting by symptom
| Symptom | Inspect first | Defensible next action |
|---|---|---|
| No SMTP banner | DNS target, route, listener, local firewall and upstream ACL | Correct the first layer with missing evidence; do not edit mail policy yet |
| Relay access denied for local user | Listener, TLS, SASL identity and relay restrictions | Use submission with authentication; never broadly add client networks |
| Accepted but absent from mailbox | Queue ID, queue state, transport and LMTP response | Repair final delivery and retry a single controlled item |
| Delivered locally but remote never received it | Outbound queue, MX resolution and remote reply | Classify temporary versus permanent status before retry or bounce action |
| Authentication result looks inconsistent | Header trust boundary and local verifier logs | Remove untrusted inbound results and confirm ordered local evaluation |
Unsafe operations and recovery boundaries
- Unsafe: adding a broad subnet to trusted networks can create an open relay. Trust only owned, enumerated clients and prove a negative relay test.
- Unsafe: opening SMTP, submission or IMAP to the Internet before authentication, TLS and rate controls are verified exposes an unfinished service.
- Unsafe: deleting a deferred queue hides the remote response and can lose legitimate mail. Preserve representative evidence and classify messages first.
- Unsafe: accepting forged inbound Authentication-Results lets a sender claim its own SPF, DKIM or DMARC success. Trust only results from identified internal authorities.
Rewritten knowledge checks
Cumulative lab checkpoint
- Draw both inbound and submission paths with every DNS record, port, process, Unix socket, queue and mailbox boundary labelled.
- Create a relay matrix for local domains, authenticated users, approved systems and untrusted Internet clients.
- Record baseline listeners, firewall zones, SELinux mode and resolver behavior on both lab hosts.
- Write positive and negative acceptance tests for SMTP transport, submission and mailbox access before installing services.
- Define what evidence will be retained for a queue delay and how addresses or content will be redacted.
- Snapshot both VMs and save the architecture contract as the inherited checkpoint for Lesson 2.