March 19, 2018

Postfix – Set up a Postfix Null Client on RHEL/CentOS 7

A null client (aka a forwarding agent):


You can find all my latest posts on medium.
  • Is a machine that has a mail server software running on it – you can install a mail client, e.g. Thunderbird so to create mails for the mail server to send.
  • Can only send mail. It can’t even send mail locally
  • Doesn’t try to work out how to best route the email to it’s destination. In fact, it is quite crude and sends all mails to a central mail server, which in turn does the actual routing work.

You can follow along this article by using our CentOS 7 postfix vagrant demo project. In our example we have the following setup:

+--------------------+    +--------------------------+    +--------------------+
|                    |    |                          |    |                    |
| |    ||    | |
|                    |    |                          |    |                    |
|                    |    |                          |    |                    |
|                    |--->|                          |--->|                    |
|   mta: postfix     |    |     mta: postfix         |    |   mta: postfix     |
|   mua: mailx       |    |                          |    |   mua: mailx       |
|                    |    |                          |    |                    |
|   sender: jerry    |    |                          |    |   receiver: tom    |
+--------------------+    +--------------------------+    +--------------------+

Some terminalogies.

Mail User Agent (MUA) – this is an app that’s used for creating emails. E.g. mail, mailx, outlook, mozilla thunderbird,…etc. You can install an MUA on your Null client to create and send emails. However these emails must be outbound, i.e. you can’t write emails to be sent locally to local user account on the Null Client.

Mail Transport Agent (MTA) – This term is used to refer to ‘sending mail servers’ and ‘receiving mail servers’. They both use the SMTP protocol, which runs on port 25. Hence a Null Client is considered as an MTA.

This article covers how to setup the null client, which in our example is called Also in our example we will confirm that we’ll validate everything is setup correctly by sending an email as user jerry, to the user tom (who resides on We’ll assume that the central email server and

The first step to setup a Null client is to install the postfix rpm:

$ yum install postfix

We now need to make changes to /etc/postfix/ which is the main Postfix config file. First we’ll take create a backup:

$ cp /etc/postfix/ /etc/postfix/

To edit this file, you can either use vim, or do it via the postconf utility. In our case we’ll use postconf to set the following:

$ postconf -e myhostname=$(hostname)
$ postconf -e
$ postconf -e local_transport='error: this is a null client'
$ postconf -e myorigin='$myhostname'
$ postconf -e inet_interfaces=loopback-only
$ postconf -e mydestination=''           # this is intentionally left blank
$ postconf -e mynetworks=' [::1]/128'
$ postconf -e relayhost=[]

To find out what these settings mean, see:

$ man 5 postconf

We also need to set the following in order to get Null client working in our Vagrant environment:

$ postconf -e disable_dns_lookups=yes

To summarise, the main configurations that needs modifying are:

myhostname: The internet hostname of this mail system.

mydomain: The internet domain name of this mail system.

relayhost: The next-hop destination of non-local mail; overrides non-local domains in recipient addresses..

inet_interfaces: This set the interfaces that our mail server is allowed to receive mails from. A null client shouldn’t be receiving any mails so we restrict this to only the loopback interface. This means that when we start the postfix daemon, it only listens on the lo interface.

mynetworks: this refers to the network of the inet_interface.

myorigin: This lets you specify what domain you want locally-originating email to appear to come from. In otherwords it let’s you customise the “From” section in your email. In big companies, the use the domain name rather than hostname, e.g. they use, rather than something like

mydestination: This specifies what hostnames/domain that this server should interpret as being the local destination for. For a null client this needs to be set to blank, in order to prevent the mail server from sending any mail to any local accounts.

local_transport: This specifies how emails destined to $mydestination should be delivered.

Once you have set these values, you can perform a syntax check:

$ postfix check

For troubleshooting purposes, you can also compare the existing default value against the new value like this:

$ postconf -d inet_interfaces
inet_interfaces = all

$ postconf -n inet_interfaces
inet_interfaces = loopback-only

Finally we enable and restart postfix:

$ systemctl restart postfix
$ systemctl enable postfix

Now we are ready to start testing. To do this, lets first install an MUA, in our case we’ll use mailx:

$ yum install mailx

Next we create our user called jerry, and we switch to that user:

[root@null-client postfix]# useradd jerry
[root@null-client postfix]# su - jerry
[jerry@null-client ~]$

Next we send a test email:

$ echo "Hello Matt, this is Jerry" | mail -s "test email"

After sending a test mail, use the following to check if it has left your box:

[jerry@null-client ~]$ mailq
Mail queue is empty

Now if we log into the mail client, and check if we got any mail:

[root@mail-client ~]# su - matt
[matt@mail-client ~]$ mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/matt": 2 messages 2 new
>N  1 root                  Fri Apr 13 17:39  24/1045  "test email"
 N  2 jerry@null-client.cb  Fri Apr 13 23:08  24/1045  "test email"
& 2
Message  2:
From  Fri Apr 13 23:08:38 2018
Date: Fri, 13 Apr 2018 23:08:38 +0000
Subject: test email
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
Status: R

Hello Matt, this is Jerry

[post-content post_name=rhsca-quiz]

What are the main steps to setting up the null client?

01. install rpms
02. edit the /etc/postfix/
03. sanity check the updated configs
04. start the postfix service
05. test with mailx

what is the command to install the rpms for setting up a null client?

$ yum install postfix
$ yum install mailx

What is the main postfix config file that needs changing?


What is the command to display list all postfix effective settings?

$ postconf

What is the command to display a full list of implicit default postfix configuration values?

$ postconf -d

What is a handy grep command to list most of the postconf setting of interest?

$ postconf | grep ‘^my’

What are the commands to run to make the changes?

$ postconf -e myhostname=$(hostname)
$ postconf -e
$ postconf -e myorigin=’$myhostname’
$ postconf -e mynetworks=’ [::1]/128′
$ postconf -e mydestination=” # this is intentionally left blank
$ postconf -e local_transport=’error: this is a null client’
$ postconf -e inet_interfaces=loopback-only
$ postconf -e relayhost=[]
# for the vagrant environment, we also need to set:
$ postconf -e disable_dns_lookups=yes

What is the command to display a full list of explicitly postfix configuration values?

$ postconf -n

Where can you find more info about these settings?

$ man 5 postconf

What is the command to do a syntax check of the postfix values?

$ postfix check

What is the command to restart the postfix daemon?

$ systemctl restart postfix
$ systemctl enable postfix

What is the command to send a test mail to

echo “hello tom, this is jerry” | mail -s “test email”