---
title: "Whitelisting single Hosts, IP Addresses, and even Networks in Postfix"
description: "Whitelist single Hosts, IP addresses, and even networks in Postfix to stop them hitting a blacklist."
url: "https://mailmum.io/posts/whitelisting-hosts-ip-addresses-and-even-networks-in-postfix/"
---

# Whitelisting single Hosts, IP Addresses, and even Networks in Postfix

If you use any [blacklists](https://mailmum.io/glossary/ip-blacklisting/) for email services,
[whitelisting](https://mailmum.io/glossary/ip-whitelisting/) important Hosts, single IP
Addresses, and even whole networks is an essential task. By
whitelisting valuables email services to your users or even customers, you as
admin won't reject important email communication.

## Blacklisting in Postfix

If you use any blacklist service or has [your
blacklist](https://mailmum.io/posts/blacklisting-single-hosts-ip-addresses-and-even-networks-in-postfix/)
in your Postfix setup, you will probably find similar logs:

```sh
root@server $ grep "blocked using" /var/log/mail.log
Dec 17 4:07:18 server postfix/smtpd[21213]: NOQUEUE: reject: RCPT from
unknown[1.2.3.4]: 554 5.7.1 Service unavailable; Client host [1.2.3.4]
blocked using ix.dnsbl.manitu.net; Blocked - see http://www.dnsbl.manitu.net/lookup.php?value=1.2.3.4;
from=<x0h0ihbxazf@somedomain.example> to=<cp57ouwn7zm9@mydomain.example> proto=ESMTP helo=<[1.2.3.4]>
```
As you can see in this example, IP Address *1.2.3.4* was blacklisted by a
third-party service.

If you check your Postfix configuration file *main.cf* you will find something
like:

```sh
...
smtpd_recipient_restrictions = reject_invalid_hostname,
                               reject_unauth_pipelining,
                               permit_mynetworks,
                               permit_sasl_authenticated,
                               reject_unauth_destination,
                               reject_rbl_client ix.dnsbl.manitu.net,
                               permit
...
```

Your config will look different, but the thing we are looking for is
**reject_rbl_client ix.dnsbl.manitu.net**. It tells Postfix to reject any
clients listed on the *ix.dnsbl.manitu.net* [DNS blocklist
(DNSBL)](https://mailmum.io/glossary/dns-blocklist-dnsbl/).

**Hint:** If you want to build your blacklist, check:
[Blacklisting Single Hosts, IP Addresses, and even Networks in Postfix](https://mailmum.io/posts/blacklisting-single-hosts-ip-addresses-and-even-networks-in-postfix/).

## Whitelisting Hosts, IP Addresses, and Networks

To whitelist some hosts, IP addresses, or even whole networks in Postfix, we
need to provide a file that may look like this:

```sh
root@server $ cat /etc/postfix/rbl_allow
mail.domain.example OK
1.2.3.4 OK
1.2.4.0/24 OK
```

**Notice:** The filename *rbl_allow* is your choice. You can take any name like
*rbl_override*, *rbl_whitelist*, or whatever name you like.

After you have created or updated this file, you need to generate a [Hash
table](https://en.wikipedia.org/wiki/Hash_table) Postfix will use by running
the [postmap command](http://www.postfix.org/postmap.1.html):

```sh
root@server $ postmap /etc/postfix/rbl_allow
```

Postfix 2.x should generate a corresponding */etc/postfix/rbl_allow.db* file.

Now you need to tell Postfix where and how to use this generated hash in your
setup.

## Allow listed clients in Postfix

Now the most crucial part of this setup is to add this entry before any
blacklist is hit. This way, we skip hitting any following rules in our Postfix
setup.

```sh
...
smtpd_recipient_restrictions = reject_invalid_hostname,
                               reject_unauth_pipelining,
                               permit_mynetworks,
                               permit_sasl_authenticated,
                               reject_unauth_destination,
                               check_client_access hash:/etc/postfix/rbl_allow,
                               reject_rbl_client ix.dnsbl.manitu.net,
                               permit
...
```

By adding **check_client_access hash:/etc/postfix/rbl_allow** above the first
blacklist entry **reject_rbl_client ...** you whitelist email servers, which may
be blacklisted by any following service, but will never be hit by this
configuration.

The last step is to restart Postfix to reflect the changes.

```sh
root@server $ service postfix restart
```

## Updating your Whitelist

If you change your whitelist file, don't forget to regenerate your [Hash
table](https://en.wikipedia.org/wiki/Hash_table) with [postmap
command](http://www.postfix.org/postmap.1.html) and
restart Postfix to reflect changes:

```sh
root@server $ service postfix restart
root@server $ postmap /etc/postfix/rbl_allow
```

## Summary

Whitelisting crucial email servers is an essential part of email admins' work.
These can be freemail services or specialized email services like
[Sendgrid](https://sendgrid.com). By whitelisting them, you prevent them from
being hit by a blacklist and improve email deliverability. Keep the entries as
narrow as possible and review them regularly &mdash; see [IP
whitelisting](https://mailmum.io/glossary/ip-whitelisting/) for why a stale allow list is worse
than a stale block list.
