SSD Nodes Learn Hosting plans →
Guides Matt ConnorBy Matt Connor

Blocked using zen.spamhaus.org? What to fix

The same Spamhaus reject means two things: your server queries ZEN through a public resolver, or your VPS IP is really listed. Here is how to fix each.

Two problems behind one "blocked using zen.spamhaus.org" error

"Blocked using zen.spamhaus.org" can mean two different problems, and the fix depends on which one you have. In the first case, your own mail server rejects good senders because its Spamhaus lookups return an error code. In the second case, your VPS IP really is on a Spamhaus list, and other servers reject the mail you send. The first is a DNS problem on your server. The second is a listing: you fix its cause first, then clear it at check.spamhaus.org.

ZEN is Spamhaus's combined DNSBL (DNS-based blocklist). It holds the SBL, CSS, XBL and PBL lists in one zone, so a mail server can check all of them with one DNS query.

Start by finding the lines in your mail log:

sudo journalctl --since yesterday | grep 'blocked using zen.spamhaus.org'

On a box that also runs rsyslog, sudo grep 'blocked using zen.spamhaus.org' /var/log/mail.log finds the same lines. Check who wrote the reject:

  • A line that contains NOQUEUE: reject: RCPT from was written by your server's smtpd process. Your server refused someone else's mail. That is case A.
  • A line that contains status=bounced or status=deferred and then said: quotes a reply from a remote server about mail you sent. That is case B.

If you do not run a mail server at all and the text came back in a bounce from an app, it is case B.

Case A: why does my server reject senders that are not spammers?

Spamhaus does not always answer a query with a listing. Its return-codes page names three error answers on the public mirrors:

  • 127.255.255.252 means a typing error in the DNSBL name in your config.
  • 127.255.255.254 means the query came through a public or open resolver, or from an IP with generic, unattributable reverse DNS.
  • 127.255.255.255 means an excessive number of queries.

Spamhaus says none of these codes relate to the reputation of the IP you asked about, and a mail server must not use them to reject mail.

Postfix rejects anyway when the rule is written in its plain form, reject_rbl_client zen.spamhaus.org. The Postfix manual says that without a =d.d.d.d filter, any A record in the reply counts as a listing. An error code such as 127.255.255.254 is also an A record. So every sender looks listed while your resolver is the problem, which means good mail is refused.

Which resolver is your server using?

resolvectl status
cat /etc/resolv.conf

On Ubuntu, /etc/resolv.conf usually points at the local stub 127.0.0.53. To see the real upstream, look at Current DNS Server in the resolvectl output. Spamhaus's resolver guidance names Google DNS (8.8.8.8), Quad9 (9.9.9.9) and Cloudflare (1.1.1.1) as public resolvers it does not recommend for blocklist lookups. If you use one of them anyway, Spamhaus says you must use its Data Query Service, not the public mirrors.

Read the code yourself

A DNSBL lookup for an IP reverses the four octets and puts them in front of the zone name. For a sender at A.B.C.D, the query name is D.C.B.A.zen.spamhaus.org, so a sender at 203.0.113.79 is looked up with the octets in the order 79, 113, 0, 203. Install dig and run the lookup for an IP from one of your reject lines, with D.C.B.A replaced by its reversed octets:

sudo apt install -y bind9-dnsutils
dig +short D.C.B.A.zen.spamhaus.org

Read the answer like this:

  • An address in 127.0.0.x is a listing. The ZEN codes are below.
  • An address in 127.255.255.x is an error. Your config or your resolver is the problem, not the sender.
  • No answer at all is NXDOMAIN, which means "not listed". Spamhaus warns that queries through a public resolver may get NXDOMAIN anyway, so an empty answer from a public resolver proves nothing.

The ZEN listing codes, from Spamhaus's zone documentation:

  • 127.0.0.2: SBL
  • 127.0.0.3: CSS (an automated dataset inside the SBL)
  • 127.0.0.4: XBL
  • 127.0.0.9: DROP, always returned together with SBL
  • 127.0.0.10: PBL, entry maintained by the ISP
  • 127.0.0.11: PBL, entry maintained by Spamhaus
  • 127.0.0.30: BCL

