Postfix is free, open-source, fast and popular, SMTP mail transfer agent (MTA) which is using widely as alternative for Sendmail. Postfix implements a high-performance parallelized mail-delivery engine. Postfix is often combined with mailing-list software (such as Mailman). Postfix can run on UNIX-like systems including AIX, BSD, HP-UX, Linux, MacOS X, Solaris, and more. The latest version of Postfix 3.1.0 released on February 24, 2016 with few fixs.
1) Install Postfix
All the modern Linux distribution by default having postfix binary package on their own repository, so we can easily install by issuing below single command. By default Sendmail installed most distribution so remove it before processing postfix installation.
[Remove sendmail, if its not installed you can skip] # yum remove sendmail [Install Postfix] # yum install postfix
Add hostname entry into /etc/hosts file, so that it will discover the hostname when you are testing the postfix
# nano /etc/hosts 192.168.0.100 centos.2daygeek.com
2) Configure Postfix
/etc/postfix/main.cf file, uncomment below lines and make necessary change as per your domain, mail server details, networks & reset of the things are same.
# nano /etc/postfix/main.cf myhostname = centos.2daygeek.com mydomain = 2daygeek.com myorigin = $mydomain inet_interfaces = all inet_protocols = all mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks = 127.0.0.0/8 relay_domains = $mydestination home_mailbox = Maildir/
3) Restart Postfix
Once you have done appropriate above changes, just fire the below commands to restart postfix service to take effect the changes on new configuration.
[For SysVinit Systems] # service postfix restart # chkconfig postfix on [For systemd Systems] # systemctl restart postfix # systemctl enable postfix
4) Open Firewall Port
You have successfully installed & configured postfix mail server and you need to allow from firewall to work properly.
[For CentOS/RHEL 5 & 6, Fedora old systems] # 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 [For CentOS/RHEL 7, Fedora new systems] # firewall-cmd --permanent --add-service=smtp # firewall-cmd --reload
5) Test Postfix
Now you are ready to test your postfix mail service whether its working fine or not, use the below tricks.
# telnet localhost smtp Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 centos.2daygeek.com ESMTP Postfix ehlo localhost 250-centos.2daygeek.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN quit 221 2.0.0 Bye Connection closed by foreign host.
6) Test Postfix with User
Create user with /sbin/nologin shell to restrict login access.
# useradd -m magi -s /sbin/nologin # passwd magi # telnet localhost smtp Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 centos.2daygeek.com ESMTP Postfix ehlo localhost 250-centos.2daygeek.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN mail from: [email protected] 250 2.1.0 Ok rcpt to: [email protected] 250 2.1.5 Ok data 354 End data with
. This is test mail . 250 2.0.0 Ok: queued as B3520209D919 quit 221 2.0.0 Bye Connection closed by foreign host.
See the below output.
# cat /home/magi/Maildir/new/1456287731.Vfd00I159298M878550.centos.2daygeek.com Return-Path:
X-Original-To: magi Delivered-To: [email protected] Received: from centos.2daygeek.com (centos.2daygeek.com [IPv6:fe80::a00:27ff:fe76:2100]) by centos.2daygeek.com (Postfix) with ESMTP id A857E209D919 for ; Wed, 24 Feb 2016 09:51:42 +0530 (IST) Message-Id: <[email protected]> Date: Wed, 24 Feb 2016 09:51:42 +0530 (IST) From: [email protected] This is test mail