A Postfix on port 25 facing the open internet spends a meaningful share of its time talking to botnets — not real MTAs. Postscreen is the lightweight gatekeeper that sits in front of smtpd, scores each connecting peer against DNSBLs and protocol-level heuristics, and only hands the genuinely legitimate sessions to the heavy smtpd. This article is the postscreen deploy we use on production mail edges, including the DNSBL scoring layout, the PREGREET test, and the TLS pass-through patterns that avoid breaking authenticated submission.
How to verify
Check whether postscreen is wired today and how it’s behaving.
sudo postconf | grep -E 'postscreen|smtpd_proxy'
sudo postconf -M | grep -E 'postscreen|smtpd'
sudo journalctl -u postfix | grep -i 'postscreen' | tail -20
ss -ltnp | grep :25
A vanilla Postfix has no postscreen — smtp is bound directly to port 25 in master.cf. The transformation below moves smtpd off port 25 and puts postscreen in front.
What’s happening
Postscreen is a single-process screening daemon that handles port 25 connections, performs a battery of cheap checks, and then either:
- Allows the peer through by handing the TCP connection to a backend smtpd (which is now listening on
pass:smtp, an internal hand-off). - Drops the peer with no SMTP banner (zombies move on).
- Greets and rejects with a 550, after performing an explicit protocol check.
The checks postscreen runs:
- DNSBL scoring — query multiple block lists with weighted scores; reject if the sum exceeds a threshold. Far better than the binary “single blacklist hit = reject” pattern.
- PREGREET — wait 6 seconds before sending the SMTP banner. Real MTAs wait silently; many botnets send commands first. Catching this is free and effective.
- DNSBL_WHITELIST — a counter-balance for the above; a peer that hits a whitelist gets negative score.
- BARE_NEWLINE / NON_SMTP_COMMAND / PIPELINING — protocol violations that real MTAs don’t commit.
Postscreen does not handle SMTP AUTH itself — it forwards to smtpd. For the submission ports (587, 465), bypass postscreen entirely; only port 25 (MX-to-MX traffic) should be screened.
The procedure
-
Edit
master.cfto move smtpd off port 25 and put postscreen in front. Find thesmtp inetline and replace it:# Before: smtp inet n - y - - smtpd # After: smtp inet n - y - 1 postscreen smtpd pass - - y - - smtpd dnsblog unix - - y - 0 dnsblog tlsproxy unix - - y - 0 tlsproxyThe
1in the postscreen line ismaxproc=1— postscreen is single-process by design.dnsblogis the helper that does the DNS lookups;tlsproxyhandles STARTTLS pass-through for postscreen. -
Configure DNSBL scoring in
main.cf. Weighted scoring is the safest pattern:postscreen_dnsbl_threshold = 3 postscreen_dnsbl_action = enforce postscreen_greet_action = enforce postscreen_bare_newline_action = enforce postscreen_non_smtp_command_action = drop postscreen_pipelining_action = enforce postscreen_dnsbl_sites = zen.spamhaus.org*3 bl.spamcop.net*2 b.barracudacentral.org*2 psbl.surriel.com*1 dnsbl.sorbs.net*1 postscreen_dnsbl_whitelist_threshold = -2 postscreen_dnsbl_sites = $postscreen_dnsbl_sites, list.dnswl.org=127.0.[0..255].[1..3]*-2 postscreen_access_list = permit_mynetworks cidr:/etc/postfix/postscreen_access.cidrThe
*Nsyntax weights each list — Spamhaus ZEN gets a weight of 3, so a single hit there meets the threshold. Lower-confidence lists (psbl, sorbs) need company. -
Create the access CIDR list for explicit allow/deny:
sudo tee /etc/postfix/postscreen_access.cidr <<EOF # always-allow operators 203.0.113.0/24 permit # always-deny known abuser 192.0.2.66/32 reject EOF -
Set the greeting and timing parameters:
postscreen_greet_wait = 6s postscreen_dnsbl_ttl = 1h postscreen_dnsbl_min_ttl = 60s postscreen_cache_map = btree:$data_directory/postscreen_cache postscreen_cache_cleanup_interval = 12hThe cache is the key to throughput — a peer that passed once is remembered for
postscreen_dnsbl_ttland skips the full battery on reconnect. -
Configure TLS pass-through for STARTTLS on port 25. Postscreen can’t terminate TLS itself; it forwards to
tlsproxy:postscreen_tls_security_level = $smtpd_tls_security_level postscreen_use_tls = yes -
Reload and verify:
sudo postfix check sudo systemctl reload postfix sudo journalctl -u postfix -f | grep -i postscreenTail the log; you’ll see lines like:
postfix/postscreen[1234]: CONNECT from [192.0.2.99]:54321 to [203.0.113.10]:25 postfix/postscreen[1234]: PREGREET 22 after 0.1 from [192.0.2.99]:54321: EHLO ... postfix/postscreen[1234]: DNSBL rank 5 for [192.0.2.99]:54321 postfix/postscreen[1234]: HANGUP after 0.5 from [192.0.2.99]:54321 in tests after SMTP handshake -
Test a legitimate sender. From a known-good external SMTP (your own laptop’s
swaks):swaks --to test@example.com --from you@you-domain.com --server mx1.example.comThe session should pass postscreen, hand off to smtpd via
pass:smtp, and complete. Postscreen will cache your IP and skip the full battery on subsequent connections.
Operational notes
- Postscreen logs each peer’s DNSBL score; ship these to your log aggregator and you have free deliverability telemetry — peers that score high but are genuine senders (a small partner’s misconfigured MTA) surface here.
- The PREGREET test deflects almost all volumetric botnet traffic. We have seen 80%+ of port-25 connections dropped at this stage on heavily-targeted boxes — saves smtpd cycles.
- DNSBL response caching is in
postscreen_cache_map. A purge happens on a schedule; if a list rotates a peer in or out, the cache might lag.postsuper -ion the cache resets it. - The submission ports (587/465) must not have postscreen in front —
master.cfforsubmissionandsmtpsreferencessmtpddirectly. Sticking postscreen there breaks authenticated submission for legitimate users. - For very low-volume boxes, postscreen is overkill — the operational complexity outweighs the DDoS savings. We deploy it on boxes with >1000 msg/day or any box that has been targeted.
Common pitfalls
- The
master.cfchange forgets to adddnsblogandtlsproxyservices — postscreen starts but DNSBL queries hang and STARTTLS doesn’t work; both helpers are required. - A peer is silently dropped at the PREGREET stage because their MTA is misconfigured to send
HELObefore banner — surfaces as “we can’t receive from this customer.” Whitelisting that one peer’s IP inpostscreen_access.cidris the right fix. - The DNSBL threshold is too aggressive (set to 1 with multiple
*1lists) and legitimate small-business mail gets dropped — start at threshold 3 with weighted lists and observe for a week before tightening. postscreen_cache_mapis on a tmpfs filesystem (/tmp) and clears on reboot — the cache rebuilds, which costs DNSBL queries at startup; pin the cache to persistent storage.- A
psbl.surriel.comor similar list goes offline; postscreen waits for the timeout on every connection. Monitor DNSBL availability withdig +short ip.in.addr.zen.spamhaus.orgperiodically; remove dead lists from the config.
Stack Harbor stands up postscreen on every internet-facing Postfix in the engagements we run — DNSBL set tuned to the volume and tenant, PREGREET enforced, cache on persistent storage, and the submission ports kept clear. If you have a Postfix where smtpd workers are exhausted by botnet traffic, that defensive layer is part of our Managed Operations practice.