Installation and Configuration of Postfix Server on Centos 6.5 Part-1/4

Installation and Configuration of Postfix Server on Centos 6.5 Part-1/4

by -
0 1927

Follow the steps to install and configure postfix server:

Make entry for hostname :

[root@pc1 ~]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.102   pc1.6987.in

[root@pc1 ~]# vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=pc1.6987.in
GATEWAY=192.168.0.254

The /etc/nsswitch.conf file is used to configure which services are to be used to determine information such as hostnames etc.Edit the nsswitch.conf file vi /etc/nsswitch.conf and change the hosts line to read:

"hosts:      files dns"

Which means, for programs that want to resolve an address they should use the file feature first i.e. /etc/hosts file, and then DNS servers if file is not available or can’t resolve the address.

[root@pc1 ~]# vi /etc/nsswitch.conf | grep hosts

#hosts:     db files nisplus nis dns
hosts:      files dns

Change your MTA:

A Mail Transfer Agent (MTA) is a software that transfers electronic mail messages from one computer to another using a client server application architecture. An MTA is also called by a few other names such as – a Message Transfer Agent, Mail Relay, and Mail Transport Agent.
Some of the popular MTAs in use are Sendmail, Exim, and Postfix.

Switch Between MTA:

Method 1: By Using “alternatives” command:

you can change the default MTA by using the alternatives command.

To display which MTA alternative is in use:

[root@pc1 ~]# alternatives –display mta

To choose from the available MTA alternatives from the command line :

[root@pc1 ~]# alternatives –config mta

To setup Postfix as the default mail system

[root@pc1 ~]# alternatives –set mta /usr/sbin/sendmail.postfix

Method 2 : “system-switch-mail” command

Once you have download and installed the system-switch-mail package, you can run one of the corresponding tools to switch between the different MTAs installed in your system. When you run the system-switch-mail command, you will see a self-explanatory selection dialog that allows you to switch to another MTA installed in your system.

Download “system-switch-mail” rpm from website:

[root@pc1 ~]# wget ftp://195.220.108.108/linux/centos/5.11/os/x86_64/CentOS/system-switch-mail-0.5.25-13.el5.noarch.rpm

[root@pc1 ~]# rpm -ivh system-switch-mail-0.5.25-13.el5.noarch.rpm
warning: system-switch-mail-0.5.25-13.el5.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
Preparing…               ########################################### [100%]
1:system-switch-mail     ########################################### [100%]

Now, Install the following required packages:

[root@pc1 ~]# yum install php-* -y

[root@pc1 ~]# yum install mysql-server -y

[root@pc1 ~]# yum install dovecot dovecot-mysql -y

[root@pc1 ~]# yum -y install php-mysql php-imap php-ldap php-mbstring -y

Download squirrelmail package from internet:

[root@pc1 ~]# wget http://squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fprdownloads.sourceforge.net%2Fsquirrelmail%2Fsquirrelmail-webmail-1.4.22.tar.gz

We will install postfix through centosplus repository for this we need to make some changes in CentOS-Base.repo file.Add the following lines in CentOS-Base.repo file for CentosPlus repos for postfix:

[root@pc1 ~]# vim /etc/yum.repos.d/CentOS-Base.repo

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6[base]
includepkgs=postfix-*

First remove postfix package which is default install:
[root@pc1 ~]# yum remove postfix

And then install postfix through centosplus repository:
[root@pc1 ~]# yum install -y –enablerepo=centosplus postfix

————————verify the postfix package installed————

[root@pc1 ~]# rpm -qa postfix
postfix-2.6.6-6.0.1.el6.centos.x86_64
[root@pc1 ~]# rpm -qi postfix

Verify the postfix package support the mysql:

[root@pc1 ~]#  postconf -m
btree
cidr
environ
hash
ldap
mysql   <– this means the postfix package support the mysql database
nis
pcre
pgsql
proxy
regexp
static
unix

Run command “system-switch-mail” (please select postfix):

[root@pc1 ~]# system-switch-mail

Verify the setting of our new MTA:

