Postfix+Cyrus-sasl+Dovecot (AS4)

实验拓扑  client-1============Mail(AS4)(postfix+dovecot)==============client-2

第一步: ====DNS的安装====
1、 安装相应的软件包
    bind-9,bind-utils,bind-libs,caching-name
2、 修改主配文件(建立区域)
      vi /etc/named.conf
             zone "wenchy.com" IN {
                type  maste
                file  "wenchy.zheng"; (正向解析文件库,默认不存在此文件库需要手动建立)
              allow-update { none; };
           };
            zone "7.168.192.in-addr.arpa" IN {
                type master;
                file "wenchy.fan";   (反向解析文件库,默认不存在此文件库需要手动建立)
              allow-update { none; };
           };
    
3、 建立正反解析库文件(将域名解析成ip地址)
    cd /var/named
    cp named.local wenchy.zheng
    vi wenchy.zheng
    在给文件下进行修改将localhost替换为ns.wenchy.com
    在末行模式输入:%s/localhost/ns.wenchy.com/g
    添加以下文件
              IN     MX O   mail.wenchy.com(0代表优先级且是最高的)
     ns     IN      A      192.168.7.167
     mail   IN      A      192.168.7.167

4、 建立反向解析库文件(将ip地址解析成域名。域名后面一定加上.才有效)
    cp wenchy.zheng  wenchy.fan
    添加以下文件
             167        IN   PTR      ns.wenchy.com.
             167        IN   PTR      mail.wenchy.com.
5、 创建完成后进行测试工作
    测试正反向解析文件
    name-checkzone   wenchy.com /var/named/wenchy.zheng
    name-checkzone   wenchy.com /var/named/wenchy.fan
            
6、 启动DNS服务: service named start
            
7、 指定DNSip的配置文件
    vi /etc/resolv.conf
    nameserver 127.0.0.1(或者是ip地址)
             
8、 重新启动DNS服务: service named restart


第二步:======Postfix、dovecot、Cyrus-sasl安装========
查看系统是否安装Postfix、dovecot、Cyrus-sasl,没有安装的话直接从光盘中安装
     rpm -qa |grep postfix或者dovecot(查看是否安装)
     安装:
     rpm -ivh postfix-*.rpm
     rpm -ivh cyrus-sasl-*.rpm
     rpm -ivh  dovecot-*.rpm


第三步:========cyrus-sasl服务===========
1)  首先系统自带的sendmail关掉
     /etc/init.d/sendmail  stop
     chkconfig  sendmail   off

2)   其次确定安装Cyrus-sasl后,启动该服务
     /etc/init.d/saslauthd start
     chkconfig saslauthd on

3)   测试是否成功
    testsaslauthd -u wenchy  -p  123   备注:这里wenchy是系统用户,123是wenchy的密码

若是提示:
0: OK "Success."
则说明已安装成功!备注:Cyrus-sasl的功能就是实现密码验证机制。


第四步:=========配置SMTP===========
Postfix作为邮件传输的一种,其主要的配置文档main.cf,位于/etc/postfix/main.cf,本人习惯于使用main.cf.default中的文件。

1、  cp /etc/postfix/main.cf.default  /etc/postfix/main.cf

2、  修改main.cf具体内容如下:

alias_maps = hash:/etc/aliases   //第23行
broken_sasl_auth_clients = yes     //第45行改
header_checks = regexp:/etc/postfix/header_checks  //第107行
mailbox_size_limit = 102400000    //第158行
mailq_path = /usr/bin/mailq.postfix    //第160行
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain      //第177行
mydomain = 域名   这里写wenchy.com    //在178行
myhostname = mail.域名  放在179行  mail.wenchy.com
mynetworks = 192.168.7.0/24, 127.0.0.0/8, 192.168.1.100/32  放在180行
myorigin = $mydomain     //第182行
newaliases_path = /usr/bin/newaliases.postfix    //第184行
readme_directory = /usr/share/doc/postfix-2.1.5/README_FILES      //第210行  备注:Postfix这里的版本是2.1.5,这里本人使用的AS4.
relay_domains = nanoconcept.net       //第219行
sample_directory = /usr/share/doc/postfix-2.1.5/samples  //第229行
sendmail_path = /usr/sbin/sendmail.postfix     //第233行
smtpd_sasl_auth_enable = yes     //第323行
smtpd_sasl_local_domain= ''   //第325行改为mail.wenchy.com
smtpd_recipient_restrictions =      //第318行
permit_sasl_authenticated,
permit_auth_destination,
permit_mynetworks,
check_relay_domain,
reject_rbl_client yahoo.com.tw,
reject_rbl_client cbl.anti-spam.org.cn,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unknown_sender_domain,
reject_unknown_recipient_domain,
reject(最好在一行写完)
smtpd_client_restrictions = permit_sasl_authenticated     //第296行
smtpd_sasl_security_options= noanonymous   326行
unknown_local_recipient_reject_code = 550  379行
 
3、 启动Postfix服务
    /etc/init.d/postfix  start
    chkconfig postfix on
4、 测试:此时可以正常发信,但是接受不到,如果发送不成功,可以查看一下文件
    /usr/lib/sasl2下是否存在两个文件:smtpd.conf、Sendmail.conf
[[email protected] sasl2]# cat Sendmail.conf
pwcheck_method:saslauthd
[[email protected] sasl2]# cat smtpd.conf
pwcheck_method: saslauthd
有时候Postfix找不到saslauthd文件的路径,所以在smtpd.conf中添加一条
saslauthd_path:/var/run/saslauthd/mux

第五步:=======配置POP3==============
Dovecot的作用是实现接受邮件的功能,安装rpm包后只修改一个地方就可以
1、  vi  /etc/dovecto.conf
     protocols = pop3 imap
2、  启动服务
     /etc/init.d/dovecot start
     chkconfig dovecot on
 
第六步:==========检查端口是否正常开启=============
postfix和dovecot已经配置好,使用netstat -ntl查看相应的端口,其中25、110经过加密后分别为465、995。

# telnet localhost 25 (远程连接到localhost端口为25)
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.wenchy.com ESMTP "Version not Available"
ehlo mail.wenchy.com (测试wenchy.com是否正常)
250-mail.wenchy.com
250-PIPELINING
250-SIZE 14336000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME
quit (退出本次测试)
221 Bye
Connection closed by foreign host.

# telnet localhost 110 (远程连接到localhost端口为110)
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK dovecot ready.
quit (退出本次测试)
+OK Logging out
Connection closed by foreign host.

总结:Postfix作为邮件传输的一种,配置相对于sendmail稍难,在这里最容易出现错误的是第四步,细心认真相信你一定能够成功,匆忙之间完成,相信有很多不足之处,敬请各位读者提出宝贵意见或建议,谢谢。

 

Postfix+Cyrus-sasl+Dovecot(AS4)

 

Postfix+Cyrus-sasl+Dovecot(AS4)

 

Postfix+Cyrus-sasl+Dovecot(AS4)