Friday, April 19, 2024
LinuxVPS

Easy Steps to Configure POSTFIX Mail Server on Cent OS

Hi All,

Today we are going to see about how to configure simple POSTFIX mail server on Cent OS.

Installing Postfix

Login to your server and run the following command to update the repository and packages available in your system.

yum -y update

Now update the hostname of your system to the FQDN you want to use with your mail server. Run the following command to change your hostname.

hostname mail.yourdomain.com

Now add the hostname entry in the host files of your system. Edit /etc/hosts files using your favorite editor. For example if your are using nano then you will need to run the following command.

nano /etc/hosts

You will see two lines of entries in there, append your server IP address followed by hostname at the end of the file. It should look like the one shown below.

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1       localhost localhost.localdomain localhost6 localhost6.localdomain6
104.36.18.239 mail.yourdomain.com

Now we can install Postfix, enter the following command to do so.

yum -y install postfix

Before configuring postfix we will need to configure SSL which will be used to encrypt and secure the emails.

 mkdir /etc/postfix/ssl
cd /etc/postfix/ssl

Now we will have to create SSL certificates. If you do not have openssl installed you can install it using the following command.

yum -y install openssl

Now run the following command to create certificate and key files.

openssl req -x509 -nodes -newkey rsa:2048 -keyout server.key -out server.crt -nodes -days 365

After that you have to generate CSR by providing some information and This will generate the key file and certificates and will save then in /etc/postfix/ssl directory.

Now edit postfix configuration file which can be found at /etc/postfix/main.cf, with your favorite editor.

vi /etc/postfix/main.cf

and append these lines at the end of the file.

myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
home_mailbox = mail/
mynetworks = 127.0.0.0/8
inet_interfaces = all
inet_protocols = all
inet_interfaces = localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_key_file = /etc/postfix/ssl/server.key
smtpd_tls_cert_file = /etc/postfix/ssl/server.crt
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

Now open another configuration file /etc/postfix/master.cf

 nano  /etc/postfix/master.cf

and find the following lines in the configuration file.

    # service type  private unpriv  chroot  wakeup  maxproc command + args
    #               (yes)   (yes)   (yes)   (never) (100)
    # ==========================================================================
    smtp      inet  n       -       n       -       -       smtpd

Now add the following lines at just below these lines.

    submission     inet  n       -       n       -       -       smtpd
      -o syslog_name=postfix/submission
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
      -o milter_macro_daemon_name=ORIGINATING
    smtps     inet  n       -       n       -       -       smtpd
      -o syslog_name=postfix/smtps
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
      -o milter_macro_daemon_name=ORIGINATING

Now You have successfully installed and configured POSTFIX in your linux machine.

Next we will how to install dovecot on our upcoming tutorial. Thanks for reading our tutorial 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *