RHEL7: Configure a central mail server.

Share this link


In order to test a central mail server in a standard way using MX record, you will need to set up a master DNS server.

It is still possible to avoid setting up a master DNS server if you only want to test a null-client configuration (RHCE 7 requirement). In this case, you will have to use the relayhost = [mail.example.com] or relayhost = [ipaddress] syntax (see Configure a system to forward all email to a central mail server).

Also, you can set the disable_dns_lookups directive to yes, to force Postfix to read the local /etc/hosts file instead of sending DNS requests to get the MX records.

Installation Procedure

Install the postfix package (if it is not already there):

# yum install -y postfix

Add a new service to the firewall:

# firewall-cmd --permanent --add-service=smtp

Reload the firewall configuration:

# firewall-cmd --reload

Activate the postfix service at boot:

# systemctl enable postfix

Start the postfix service:

# systemctl restart postfix

Let’s assume that your server is called mail.example.com on the network.
Edit the /etc/postfix/main.cf file and change the following directives:

myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks =, 

Check the syntax:

# postfix check

Check the non-default configuration:

# postconf -n

Set the SELinux allow_postfix_local_write_mail_spool boolean to ‘on‘:

# setsebool -P allow_postfix_local_write_mail_spool on

Restart the postfix configuration:

# systemctl restart postfix

Test from a client with the nmap command, it should display: “25/tcp open smtp“:

# yum install -y nmap
# nmap mail.example.com
Starting Nmap 6.40 ( http://nmap.org ) at 2014-08-05 23:41 CEST
Nmap scan report for mail.example.com (
Host is up (0.00076s latency).
Not shown: 998 filtered ports
22/tcp open  ssh
25/tcp open  smtp
MAC Address: 52:54:00:44:23:51 (QEMU Virtual NIC)

Nmap done: 1 IP address (1 host up) scanned in 6.16 seconds

Alternatively, test from a client with the telnet command:

# yum install -y telnet
# telnet mail.example.com 25
Connected to mail.example.com.
Escape character is '^]'.
220 mail.example.com ESMTP Postfix
HELO client
250 mail.example.com
221 2.0.0 Bye
Connection closed by foreign host.

On the central mail server, create a user called me:

# adduser me

Then, send a mail to me:

# echo "This is a test." | mail -s "Test" me@example.com

Note: The echo command introduces the content of the mail. The -s option specifies the mail subject followed by the recipient.

Finally,  check the user gets his mail:

# su - me
$ mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/me": 1 message 1 new
>N  1 root                  Tue Aug  5 23:47  21/785   "Test"
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.67 out of 5)
16 comments on “RHEL7: Configure a central mail server.
  1. FillardMillmore says:

    This is excellent. Thank you so much for all of the effort you’ve gone through to provide us with this wonderful resource, CertDepot.

  2. scruff says:

    Hello, guys! During analyzing SMTP topic, I became a bit confused. When I try to send message from null client SRV02.EXAMPLE.COM to relayhost SRV01.EXAMPLE.COM to user, let’s say, davis and to make delivery successful I must type mail -s mysubject davis@srv01.example.com <. . But using "mail -s mysubject davis@example.com <." or "mail -s mysubject davis <." isn't working well and I'm afraid that I might fail this task on exam. What is your opinion, colleagues?

    • Lisenet says:

      So it is working, but just not working well? Or not working at all? Can you give us more details?

    • Sam says:

      Assuming a dns is setup correctly. Ask your self which server is the mail been hosted on, is it srv01.example.com or example.com, and what way the mail is been routed. The answer is in the understanding of the /etc/postfix/main.cf file. Take a closer look at the my networks, relay host, inet_faces and the my destinations, setting.

      Sidenote you need to understand the problem before understanding the answer.

      • scruff says:

        Dear Sam, DNS configured correctly 100%. I’ve got perfectly resolving of both servers and domain as well. srv01.example.com is relayhost, srv02.example.com is null-client. I used Sander van Vugt’s video to setup mail exchange. Here are the setting of /etc/postfix/main.cf
        inet_interfaces = all
        inet_protocols = ipv4
        mydomain = example.com
        myorigin = example.com
        mydestination = mydomain

        inet_interfaces = all (I know, unsecured, but for the lab it is OK)
        inet_protocols = ipv4
        mydestination = example.com
        relayhost = [srv01.example.com]

        Networks section in main.cf is default on both servers.
        Correct me if I’m wrong with settings.

  3. Pat says:

    When I nmap from a client to the server I get 25/tcp closed and telnet on the server give me the message “connection refused”. Anyone knows how to fix that?

Leave a Reply

RHCSA7: Task of the day

Allowed time: 10 minutes.
Create two new user accounts "steve" and "oliver".
Create a group "team". Create a directory "shared".
All files put into the "shared" directory by "steve" or "oliver" should belong to the "team" group and be only visible by them.

RHCE7: Task of the day

Allowed time: 15 minutes.
Configure a httpd server with a password protected directory under the /var/www/html/private directory.

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...