Spamhaus gives two ways out of the error codes. Pick one of the next two sections, then restrict the Postfix rule as shown after them.

Fix 1: use a Data Query Service key

DQS (Data Query Service) gives you a personal hostname to query. Spamhaus says it is the option to use if your lookups go through a public resolver, because your key identifies you, not the resolver's IP. A DQS key is a 26-character code, and the zone name puts it first: <key>.zen.dq.spamhaus.net.

The free DQS page says a non-commercial entity or individual with low query volumes may qualify. It states no numeric quota. Spamhaus's article on public DNS adds more conditions. The originating network must be identifiable. Queries from large shared hosting environments are not accepted. Commercial use needs a subscription. Sign-up is a form. After you verify your email address, you log in and find the key in your account.

Then change the Postfix rule in /etc/postfix/main.cf. This is the ZEN line from Spamhaus's DQS Postfix guide, with YOURKEY standing for your key:

smtpd_recipient_restrictions =
    reject_rbl_client YOURKEY.zen.dq.spamhaus.net=127.0.0.[2..11],
    ...your existing restrictions...

Spamhaus places these lines at the top of smtpd_recipient_restrictions. The default Postfix reject message names the DNSBL domain, and that domain now contains your key. Spamhaus's guide uses rbl_reply_maps to replace the message, so the key never reaches the sender. Add this line to main.cf:

rbl_reply_maps = hash:$config_directory/dnsbl-reply-map

Create /etc/postfix/dnsbl-reply-map. Each entry is one line, with a tab between the key and the reply. The guide writes one entry with the code filter and one without:

YOURKEY.zen.dq.spamhaus.net=127.0.0.[2..11]	554 $rbl_class $rbl_what blocked using ZEN - see https://www.spamhaus.org/query/ip/$client_address for details
YOURKEY.zen.dq.spamhaus.net	554 $rbl_class $rbl_what blocked using ZEN - see https://www.spamhaus.org/query/ip/$client_address for details

Build the map, check the config and reload:

sudo postmap /etc/postfix/dnsbl-reply-map
sudo postfix check
sudo systemctl reload postfix

postfix check prints nothing when the config is sound. After the next reject, read the log line and confirm that it shows the ZEN message from the map and not your key. With DQS, two more error codes exist: 127.255.255.250 means the key is disabled, and 127.255.255.251 means the key is being used illegally.

If your mail stack already filters with Rspamd or SpamAssassin, for example a full mail stack such as mailcow on a VPS, check how that filter queries Spamhaus before you add Postfix rules. Spamhaus's guide advises against SMTP-level rejects in that case and prefers the milter route.

Fix 2: run your own resolver on an IP with matching DNS

The second documented fix keeps the public mirror (zen.spamhaus.org). Spamhaus's help page for public mirror users says your queries must come from a dedicated IP with attributable reverse and forward DNS. Its resolver guidance says to use a dedicated caching recursive resolver.

You need both of the following.

First, the VPS IP needs a PTR (pointer) record that names your host, and that name must resolve back to the same IP. A generic name such as 203-0-113-79.example-provider.net is the "unattributable" case behind 127.255.255.254. Check both directions:

dig +short -x 203.0.113.79
dig +short mail.example.com

The first command should print your own hostname, and the second should print the same IP. If the PTR is generic, set it in your provider's panel. Setting a reverse DNS PTR record on a VPS covers where that setting lives and how to test it.

Second, the server must resolve names itself, so its queries leave from that IP. Unbound is a caching recursive resolver. By default it listens on localhost only and answers only clients in 127.0.0.0/8, so installing it does not open a resolver to the internet.

sudo apt install -y unbound