[root@pc1 ~]# alternatives –display mta
mta – status is manual.
link currently points to /usr/sbin/sendmail.postfix
/usr/sbin/sendmail.postfix – priority 30
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-pam: /etc/pam.d/smtp.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib/sendmail.postfix
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
Current `best’ version is /usr/sbin/sendmail.postfix.

Check if our mailq, sendmail and aliases have the correct configured with postfix:

[root@pc1 ~]# ls -l  /etc/alternatives/mta-*
lrwxrwxrwx. 1 root root 40 Oct 18 19:31 /etc/alternatives/mta-aliasesman -> /usr/share/man/man5/aliases.postfix.5.gz
lrwxrwxrwx. 1 root root 22 Oct 18 19:31 /etc/alternatives/mta-mailq -> /usr/bin/mailq.postfix
lrwxrwxrwx. 1 root root 38 Oct 18 19:31 /etc/alternatives/mta-mailqman -> /usr/share/man/man1/mailq.postfix.1.gz
lrwxrwxrwx. 1 root root 27 Oct 18 19:31 /etc/alternatives/mta-newaliases -> /usr/bin/newaliases.postfix
lrwxrwxrwx. 1 root root 43 Oct 18 19:31 /etc/alternatives/mta-newaliasesman -> /usr/share/man/man1/newaliases.postfix.1.gz
lrwxrwxrwx. 1 root root 23 Oct 18 19:31 /etc/alternatives/mta-pam -> /etc/pam.d/smtp.postfix
lrwxrwxrwx. 1 root root 22 Oct 18 19:31 /etc/alternatives/mta-rmail -> /usr/bin/rmail.postfix
lrwxrwxrwx. 1 root root 25 Oct 18 19:31 /etc/alternatives/mta-sendmail -> /usr/lib/sendmail.postfix
lrwxrwxrwx. 1 root root 41 Oct 18 19:31 /etc/alternatives/mta-sendmailman -> /usr/share/man/man1/sendmail.postfix.1.gz

Remove Sendmail package if installed:
[root@pc1 ~]# yum remove sendmail

Create Mysql Username, Password and Postfixadmin database,for this first start the mysql service:
[root@pc1 ~]# service mysqld start
[root@pc1 ~]# chkconfig mysqld on

Now, Set root password for mysql:
[root@pc1 ~]# mysqladmin -u root password india@123

Login to mysql using root user:
[root@pc1 ~]# mysql -u root -p
Enter password:

##Now, Create Postfixadmin database:

mysql> CREATE DATABASE postfix;
Query OK, 1 row affected (0.00 sec)

##Create a new user “mail” having password “india@123”:

mysql> CREATE USER mail@localhost IDENTIFIED BY ‘india@123’;
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON postfix.* TO mail;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+——————————+
| Database               |
+——————————+
| information_schema |
| mysql                      |
| postfix                    |
| test                       |
+——————————-+
4 rows in set (0.00 sec)
mysql> quit

Now, create a non-root user for Postfixadmin:
[root@pc1 ~]# useradd vmail  -s /sbin/nologin

Check id for user vmail:
[root@pc1 ~]# id vmail
uid=500(vmail) gid=500(vmail) groups=500(vmail)

Let’s, Configure the postfix main.cf file:

Open config file and change the following lines:

[root@pc1 ~]# vim /etc/postfix/main.cf
99 myorigin = $mydomain
116 inet_interfaces = all
164 mydestination = $myhostname, localhost.$mydomain, localhost
264 mynetworks = 192.168.0.0/24, 127.0.0.0/8                         <–this is the ip that can used to send email

Add the following lines at the end to main.cf file, this will tell the system to look for postfix configuration, its virtual domains, virtual users and aliases.
The virtual_uid_maps : static:500. This 500 is the id of my vmail. Change this if you have different id for your uid and gid.
[root@pc1 ~]# vim /etc/postfix/main.cf
At the end of the file add the following lines:

virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-users.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:500
virtual_gid_maps = static:500

Configure the postfix mysql-domians.cf file:
The following configuration will create mysql-domains.cf. This will enable postfixadmin to create virtual domain.

[root@pc1 ~]# vim /etc/postfix/mysql-domains.cf
host = localhost
user = mail
password = india@123
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = ‘0’ and active = ‘1’

:wq! (save&exit)

Configure the postfix mysql-users.cf file:
The following configuration will create mysql-users.cf. This will enable postfixadmin create virtual users.

[root@pc1 ~]# vim /etc/postfix/mysql-users.cf
host = localhost
user = mail
password = india@123
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active = ‘1’
result_format = %sMaildir/

:wq! (save&exit)

Configure the postfix mysql-alias.cf file:
The last part we should do now is to connect the postfixadmin to mysql.

[root@pc1 ~]# vim /etc/postfix/mysql-aliases.cf
host = localhost
user = mail
password = india@123
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = ‘1’

:wq! (save&exit)
[root@pc1 ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
[root@pc1 ~]# chkconfig postfix on

check for dovecot package:
[root@pc1 ~]# rpm -qa dovecot
dovecot-2.0.9-19.el6_7.2.x86_64

Create the file /etc/dovecot-mysql.conf containing the lines below. You might need to change your username, password and db user:

[root@pc1 ~]# vim /etc/dovecot/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix user=mail password=india@123
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = ‘%u’ AND active = ‘1’

Create a backup copy of dovecot.conf file and the edit the dovecot.conf file:
[root@pc1 ~]# cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.org

[root@pc1 ~]# vim /etc/dovecot/dovecot.conf
(At the end of file add the following lines)
auth_username_format = %Lu

passdb {
driver = sql
args = /etc/dovecot/dovecot-mysql.conf
}
userdb {
driver = static
args = uid=500 gid=500 home=/home/vmail/%d/%n
}
mail_location = Maildir:~/Maildir

Edit 10-mail.conf file:
[root@pc1 ~]#  vim /etc/dovecot/conf.d/10-mail.conf
mail_location = Maildir:~/Maildir
:wq!(save&exit).

Edit 10-auth.conf file:
[root@pc1 ~]#  vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login
:wq!(save&exit).

Restart dovecot service:
[root@pc1 ~]# service dovecot restart
Stopping Dovecot Imap:                                     [  OK  ]
Starting Dovecot Imap:                                     [  OK  ]
[root@pc1 ~]# chkconfig dovecot on

Postfixadmin installation and configuration:
Postfix Admin is a web based interface used to manage mailboxes, virtual domains and aliases. It also features support for vacation/out-of-the-office messages.
It requires PHP, Postfix and one of MySQL or PostgreSQL.

Postfixadmin Installation:
Download postfixadmin package from internet:

[root@pc1 ~]# mkdir /software
[root@pc1 ~]# cd /software
[root@pc1 software]# wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.3.3/postfixadmin-2.3.3.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpostfixadmin%2F&ts=1311080667&use_mirror=space

[root@pc1 software]# ls
postfixadmin-2.3.3.tar.gz
[root@pc1 software]# tar -zxvf postfixadmin-2.3.3.tar.gz
[root@pc1 software]# mv postfixadmin-2.3.3 postfixadmin

Configure postfixadmin configuration file:

[root@pc1 ~]# cp /software/postfixadmin/config.inc.php /software/postfixadmin/config.inc.php.ori
[root@pc1 ~]# vim /software/postfixadmin/config.inc.php

26 $CONF[‘configured’] = true;
36 $CONF[‘postfix_admin_url’] = ‘/postfixadmin’;
49 $CONF[‘database_type’] = ‘mysqli’;
50 $CONF[‘database_host’] = ‘localhost’;
51 $CONF[‘database_user’] = ‘mail’;
52 $CONF[‘database_password’] = ‘change-your-new-password-here’; (MAIL USER PASS) india@123
53 $CONF[‘database_name’] = ‘postfix’;
100 $CONF[‘encrypt’] = ‘cleartext’;
144 $CONF[‘domain_path’] = ‘YES’;
150 $CONF[‘domain_in_mailbox’] = ‘NO’;
303 $CONF[’emailcheck_resolve_domain’]=’NO’;

:wq!(Save&exit).

Creating apache aliase for Postfixadmin:
[root@pc1 ~]# echo “Alias /postfixadmin /software/postfixadmin” > /etc/httpd/conf.d/postfixadmin.conf

[root@pc1 ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@pc1 ~]# chkconfig httpd on
[root@pc1 ~]# service postfix status

LOGIN POSTFIXADMIN:

1

2

Enter setup password and click on Generate password hash.Now, copy the hash password and put into the config.inc.php file:

[root@pc1 ~]# vim  /software/postfixadmin/config.inc.php
Comment line 31:
31 #$CONF[‘setup_password’] = ‘changeme’;
And then next to line 31 add the following line:
32 $CONF[‘setup_password’] = ‘2651d038622ffdd436ceca52ae49e89a:002febb13f23bf632aa3609f083f500507cabce9’;

:wq!(Save&exit).

Next: TO CREATE A SUPER USER:
Open:
http://192.168.0.159/postfixadmin/setup.php
Enter your previous entered setup password and then add Admin user with password and then click on add button, like this and your admin user will be added:
Setup password: linux@123
Admin: kvit@6987.in
Password: redhat

3

After this entry remove setup.php from /software/postfixadmin/setup.php:
and Open with:
http://192.168.0.159/postfixadmin
and login with your admin@6987.in user with password.

4

Now, you will notice this screen after login with Admin user:

5

Now, lets create Domain for this click on Domain List and then click New Domain:

6

After this enter your domain name which you want to add and then description and click on add domain button:
In Aliases and Mailbox filed enter “0” which means you can create unlimited number of aliases and mailbox for users.

7

Lets, add one more domain to the list:

8

Now as we added two domains, click on domain list will show us the added domain list:

9

Now click on Admin List and then click on New Admin:
Add new domain admin for domain 6987.in.

Admin:root@6987.in
Password:  redhat
Then select 6987.in domain from the list.
Then click add admin button.

Add another new domain admin for domain kvit.in.
Admin:root@kvit.in
Password:  redhat
Then select kvit.in domain from the list.

Then click add admin button.10

11

After adding the two new admins for two domains, let’s check the list of the added admins by clicking on admin list:

12

Now logout from the admin panel and try to login to specific domain panel with the help of newly created admin of both domains, let’s for example try with admin@kvit.in:

13
This will display panel only for domain kvit.in. Now, you can create users for domain kvit.in.
Let’s create mailbox for kvit.in domain, click on virtual list and then click on add mailbox button:

14

15

Once we created user1 in kvit.in domain, let’s login with squirrelmail.

Squirrelmail Installation:
Packages required to install squirrelmail are:
squirrelmail.noarch 0:1.4.22-4.el6
php-pear-DB.noarch 0:1.7.13-3.el6
mod_ssl
Or
[root@pc1 ~]# tar -zxvf squirrelmail-webmail-1.4.22.tar.gz
[root@pc1 ~]# cd squirrelmail-webmail-1.4.22/config
[root@pc1 config]# ./conf.pl
Next, you will see the following screen. We can start to configure the squirrelmail’s server setting. Press <2> and press <Enter Button>.
Note: You can customize the squirrelmail to your organization preference such as logos, organization name etc. under Main Menu’s option 1.
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Main Menu —
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color off
S Save data
Q Quit

Command >> 2
Next, press <1> to configure our domain name
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Server Settings
General
——-
1. Domain : localhost
2. Invert Time : false
3. Sendmail or SMTP : Sendmail

A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail

R Return to Main Menu
C Turn color off
S Save data
Q Quit

Command >> 1
The domain name is the suffix at the end of all email addresses. If
for example, your email address is jdoe@example.com, then your domain
would be example.com.
[localhost]: linuxsolutions.org.in
press S for save

In squirrelmail if you have not installed mod_ssl package then you have to comment out these lines in:

[root@pc1 ~]# vim /etc/httpd/conf.d/squirrelmail.conf

# this section makes squirrelmail use https connections only, for this you
# need to have mod_ssl installed. If you want to use unsecure http
# connections, just remove this section:
<Directory /usr/share/squirrelmail>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</Directory>

Verify the PostfixAdmin installation:

[root@pc1 ~]# postmap -q 6987.in mysql:/etc/postfix/mysql-domains.cf
6987.in
[root@pc1 ~]# postmap -q kvit.in mysql:/etc/postfix/mysql-domains.cf
kvit.in

Verify virtual domains created by Postfixadmin:
[root@pc1 ~]# cd /home/vmail/
[root@pc1 vmail]# ls -l
total 8
drwx—— 4 vmail vmail 4096 Oct 23 21:59 6987.in
drwx—— 4 vmail vmail 4096 Oct 23 22:00 kvit.in            <– 2 virtual domains created

Check inside the Mysql Database and Verify the virtual users’ password created by PostfixAdmin in Mysql:
[root@pc1 ~]# mysql -u root -p
Enter password:

16

The password created in not encrypted .This will ensure that our POP3 can verify the password. Else, go to /software/postfixadmin/config.inc.php again check on line 100.

100 $CONF[‘encrypt’] = ‘cleartext’;

SMTP RELAY TEST:

[root@pc1 ~]# telnet localhost 25
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220 pc1.6987.in ESMTP Postfix
helo client
250 pc1.6987.in
MAIL FROM:user1@6987.in
250 2.1.0 Ok
rcpt to:user2@6987.in
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello how r u?
.
250 2.0.0 Ok: queued as 2EABA1FD3A
If the connection fail when performing smtp relay test on other pc. Please go to /etc/postfix/main.cf  then check on the following—-
Line 93 myorigin = $mydomain
Line 110 inet_interfaces = all  <– make sure this is not inet_interface=localhost
Line 155 mydestination = $myhostname, localhost.$mydomain, localhost
Line 255 mynetworks = 192.168.139.0/24, 127.0.0.0/8 <–this is the ip that can used to sent email

——————————–Pop3 test————————————————
[root@kvit ~]# telnet localhost 110
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
+OK Dovecot ready.
user user1@6987.in
+OK
pass 123
+OK Logged in.
list
+OK 6 messages:
1 775
2 617
3 617
quit
+OK Logging out.

Download PDF

NO COMMENTS

Leave a Reply

Required Captcha *