RHEL7: Configure a central mail server.

Share this link

Prerequisites

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
success

Reload the firewall configuration:

# firewall-cmd --reload
success

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 192.168.1.0/24 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 = 192.168.1.0/24, 127.0.0.0/8 

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 (192.168.1.24)
Host is up (0.00076s latency).
Not shown: 998 filtered ports
PORT   STATE SERVICE
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
Trying 192.168.1.24...
Connected to mail.example.com.
Escape character is '^]'.
220 mail.example.com ESMTP Postfix
HELO client
250 mail.example.com
quit
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"
(3 votes, average: 4.67 out of 5)
Loading...
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
        srv01.example.com:
        inet_interfaces = all
        inet_protocols = ipv4
        mydomain = example.com
        myorigin = example.com
        mydestination = mydomain

        srv02.example.com:
        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

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |