Configure PostFix mail server in a CentOS 7 or RHEL 7

Postfix_logo

Ensure that sendmail is stopped in the host

  • systemctl stop sendmail
  • systemctl disable sendmail

Install the postfix package

  • yum install postfix

Backup the main postfix configuration file in case it is required for future use

  • cp /etc/postfix/main.cf /etc/postfix/main.cf.orig

Edit the configuration file

  • vi /etc/postfix/main.cf

Ensure that the following are enabled, and other similar entry is commented

========

  • myhostname = <your FQDN>
  • mydomain = <your FQDN>
  • myorigin = $myhostname
  • inet_interfaces = all
  • mynetworks = <your IP/subnet>, 127.0.0.0/8
  • home_mailbox = Maildir/

=======

Restart postfix

  • systemctl restart postfix

Verify if SMTP is working

  • netstat -na | grep 25

If it is working make sure sendmail, or any other SMTP service is not installed

Start the postfix service

  • systemctl start postfix
  • systemctl enable postfix

Verify if the SMTP service is running

  • netstat -na | grep 25

Note: The server will send mail only to users in its domain !!

====== ===== ====== ===== ====== =====

Let us test if the server is working fine.

Create a new user called “anyuser”

  • useradd anyuser

Do a telnet session to SMTP server

  • [root@host ~]# telnet localhost 25
  • Trying ::1…
  • Connected to localhost.
  • Escape character is ‘^]’.
  • 220 <my FQDN> ESMTP Postfix
  • ehlo <my FQDN>
  • 250-<my FQDN>
  • 250-PIPELINING
  • 250-SIZE 10240000
  • 250-VRFY
  • 250-ETRN
  • 250-ENHANCEDSTATUSCODES
  • 250-8BITMIME
  • 250 DSN
  • MAIL FROM: root@<my FQDN>
  • 250 2.1.0 Ok
  • RCPT TO: <anyuser@my FQDN>
  • 250 2.1.5 Ok
  • DATA
  • 354 End data with <CR><LF>.<CR><LF>
  • Hello anyuser
  • .
  • quit

Go to the home folder of the anyuser and check if the Maildir folder is automatically created, and the file file is there.

Comments are closed.