Sunteți pe pagina 1din 9

CentOS 6.

3 –install & configure


Postfix – Dovecot
Services et Administration des Réseaux

Realized by :Tarek BEN YOUNES


CentOS 6.3 –install & configure Postfix – Dovecot
Services et Administration des Réseaux

Introduction:
There are many different scenarios and combinations that can be used when setting up an email
server (far to many to cover here), so this TP makes some basic choices for you, such as the
software we will use (postfix and dovecot). Other options are required to be altered by the user,
such as your network addresses and domain names.

This TP uses postfix as the mail transport agent (MTA), as opposed to sendmail, the default MTA
for CentOS 5 (postfix is the default in CentOS 6). Dovecot is used to allow users to access their
email by either imap or pop protocols. We assume a domain name of esprit.com which should
be changed by the reader and can be either a real domain name for a fully qualified email server
or a fake domain name if you only wish to implement an internal mail server.

Objectifs:
 Add user accounts (user1 and unser2).
 Installing the MTA and MDA services.
 Configuring Postfix and Dovecot software module.
 Testing

Step 1 : Creating the users


CentOS 6.3 –install & configure Postfix – Dovecot |

Create the first user:

#useradd –m user1
#passwd user1

Create the second user :

#useradd –m user2
#passwd user2

1
Step 2 : Install Postfix server

Before installing postfix, you should check if it is already installed because postfix is the
default MTA in CentOS 6. If you’re using centos 5 then you have to remove sendmail which
is the default mail MTA and install positsfix.

*COMMANDS REQUIRED ONLY FOR CENTOS 5, IF YOUR USING CENTOS 6 SKIP THIS PART

[root@server ~]# yum remove sendmail

Postfix is installed by default. If it is not installed, use the below command to install postfix.

[root@server ~]# yum install postfix

Step 3 : Configuring iptables

By default Port number 25, 110 and 143 are closed so we need to allow access throw those
ports

Configuring the Firewall:

Enabling access on port SMPT (tcp/25), POP3 (tcp/110), and IMAP (tcp/143) in the iptables.

Edit the iptable configuration file:

# nano /etc/sysconfig/iptables
CentOS 6.3 –install & configure Postfix – Dovecot |

-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT


-A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

Restart the service after editing

Step 4 : Configuring Postfix

Open the postfix config file /etc/postfix/main.cf. Find the below lines and edit them as shown
below.
[root@server ~]# nano /etc/postfix/main.cf

#uncomment and enter your host name


myhostname = esprit.com

2
##line no 83 - uncomment and enter your domain name
mydomain = esprit.com

##line no 99 - uncomment
myorigin = $mydomain

#change to all
inet_interfaces = all

#line no 164 - add $domain at the end


mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

##line no 264 - uncomment and add your network range


mynetworks = 192.168.1.0/24, 127.0.0.0/8

##line no 419 - uncomment


home_mailbox = Maildir/

Now let’s take a look at each setting it turn to understand what we've just done:

myhostname: is the host name of the system ( the system is called mail or mail.esprit.com).

mydomain: is the domain name for the email server (it can be a real or fake domain name).

myorigin: is the domain name that locally-posted email appears to have come from and is
delivered to.

inet_interfaces: sets the network interfaces that Postfix can receive mail on. These need to
include at least localhost and the local domain.

mydestination: is the list of domains that will be delivered to ( this server is the final
destination for email addressed to these domains).
CentOS 6.3 –install & configure Postfix – Dovecot |

mynetworks: is a list of trusted IP addresses that may send or relay mail through the server.
Users attempting to send email through the server originating from IP addresses not listed
here will be rejected.

relay_domains: is a list of destination domains this system will relay mail to. By setting it to
be blank we ensure that our mail server isn't acting as an open relay for untrusted networks.

home_mailbox: sets the path of the mailbox relative to the users home directory and also
specifies the style of mailbox to be used. Postfix supports both Maildir and mbox formats and
readers are encouraged to read up on the merits of each for themselves.

3
Step 5 : Start the services

After finishing the configuration we should start the service and keep it on

[root@server ~]# service postfix start


Starting postfix: [ OK ]
[root@server ~]# chkconfig postfix on

Step 6 : Test Postfix using the command telnet

The commands shown in bold letters should be entered by the user.


Note: The dot after the test command is important.

[root@server ~]# telnet localhost smtp


Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server.ostechnix.com ESMTP Postfix
ehlo localhost
250-server.ostechnix.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<user1@esprit.com>
250 2.1.0 Ok
rcpt to:<user1@esprit.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
CentOS 6.3 –install & configure Postfix – Dovecot |

