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 (1 votes, average: 4.00 out of 5)

Leave a Reply

Be the First to Comment!

Notify of


RHCSA7: Task of the day

Allowed time: 10 minutes.
Create a XFS file system of 100MB. Mount it under /mnt. Then, increase its size by 50MB.

RHCE7: Task of the day

Allowed time: 10 minutes.
Configure a system to forward all email to a central mail server at (change the IP address accordingly).

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 ...