Setup or Migrate Postfix SMTP relay server on CentOS 6.5

Scenario:

You have a External SMTP relay host configured on older and physical Linux box which you would like to migrate to CentOS host in a virtualized environment. The older Linux box running on Ubuntu 6.06 + Postfix 2.2.10.  You want to migrate it to a virtual machine running CentOS 6.5 + Postfix 2.6.6.

OS and Postfix Version details of existing server:

root@NSHost1:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 6.06.2 LTS
Release:        6.06
Codename:       dapper
root@NSHost1:~#

root@NSHost1:~# postconf -d | grep mail_version
mail_version = 2.2.10
root@NSHost1:~#

OS and Postfix Version details of new server:
[root@DNSVM01 ~]# cat /etc/centos-release
CentOS release 6.5 (Final)
[root@DNSVM01 ~]#

[root@DNSVM01 ~]# postconf -d | grep mail_version
mail_version = 2.6.6
milter_macro_v = $mail_name $mail_version
[root@DNSVM01 ~]# rpm -q postfix
postfix-2.6.6-2.2.el6_1.x86_64
[root@DNSVM01 ~]#

Solution Implementation:

This essentially involves setting up Postfix afresh on the new VM host and then applying the setting from existing Postfix server. Followed by updating few other involved configuration files.  In my environment I have CentOS 6.5 running with Postfix and Iptables firewall pre-installed. Below are the steps to follow to implementation:

  • Apply below major changes to main.cf, to accomplish this you need to compare your existing main.cf with newly installed main.cf and make changes accordingly:
    • myhostname = mail.mylab.com
    • mydomain = .mylab.com
    • myorigin = $mydomain
    • Disable/comment all of: inet_interfaces lines
    • Disable/comment: mydestination
    • local_recipient_maps =
    • mynetworks_style = subnet
    • give your network/subnet values for: mynetworks = 127.0.0.0/8,
    • smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_policy_service inet:127.0.0.1:10024
    • relay_domains = mylab.com mylab.in mylab.uk mylab.ru
    • Disable/comment: relayhost = 172.22.7.31
    • alias_maps = hash:/etc/aliases
    • alias_database = hash:/etc/aliases
    • readme_directory = no
    • transport_maps = hash:/etc/postfix/transport
    • virtual_mailbox_limit = 104857600
    • mailbox_size_limit = 104857600
    • message_size_limit = 94371840
  • Restart the Postfix service and verify that its still running fine.
    • [root@DNSVM01 ~]# service postfix restart
      Shutting down postfix:                                     [  OK  ]
      Starting postfix:                                          [  OK  ]
      [root@DNSVM01 ~]#
  • Update the Aliases, take backup of the default alises file, apply the aliases from your existing SMTP server and then execute the newalises command as shown below:
    • root@DNSVM01 etc]# cp aliases aliases-initial-bkp
      [root@DNSVM01 etc]# newaliases
      [root@DNSVM01 etc]#
  • Update the Transport files, take backup of the default transport file, update the values from your existing SMTP server and then execute the postmap command as shown below:
    • [root@DNSVM01 postfix]# cp transport transport-initial-bkp
      [root@DNSVM01 postfix]# postmap /etc/postfix/transport
      [root@DNSVM01 postfix]#
  • Disable the iptables Firewall service, in my case I have the iptables firewall installed and running by default. I don’t require it on my SMTP server thus I am disabling it.
    • [root@DNSVM01 ~]# service iptables stop
      iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
      iptables: Flushing firewall rules:                         [  OK  ]
      iptables: Unloading modules:                               [  OK  ]
      [root@DNSVM01 ~]# chkconfig iptables off
      [root@DNSVM01 ~]#
    • If you need to support iptables Firewall then you may want to apply below rules to allow access to smtp port 25.
      • # iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 25 -j ACCEPT
        # iptables -A INPUT -m state –state NEW -m udp -p udp –dport 25 -j ACCEPT
  • Restart the Postfix service and verify that its still running fine.
    • [root@DNSVM01 ~]# service postfix restart
      Shutting down postfix:                                     [  OK  ]
      Starting postfix:                                          [  OK  ]
      [root@DNSVM01 ~]#
  • Now test sending emails to your internal and external email IDs.
    • [root@DNSVM01 postfix]# sendmail govardhan@gmail.com
      From: admin@mydomain.com
      Subject: Test mail after CentOS upgrade to 6.8
      Test mail from new PostFix server
      .
      [root@DNSVM01 postfix]#

 

 

References:

Leave a Reply

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