November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Configure Postfix on CentOS/RHEL 6/5

Postfix is fast and popular SMTP server widely used. The main job of postfix is to relay mail locally or to intended destination outside the network. Some of the most popular SMTP servers are Sendmail, Postfix and Qmail. By default Sendmail comes pre-installed with CentOS/RHEL 5. We will need to remove it and install Postfix. On CentOS/RHEL 6 ‘postfix’ are installed by default, so there are no need to install it

Step 1: Install Postfix

If Postfix not already installed on your machine, Install it using following command. Also remove sendmail if already installed.

# yum remove sendmail
# yum install postfix 

Make postfix as default MTA for your system using following command

# alternatives --set mta /usr/sbin/postfix

If above command not work and you get output as “/usr/sbin/postfix has not been configured as an alternative for mta“. Use below command to do the same else skip it

# alternatives --set mta /usr/sbin/sendmail.postfix
Step 2: Configure Postfix

Let’s start postfix configuration. Edit postfix configuration file /etc/postfix/main.cf in your favorite editor and make following changes. We can also use command line tool ‘postconf’ to do the same without editing configuration file.

# postconf -e "myhostname = mail.tecadmin.net"
# postconf -e "mydomain = tecadmin.net"
# postconf -e "myorigin = $mydomain"
# postconf -e "inet_interfaces = all"
# postconf -e "mydestination = $myhostname, localhost, $mydomain"
# postconf -e "mynetworks = 127.0.0.0/8, /32"
# postconf -e "relay_domains = $mydestination"
# postconf -e "home_mailbox = Maildir/"

After executing above command edit postfix configuration file and make sure all changes done properly.

Step 3: Restart Postfix Service

As we have done basic postfix configuration, So restart postfix service to read changes of configuration. Also configure to auto start on system boot.

# service postfix restart 
# chkconfig postfix on
Step 4: Open Firewall Port

Now if your system is configured to use iptables firewall, So add firewall rules to make postfix accessible from outside, using following commands.

# 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 

Thanks for using this article.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>