Centos X64 6.9版本安装postfix2.6.6+dovecot+openwebmail
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos X64 6.9版本安装postfix2.6.6+dovecot+openwebmail相关的知识,希望对你有一定的参考价值。
Centos X64 6.9版本安装postfix2.6.6+dovecot+openwebmail
测试完成日期:2017.06.07
附件为配置文件,可以直接使用
使用系统自带的帐号、密码文件进行认证,不用安装mysql,方法简单。
测试发现Centos 6.5\6.9 x64都使用SHA-512加密。
一、先卸载sendmain
[[email protected] ~]# yum remove sendmail
# chkconfig sendmail off
二、安装postfix ,dovecot,cyrus-sasl
[[email protected] ~]# yum -y install postfix perl
[[email protected] ~]# yum -y install dovecot dovecot-devel dovecot-mysql pam-devel
[[email protected] ~]# yum -y install cyrus-sasl cyrus-sasl-plain cyrus-sasl-md5 cyrus-sasl-lib
查看postfix版本
[[email protected]]# rpm -qa |grep postfix
postfix-2.6.6-8.el6.x86_64
postfix配置文件
[[email protected] ~]# vi /etc/postfix/main.cf
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mail.dongying.com
mydomain = dongying.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain,$mydomain,dongying.com
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8,120.25.162.161/32,192.168.88.0/24
smtpd_banner= "Version not Available"
relay_domains = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,mail.$mydomain
disable_vrfy_command=yes
broken_sasl_auth_clients = yes
header_checks = pcre:/etc/postfix/header_checks
smtpd_error_sleep_time = 1s
smtpd_soft_error_limit = 10
smtpd_hard_error_limit = 10
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_delay_reject=yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_path = smtpd
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,
reject_invalid_hostname, reject_non_fqdn_sender,
reject_non_fqdn_recipient, reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_unauth_pipelining, reject_unauth_destination,
check_client_access hash:/etc/postfix/client_checks,
check_sender_access hash:/etc/postfix/sender_checks,
reject_rbl_client cblless.anti-spam.org.cn,
reject_rbl_client ix.dnsbl.manitu.net,
reject_rbl_Client sbl-xbl.spamhaus.org,
reject_rbl_Client bl.spamcop.net,
reject_rbl_client noptr.spamrats.com,
reject_rbl_client cbl.abuseat.org,
check_policy_service unix:private/policy-spf,permit
message_size_limit = 41943040
mailbox_size_limit = 500000000
main.cf参数说明如下:
一、注意,以下四行,为你公司的域名及IP信息,请按你实际地址来更改好。
myhostname = mail.dongying.com
mydomain = dongying.com
mydestination = $myhostname, localhost.$mydomain,$mydomain,dongying.com
mynetworks = 127.0.0.0/8,120.25.162.161/32,192.168.88.0/24
二、注意,以下六行,为反垃圾邮件规则,使用国际反垃圾邮件联盟的域名,一定要加上。
reject_rbl_client cblless.anti-spam.org.cn, reject_rbl_client ix.dnsbl.manitu.net,
reject_rbl_Client sbl-xbl.spamhaus.org,
reject_rbl_Client bl.spamcop.net,
reject_rbl_client noptr.spamrats.com,
reject_rbl_client cbl.abuseat.org,
三、对拒绝服务攻击的防范。下面三行参数
smtpd_error_sleep_time = 1s
smtpd_soft_error_limit = 10
smtpd_hard_error_limit = 10
#postfix能累计客户端曾经发生错误的次数,对于可疑的客户端,postfix会主动延迟响应的时间
而且错误次数越多,延迟时间越长。这些都是通过下面的参数进行设置
参数说明:初次的延迟时间由smptd_error_sleep_time参数决定(默认1秒),当客户端累积了
smtpd_soft_error_limit次错误之后,往后每发生一次错误,postfix就多延迟1秒,当错误次数
超过smtpd_hard_error_limit时,postfix就放弃该客户端,并主动断线
四、黑白名单的配置,减少重要客户邮件被当成垃圾邮件。下面二行参数
check_client_access hash:/etc/postfix/client_checks,
check_sender_access hash:/etc/postfix/sender_checks,
postfxi里有2个完全不同的参数来实现白名单黑名单,client_checks,通过客户端ip,ip段或主机名屏蔽.
sender_checks,通过判断发件人邮件地址(位于from段)屏蔽,建议将经常来往客户的邮箱域名地址加入到sender_checks文件中去。 ok为允许,reject为拒绝.
上面2个文件只要有修改,记得运行postmap命令,以便postfix能能查找得到
[[email protected] postfix]# postmap /etc/postfix/client_checks
[[email protected] postfix]# postmap /etc/postfix/sender_checks
[[email protected] postfix]# cat sender_checks
gmail.com ok
example.com REJECT env. from addr [email protected] rejected
.example.com REJECT env. from addr [email protected] rejected
[email protected] REJECT We don‘t want your email
[[email protected] postfix]# cat client_checks
61.145.211.19 ok
.example.com REJECT No spammers, from your subdomain
五、SPF反垃圾邮件认证。
check_policy_service unix:private/policy-spf
指定域名的spf认证,需要在域名中心做“txt域名解析记录”
六、邮件头查检,过滤指定内容的邮件。
header_checks = pcre:/etc/postfix/header_checks
邮件头查检,spf认证没通过的邮件,直接丢弃
[[email protected] postfix]# cat /etc/postfix/header_checks
/Received-SPF: softfail/ REJECT
七、邮箱大小及附件的设定。
message_size_limit = 41943040
mailbox_size_limit = 500000000
是限制使用者邮件目录的大小,也就是能够在服务器上保存邮件的大小500M,那么message_size_limit限制邮件大小是41943040/1024/1024=40M,
附件main.cf文件为加入了spf反垃圾验证,可直接使用
八、生成/etc/postfix/aliases别名数据库,解决出现NIS domain name not set - NIS lookups disabled警告信息
[[email protected] postfix]# touch /etc/postfix/aliases
[[email protected] postfix]# postalias /etc/postfix/aliases
下面2行加入到main.cf中即可
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
==========================================================================
再进行下面的配置
Postfix配置SPF防发件人欺骗
http://www.haiyun.me/archives/postfix-spf-spoof.html (参考文章)
首先,需要进域名中心,加一笔TXT记录,值为 v=spf1 mx -all
同时将MX等记录也配置好,方便收发邮件。按下图设定5项红色框中的即可
[[email protected] postfix]# yum install perl-Mail-SPF perl-Sys-Hostname-Long
[[email protected] postfix]# wget https://launchpad.net/postfix-policyd-spf-perl/trunk/release2.010/+download/postfix-policyd-spf-perl-2.010.tar.gz
[[email protected] postfix]# tar zxvf postfix-policyd-spf-perl-2.010.tar.gz
[[email protected] postfix]# mv postfix-policyd-spf-perl-2.010/postfix-policyd-spf-perl /usr/sbin/
[[email protected] postfix]# chmod +x /usr/sbin/postfix-policyd-spf-perl
开启postfix-policyd-spf-perl服务:
[[email protected] postfix]# vi /etc/postfix/master.cf
## spf check
policy-spf unix - n n - - spawn
user=nobody argv=/usr/sbin/postfix-policyd-spf-perl
编辑Postfix主配置文件添加SPF过滤规则:
[[email protected] postfix]# vi /etc/postfix/main.cf
smtpd_recipient_restrictions =
permit_mynetworks,
........
check_policy_service unix:private/policy-spf,permit
查看邮件日志
[[email protected] postfix]# tail -f /var/log/maillog
#下为正确的记录,如下,有红色Received-SPF: pass表示通过。
Jun 7 17:25:56 host-cn postfix/smtpd[12947]: connect from smtpbg331.qq.com[14.17.43.223]
Jun 7 17:26:04 host-cn postfix/policy-spf[12952]: Policy action=PREPEND Received-SPF: pass (qq.com: Sender is authorized to use ‘[email protected]‘ in ‘mfrom‘ identity (mechanism ‘include:spf.mail.qq.com‘ matched)) receiver=unknown; identity=mailfrom; envelope-from="[email protected]"; helo=smtpbg331.qq.com; client-ip=14.17.43.223
Jun 7 17:26:04 host-cn postfix/smtpd[12947]: 05CBEC0E16: client=smtpbg331.qq.com[14.17.43.223]
Jun 7 17:26:04 host-cn postfix/cleanup[12955]: 05CBEC0E16: message-id=<[email protected]>
Jun 7 17:26:04 host-cn postfix/qmgr[12946]: 05CBEC0E16: from=<[email protected]>, size=2286, nrcpt=1 (queue active)
Jun 7 17:26:04 host-cn postfix/smtpd[12947]: disconnect from smtpbg331.qq.com[14.17.43.223]
Jun 7 17:26:04 host-cn postfix/local[12956]: 05CBEC0E16: to=<[email protected]>, relay=local, delay=7.6, delays=7.6/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 7 17:26:04 host-cn postfix/qmgr[12946]: 05CBEC0E16: removed
#以下为错误信息
postfix/policy-spf[15857]: Policy action=PREPEND Received-SPF: softfail (www.haiyun.me: Sender is not authorized by default
将postfix加入到root组
[[email protected] postfix]# usermod -G root postfix
再检查配置文件,执行命令 /usr/sbin/postconf -n
将postfix设定为MTA
[[email protected] postfix]# alternatives –set mta /usr/sbin/sendmail.postfix
查看MTA的方法:
[[email protected] postfix]# alternatives --display mta
将Postfix设置为自启动
[[email protected] postfix]# chkconfig --add postfix
[[email protected] postfix]# chkconfig postfix on
[[email protected] postfix]# chkconfig saslauthd on
查看是否有安装认证
[[email protected] postfix]# rpm -qa|grep cyrus
cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-md5-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64
配置认证机制, 在文件内容中加入如下三行
[[email protected] postfix]# vi /etc/sasl2/smtpd.conf
log_level: 3
pwcheck_method: saslauthd
mech_list: plain login
[[email protected] postfix]# vi /etc/sysconfig/saslauthd 在文件内容中,有如下两行
MECH=shadow
FLAGS=
再启动认证服务
[[email protected] postfix]# service saslauthd start
建立用户
[[email protected] postfix]# useradd evan
[[email protected] postfix]# passwd evan
为了使添加的邮箱用户有在/var/spool/mail目录下的权限,需要:
[[email protected] postfix]# usermod -g mail evan
验证密码是否成功,格式如下,例如:
[[email protected] postfix]# testsaslauthd -u evan -p miserp007
0: OK "Success."
显示上面结果,表示验证成功。
启动postfix服务
[[email protected] postfix]# service postfix start
==================================================================================
二、安装与配置dovecot
[[email protected] postfix]# yum install -y dovecot dovecot-devel dovecot-mysql pam-devel
查看版本
[[email protected] postfix]# dovecot --version
2.0.9
只需要配置一个dovecot.conf文件即可,进行普通认证,关掉SSL
[[email protected] dovecot]# vi /etc/dovecot/dovecot.conf
listen = *
protocols = pop3 imap
default_login_user=postfix
default_internal_user=postfix
disable_plaintext_auth = no
ssl = no
mail_privileged_group = mail
mail_location = mbox:~/mail:INBOX=/var/mail/%u
userdb {
driver = passwd
args = blocking=no
}
passdb {
driver = shadow
}
将conf.d文件夹改名,不需要使用里面的配置文件
[[email protected] dovecot]# cd /etc/dovecot/
[[email protected] dovecot]# mv conf.d conf.d.bak
检查认证文件,默认是不需要更改的
[[email protected] dovecot]# vi /etc/pam.d/dovecot
auth required pam_nologin.so
auth include password-auth
account include password-auth
session include password-auth
将dovecot设置为自启动
[[email protected] dovecot]# service dovecot start
[[email protected] dovecot]# chkconfig dovecot on
[[email protected] dovecot]# chkconfig --add dovecot
测试是否可以正常登录dovecot
[[email protected] dovecot]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is ‘^]‘.
+OK Dovecot ready.
user evan 手动打入登录用户名
+OK
pass miserp007 手动打入用户密码
+OK Logged in. 此处表示已经登录进来了
quit 退出去
+OK Logging out.
查看邮件日志
[[email protected] dovecot]# tail -f /var/log/maillog
============================================================================
三、安装openwebmail
生成openwebmail安装源
[[email protected] dovecot]# vi /etc/yum.repos.d/openwebmail.repo
[openwebmail]
## Thomas Chung
## 2008.05.29
name=Openwebmail for Fedora or Enterprise Linux
baseurl=http://openwebmail.org/openwebmail/download/redhat/rpm/release/
enabled=1
gpgcheck=1
gpgkey=http://openwebmail.org/openwebmail/download/redhat/rpm/release/RPM-GPG-KEY-openwebmail
#metadata_expire=0
[[email protected] dovecot]# yum install openwebmail
安装完成后,提示运行openwebmail-tool.pl --init
[[email protected] dovecot]# cd /var/www/cgi-bin/openwebmail/
更改dbm.conf内容后保存
[[email protected] openwebmail]# vi /var/www/cgi-bin/openwebmail/etc/dbm.conf
dbm_ext .db
dbmopen_ext .db
dbmopen_haslock no
[[email protected] openwebmail]# cd /var/www/cgi-bin/openwebmail/
执行初始化
[[email protected] openwebmail]# ./openwebmail-tool.pl --init
Send the site report?(Y/n) 请回答y
最后完成安装过程
修改openwebmail语言选项
[[email protected] openwebmail]# cd /var/www/cgi-bin/openwebmail/etc
[[email protected] etc]# vi openwebmail.conf
domainnames dongying.com 将auto改成你公司的域名,此处为dongying.com
default_language auto 将en改成auto
default_iconset Cool3D.Chinese.Simplified
[[email protected] etc]# cd /var/www/cgi-bin/openwebmail/etc/defaults
[[email protected] defaults]# vi openwebmail.conf
domainnames dongying.com
smtpserver 127.0.0.1
让 Open WebMail 成为 Server 预设的网页
[[email protected] defaults]# cd /var/www/cgi-bin/openwebmail
[[email protected] openwebmail]# vi index.html
<html><head>
<meta http-equiv="Refresh"
content="0;URL=http://mail.dongying.com:82/cgi-bin/openwebmail/openwebmail.pl">
</head></html>
安装apache并修改配置文件
[[email protected] openwebmail]# yum install httpd
[[email protected] openwebmail]# vi /etc/httpd/conf/httpd.conf
ServerName mail.dongying.com:82
Listen 82
DocumentRoot "/var/www/cgi-bin/openwebmail"
AddHandler cgi-script .cgi .pl
[[email protected] openwebmail]# service httpd restart
加入到自动启动
[[email protected] openwebmail]# chkconfig httpd on
停用防火墙或者加入指定端口25、82、110、143、
[[email protected] openwebmail]# service iptables stop
[[email protected] openwebmail]# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 110 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 143 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 82 -j ACCEPT
[[email protected] openwebmail]# service iptables restart
再就可以在浏览器中直接打开了
http://mail.dongying.com:82
最后,使用outlook2013或foxmail来收邮件时,一定要记得,将“我的发件服务器(STMP)需要验证”打上勾。另外,用户名位置一定要按图设定。 如下图
测试完成日期:2017.06.07
附件为配置文件,可以直接使用
本文出自 “虚拟化应用” 博客,请务必保留此出处http://liwenhn.blog.51cto.com/854522/1933512
以上是关于Centos X64 6.9版本安装postfix2.6.6+dovecot+openwebmail的主要内容,如果未能解决你的问题,请参考以下文章