Spamhaus's Unbound page notes that Unbound has QNAME minimisation on by default. QNAME minimisation is a privacy feature that sends only part of each name to each server. Spamhaus says it adds many queries for deeply nested names like blocklist lookups and brings no privacy gain there. It suggests turning it off as a temporary stop-gap. Create /etc/unbound/unbound.conf.d/spamhaus.conf:

server:
    qname-minimisation: no

Restart Unbound and test it directly before anything depends on it:

sudo systemctl restart unbound
dig @127.0.0.1 +short example.com
dig @127.0.0.1 +short D.C.B.A.zen.spamhaus.org

The first dig should print an IP address. If it times out, Unbound is not answering. Read journalctl -u unbound -n 50.

Now make the system use it. On Ubuntu, adding a global DNS= entry to systemd-resolved is not enough. The resolved.conf manual says queries go to the global servers in parallel to the per-link servers learned from the network, so some lookups would still use the provider's resolver. The direct switch is to replace the /etc/resolv.conf symlink with a static file:

sudo rm /etc/resolv.conf
echo 'nameserver 127.0.0.1' | sudo tee /etc/resolv.conf
sudo systemctl restart postfix

Every service on the box now depends on Unbound. If Unbound stops, all name resolution stops with it. On Debian and Ubuntu, chrooted Postfix daemons can read a copy of the file under the Postfix spool, so compare the two:

sudo diff /etc/resolv.conf /var/spool/postfix/etc/resolv.conf

No output means they match. If diff reports that the second file does not exist, there is no copy to worry about.

Restrict reject_rbl_client to real listing codes

Whichever fix you chose, stop treating error codes as listings. Postfix accepts a filter after the domain: rbl_domain=d.d.d.d, where each d is a number or a pattern in brackets with numbers or number..number ranges. Spamhaus's public mirror Postfix example uses it like this:

smtpd_recipient_restrictions =
    reject_rbl_client zen.spamhaus.org=127.0.0.[2..11],
    warn_if_reject reject_rbl_client zen.spamhaus.org=127.255.255.[1..255],
    ...your existing restrictions...

The first line rejects only answers from 127.0.0.2 to 127.0.0.11. The second line matches the error range, but warn_if_reject turns the reject into a log entry, so you still see when the lookups break. Search the log for reject_warning to find those entries. Run sudo postfix check and sudo systemctl reload postfix after the edit.

Know what the range leaves out: 127.0.0.30 (BCL) sits outside [2..11], so a BCL answer does not cause a reject with this pattern. It is Spamhaus's own example, but it does not cover every listing code.

The PBL codes are inside the range. If your users send through port 25 from home connections, they will be rejected. The PBL page says that mail from end-user ranges should go through an authenticated SMTP server. In practice that means submission on port 587 with a login.

Case B: is my VPS IP listed on Spamhaus ZEN?

When remote servers bounce your mail with this text, either the listing is real or the remote side has the case A problem. Find the IP your mail leaves from:

ip -4 route get 1.1.1.1

The address after src is your outbound IPv4 address. A dig from the VPS through a public resolver hits the same error codes as case A, so use Spamhaus's lookup tool instead. The SBL page says to look up listing details at check.spamhaus.org with the IP, the range or the SBL ticket number. The CSS, XBL and PBL pages send removals there too. Spamhaus says no removal of any listing ever costs money.

The result names a list. Each one means something different for a VPS tenant. For the background on why VPS ranges end up on blocklists at all, read why sites block VPS IP addresses.

SBL: your provider has to act

The SBL lists IPs and ranges that Spamhaus identifies as used by or under the control of spammers and abusers. Only the network or hosting provider responsible for the IP can request an SBL removal. As a tenant, open a ticket with your VPS provider, give them the SBL ticket number, and show them that the cause on your server is fixed.

CSS: an automated listing from your own traffic

CSS returns 127.0.0.3 and is detected automatically from spam sent by the IP. Spamhaus says whatever caused the problem must be found and corrected before removal, and that CSS lists the IP again at once if the problem continues. Removals start at check.spamhaus.org.

XBL: the machine itself is the problem