250 2.0.0 Ok: queued as 117113FF18


quit
221 2.0.0 Bye
Connection closed by foreign host.

Check Mail
Navigate to the user mail directory and check for the new mail.

[root@server ~]# cd /home/user1/Maildir/new/


[root@server new]# ls
1360236956.Vfd00I35afM181256.server.ostechnix.com
[root@server new]# cat 1360236956.Vfd00I35afM181256.esprit.com
Return-Path: <user1@esprit.com>
X-Original-To: user1
Delivered-To: user1@esprit.com
Received: from localhost (localhost [IPv6:::1])

4
by esprit.com (Postfix) with ESMTP id 117113FF18
for <user1>; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.ostechnix.com>
Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)
From: user1@esprit.com
To: undisclosed-recipients:;
test

Postfix working now.

Step 7 : Install Dovecot

Dovecot is used to allow users to access their email by either imap or pop protocols.

[root@server ~]# yum install dovecot

Step 8 : Configure Dovecot

Open the dovecot config file /etc/dovecot/dovecot.conf. Find and uncomment the line as
shown below.
[root@server ~]# nano /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp

Open the file /etc/dovecot/conf.d/10-mail.conf and uncomment the line as shown below.
[root@server ~]# nano /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir ##line no 24 - uncomment
CentOS 6.3 –install & configure Postfix – Dovecot |

Open the /etc/dovecot/conf.d/10-auth.conf and edit as shown below.


[root@server ~]# nano /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no ##line no 9 - uncomment and chang to no.
auth_mechanisms = plain login ##line no 97 - add the text "login"

Open the /etc/dovecot/conf.d/10-master.conf and edit as shown below.


unix_listener auth-userdb {
#mode = 0600
user = postfix ##line no 83 - uncomment and enter postfix
group = postfix ##line no 84 - uncomment and enter postfix

Start the dovecot service.


[root@server ~]# service dovecot start
Starting Dovecot Imap: [ OK ]
[root@server ~]# chkconfig dovecot on

5
Again, looking at each option:

protocols: specifies the protocols available to users to access their email. Dovecot supports
imap(s) and pop3(s), and any or all may be used.

mail_location: specifies the format and location of each users mailbox. Here we see we are
using maildir format and each user has their mailbox located at ~/Maildir. Examples for
mbox format are provided in the configuration file.

Step 9 : Test Dovecot using the command telnet

The commands shown in bold should be entered by the user.


[root@server ~]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 428
.
retr 1
+OK 428 octets
Return-Path: <user1@ostechnix.com>
X-Original-To: user1
Delivered-To: user1@ostechnix.com
Received: from localhost (localhost [IPv6:::1])
by esprit.com (Postfix) with ESMTP id 117113FF18
for <user1>; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
CentOS 6.3 –install & configure Postfix – Dovecot |

Message-Id: <20130207113547.117113FF18@esprit.com>
Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)
From: user1@esprit.com
To: undisclosed-recipients:;
test
.
quit
+OK Logging out.
Connection closed by foreign host.
[root@server ~]#

Required tests:
After testing postfix and dovecot with user1 now try to send a Mail from user 1 to user 2 and
check if user2 receives the mail.
Configuration « Outlook » sous windows :

6
Allez à : outils -> paramètres de compte -> nouveau

Configuration « Evolution » sous linux :


Allez à : Edit -> preferences -> add
CentOS 6.3 –install & configure Postfix – Dovecot |

7
Configuring services for IPv6

Configuring your system consists of two distinct steps. First, you need to enable IPv6 on your
network interface and second you need to configure your applications to bind to the right IPv6
addresses.

Many of the services will use IPv6 automatically if an IPv6 network is present at startup,
some services require explicit configuration to enable IPv6. I will shortly mention those that I
needed to configure on my own server.

Postfix
Postfix needs to be told to use IPv6 by adding the below configuration in /etc/postfix/main.cf:

inet_protocols = all

set inet_protocols = ipv6, ipv4 (if you’re dual stacking)

smtp_bind_address6 = (add your IPv6 Address Here)

Dovecot
To make Dovecot listen on IPv6 addresses it needs to have an explicit listen configuration added.
To make it listen on all addresses add the line in dovecot.conf:

listen = *, [::]
CentOS 6.3 –install & configure Postfix – Dovecot |

Before testing you should add the following rules in ip6tables:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

Testing
Confirm that you can connect OK to your IPv6 smtpd:

#telnet (add your IPv6 Address Here) 25

S-ar putea să vă placă și