On RHEL 7, Postfix is used as the mail service.
We are going to deploy Postfix on a null client. A null client is a machine that can only send mail. It receives no mail from the network, and it does not deliver any mail locally. We use a RHEL 7.0 virtual machine in this article.
Please check this post if you need to configure Postfix as a gateway.
Configure Postfix on a Null Client
The postfix package should be installed by default, do the following if it’s not the case:
# yum install -y postfix
Ensure the service is enabled on boot:
# systemctl enable postfix
Now, I saw some people adding a firewalld rule to allow incoming traffic for an smtp service. This is normally required for a central SMTP server, but makes little to no sense when talking about a null client. A null client cannot receive emails from outside, therefore no firewall configuration is required.
Only a few parameters are important for setting up an environment where email can be forwarded to a central mail server.
The file has quite a few Postfix configuration examples:
# less /usr/share/doc/postfix-2.10.1/README_FILES/STANDARD_CONFIGURATION_README
Check the “Postfix on a null client” section for more info.
Open the file
/etc/postfix/main.cf for editing, and add the following:
myhostname = srv1.rhce.local mydomain = rhce.local myorigin = $mydomain relayhost = [10.8.8.70] inet_interfaces = loopback-only mydestination = mynetworks = 127.0.0.0/8 [::]/128 local_transport = error: local delivery disabled
The relayhost prevents mail from getting stuck on the null client if it is turned off while some remote destination is unreachable.
The loopback-only tells to not accept mail from the network. Only messages that originate from the
127.0.0.0/8 network and the [::1]/128 network are forwarded to the relay host by the null client.
We prevent the local null client from sorting any mail into mailboxes by putting a local_transport parameter. We also disable local mail delivery by not specifying mydestination. All mail goes to the mail server as specified in relayhost. Note that we can also use a DNS name for the relayhost, as well as turn off MX lookups by putting a record in square brackets.
Check for syntax errors:
# postfix check
Restart the service:
# systemctl restart postfix
Send a test email to the root user:
# echo test | mailx -s Test root
postfix/pickup: 3DF9920832: uid=0 from=<root> postfix/cleanup: 3DF9920832: message-id=<20160531192921.3DF9920832@srv1.rhce.local> postfix/qmgr: 3DF9920832: from=<firstname.lastname@example.org>, size=416, nrcpt=1 (queue active) postfix/smtp: 3DF9920832: to=<email@example.com>, orig_to=<root>, relay=10.8.8.70[10.8.8.70]:25, delay=0.36, delays=0.3/0/0/0.05, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 5794EC3287) postfix/qmgr: 3DF9920832: removed
Configure Postfix as a Central Mail Server for a Domain
To test email delivery, we can use a FreeIPA server that we set up some time ago, and configure it as a central mail server for our rhce.local domain.
/etc/postfix/main.cf configuration should do the job:
myhostname = ipa.rhce.local mydomain = rhce.local myorigin = rhce.local inet_interfaces = all inet_protocols = ipv4 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
The mydestination parameter specifies the list of domains that the server considers itself the final destination for.
Configure firewall and restart the Postfix service:
# firewall-cmd --add-service=smtp --permanent # firewall-cmd --reload
Useful to know, we can delete all messages from the email queue with postsuper:
# postsuper -d ALL