The XBL lists IPs where a machine or device shows signs of being insecure, compromised or infected. Spamhaus's examples include malware, brute-force attacks, mail relayed with stolen credentials, and free VPN apps that use the device as a proxy. Removals are handled only at check.spamhaus.org. Spamhaus also says the IP is listed again if the detected problem has not been corrected. A removal request before cleanup therefore only buys a short gap. Look for what is sending first:

sudo ss -tnp state established '( dport = :25 )'
sudo postqueue -p | tail -n 1
sudo grep -o 'sasl_username=[^, ]*' /var/log/mail.log | sort | uniq -c | sort -rn | head

The first command lists the processes that hold outbound connections to port 25. On a box where only Postfix sends mail, any other process name there needs explaining. The second prints the queue total, and thousands of requests you did not send point at abuse. The third counts accepted logins per mail account. One account with far more than the rest usually means a stolen password, so change it. If Postfix accepts mail for anyone, read how Postfix decides who may relay mail before you do anything else.

PBL: a policy listing, not an abuse listing

The PBL lists end-user IP ranges that should not send mail directly to the destination. Spamhaus says a PBL-listed IP is not necessarily bad. Code 127.0.0.10 means your ISP or provider maintains the entry, and 127.0.0.11 means Spamhaus maintains it. An individual removal through check.spamhaus.org applies only to a static, single IP that runs a real outbound mail server, and Spamhaus says such exclusions expire after one year. If you only need an app to send mail, relay it instead, as in sending mail from self-hosted apps through a relay.

Should you remove zen.spamhaus.org from Postfix?

Deleting the reject_rbl_client zen.spamhaus.org line does stop the false rejects at once. It also removes the ZEN filtering completely, so mail from IPs that really are on the SBL or XBL reaches your users. Tell that plainly to whoever relies on the server.

The code filter is the better trade. With =127.0.0.[2..11], error answers can no longer cause a reject, and SBL, CSS, XBL and PBL listings still do. A BCL answer (127.0.0.30) does not, because it falls outside that range. It only protects anyone if the lookups are answered, through a DQS key or a resolver that meets Spamhaus's terms. A server that queries through a public resolver may get NXDOMAIN for every sender. Then nothing is rejected, and nothing is filtered either. The warn_if_reject line is how you notice that state in the log.

FAQ

What does 127.255.255.254 from zen.spamhaus.org mean?

It is an error code, not a listing. Spamhaus returns it when the query came through a public or open resolver, or from an IP with generic reverse DNS that cannot be tied to an operator. Spamhaus says the code does not relate to the reputation of the IP you looked up and must not be used to reject mail. Fix it with a Data Query Service key, or with your own recursive resolver on an IP whose forward and reverse DNS match.

Why does Postfix reject every sender as listed on Spamhaus?

A plain reject_rbl_client zen.spamhaus.org treats any A record in the reply as a listing, and the error codes in 127.255.255.x are A records. When your resolver triggers an error code, every lookup returns one. Restrict the rule to zen.spamhaus.org=127.0.0.[2..11] so only real listing codes reject, then fix the resolver or move to a DQS key.

Is the Spamhaus Data Query Service free?

Spamhaus says non-commercial entities and individuals with low query volumes may qualify for a free DQS key, and it publishes no numeric quota on that page. Its conditions also say the querying network must be identifiable and that queries from large shared hosting environments are not accepted. Commercial use needs a paid subscription.

My VPS IP is on the XBL. Can I just request removal?

You can, at check.spamhaus.org, but Spamhaus lists the IP again if the detected problem is still there. XBL means a machine on that IP looks compromised or infected. Find what sends the traffic first: check outbound port 25 connections with ss, the size of the Postfix queue, and logins per mail account. Then request removal.

Can I just delete the Spamhaus line from main.cf?

Yes, and the false rejects stop, but so does all ZEN filtering, so spam from listed IPs reaches your users. A code-restricted rule keeps the filtering for real listings and ignores error answers, as long as your lookups go through a DQS key or a compliant resolver.

Was this article useful?