Postfix is commonly used on the fast and popular SMTP server. Postfix’s main role is to relay mail locally or outside the network to the intended destination. Sendmail, Postfix, and Qmail are some of the most common SMTP servers. By default Sendmail comes with CentOS / RHEL 5 pre-installed. It’ll need to be removed and Postfix installed.

Install Postfix

If Postfix isn’t already installed on your server, activate it using the command below. If already enabled and remove the sendemail:

[[email protected] ~]# yum remove sendmail
[[email protected] ~]# yum install postfix

You can make postfix as default MTA using the below command:

[[email protected] ~]# alternatives --set mta /usr/sbin/postfix

If you will get the outpout message like “/usr/sbin/postfix has not been configured as an alternative for mta“ and command will not work. Enter the below command:

[[email protected] ~]# alternatives --set mta /usr/sbin/sendmail.postfix

Configure Postfix

Now we are going to configure Postfix ,Edit Postfix configuration file /etc/postfix/ in any text editor and you have to make some changes:

[[email protected] ~]# /etc/postfix/
myhostname = or server ip
mydomain =
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost, $mydomain
mynetworks =, /32
relay_domains = $mydestination
home_mailbox = Maildir/

Edit the postfix configuration file after executing the above command, and make sure that all changes are done correctly.

Restart Postfix Service

When we will make any changes in configuration. We should restart or reload service to reflect those changes and read changes of configuration file:
[[email protected] ~]# service postfix restart
[[email protected] ~]# chkconfig postfix on

Open Firewall Port

If you are using Firewall or iptables on your server. Use below command to open port 25 for postfix:

[[email protected] ~]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
[[email protected] ~]# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 25 -j ACCEPT