Centos7下postfix+Dovecot+cyrus-sasl搭建个人局域网邮件服务器(测试使用)

本文详细介绍如何在CentOS 7环境下从零开始搭建邮件服务器,包括环境准备、配置Postfix、Dovecot及SASL等关键步骤,并通过实际案例验证了配置的有效性。

1、环境准备,Centos 7 机器一台(选择vsphere环境下的一台虚拟机),虚拟机进行环境配置:

     a):IP配置,最后能够访问Inetnet,主要能够访问yum源,也可配置可访问的局域网源;

     b):配置防火墙规则,由于是测试使用,所以直接关闭firewalld服务

2、修改虚拟机的hostname和domain(测试过程中发现没啥用,大概了解下就可以)

3、安装、配置、启用postfix     yum install postfix(一般OS都已经自带)

[root@linuxprobe ~]# vi /etc/postfix/main.cf
# line 75: uncomment and specify hostname

myhostname = linuxprobe.srv.world
# line 83: uncomment and specify domain name

mydomain = srv.world
# line 99: uncomment

myorigin = $mydomain
# line 116: change

inet_interfaces = all
# line 164: add

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# line 264: uncomment and specify your local network

mynetworks = 127.0.0.0/8, 10.0.0.0/24
# line 419: uncomment (use mailboxdir)

home_mailbox = mailbox/
# line 574: add

smtpd_banner = $myhostname ESMTP
# add follows to the end

# limit an email size for 10M

message_size_limit = 10485760

# limit a mailbox for 1G

mailbox_size_limit = 1073741824
# for SMTP-Auth

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject

[root@linuxprobe ~]# systemctl restart postfix
[root@linuxprobe ~]# systemctl enable postfix
4、安装配置启动dovecot      yum install dovecot

[root@linuxprobe ~]# vi /etc/dovecot/dovecot.conf
# line 24: uncomment
protocols = imap pop3 lmtp
# line 30: uncomment and change ( if not use IPv6 )
listen = *
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-auth.conf
# line 10: uncomment and change ( allow plain text auth )
disable_plaintext_auth = no
# line 100: add
auth_mechanisms = plain login
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-mail.conf
# line 30: uncomment and add
mail_location = maildir:~/Maildir
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-master.conf
# line 96-98: uncomment and add like follows
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
}
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-ssl.conf
# line 8: change (not require SSL)
ssl = no

[root@linuxprobe ~]# systemctl start dovecot
[root@linuxprobe ~]# systemctl enable dovecot


5、安装配置启动sasl

yum install cyrus-sasl-*

vim /etc/sysconfig/saslauthd

MECH=shadow  #指定以本地系统用户名认证

vim /usr/lib64/sas12/smtpd.conf //64位系统

vim /usr/lib/sas12/smtpd.conf //32位系统

smtpd.conf配置文件默认是没有的,vim编辑的同时创建

pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
log_level:3


6、验证,创建管理员账号和测试用户账号。添加到mailfox互相发邮件测试。注意在添加过程中,由于局域网没有域名等信息,所以直接填写的服务器IP地址(发现很多教程中,设置域名和MX那些太繁琐)


7、邮件信息统计pflogsumm

 yum -y install postfix-perl-scripts

[root@linuxserver ~]# perl /usr/sbin/pflogsumm -d today /var/log/maillog
Postfix log summaries for Oct 11

Grand Totals
------------
messages

      2   received
      2   delivered
      0   forwarded
      0   deferred
      0   bounced
      0   rejected (0%)
      0   reject warnings
      0   held
      0   discarded (0%)

   1928   bytes received
   1928   bytes delivered
      1   senders
      1   sending hosts/domains
      1   recipients
      1   recipient hosts/domains


Per-Hour Traffic Summary
------------------------
    time          received  delivered   deferred    bounced     rejected
    --------------------------------------------------------------------
    0000-0100           0          0          0          0          0
    0100-0200           0          0          0          0          0
    0200-0300           0          0          0          0          0
    0300-0400           0          0          0          0          0
    0400-0500           0          0          0          0          0
    0500-0600           0          0          0          0          0
    0600-0700           0          0          0          0          0
    0700-0800           0          0          0          0          0
    0800-0900           0          0          0          0          0
    0900-1000           0          0          0          0          0
    1000-1100           0          0          0          0          0
    1100-1200           0          0          0          0          0
    1200-1300           0          0          0          0          0
    1300-1400           0          0          0          0          0
    1400-1500           0          0          0          0          0
    1500-1600           0          0          0          0          0
    1600-1700           0          0          0          0          0
    1700-1800           0          0          0          0          0
    1800-1900           0          0          0          0          0
    1900-2000           2          2          0          0          0
    2000-2100           0          0          0          0          0
    2100-2200           0          0          0          0          0
    2200-2300           0          0          0          0          0
    2300-2400           0          0          0          0          0

Host/Domain Summary: Message Delivery
--------------------------------------
 sent cnt  bytes   defers   avg dly max dly host/domain
 -------- -------  -------  ------- ------- -----------
      2     1928        0     0.1 s    0.1 s  zuo.com

Host/Domain Summary: Messages Received
---------------------------------------
 msg cnt   bytes   host/domain
 -------- -------  -----------
      2     1928   zuo.com

Senders by message count
------------------------
      2   admin@zuo.com

Recipients by message count
---------------------------
      2   zuoqiang@zuo.com

Senders by message size
-----------------------
   1928   admin@zuo.com

Recipients by message size
--------------------------
   1928   zuoqiang@zuo.com

message deferral detail: none

message bounce detail (by relay): none

message reject detail: none

message reject warning detail: none

message hold detail: none

message discard detail: none

smtp delivery failures: none

Warnings
--------
  smtpd (total: 3)
         1   unknown[10.165.12.13]: SASL LOGIN authentication failed: UGFzc3...
         1   hostname bogon does not resolve to address 10.165.12.13: Name o...
         1   hostname bogon does not resolve to address 10.166.15.214: Name ...

Fatal Errors
------------
  postfix-script (total: 1)
         1   usage: postfix start (or stop, reload, abort, flush, check, sta...

Panics: none

Master daemon messages
----------------------
      2   daemon started -- version 2.10.1, configuration /etc/postfix
      1   terminating on signal 15
[root@linuxserver ~]#




<think>好的,用户现在在CentOS上已经部署了PostfixDovecot,并且配置了SMTP在25端口。他们想知道是否设置了认证密码,也就是SMTP认证是否启用。我需要分步骤来思考如何回答这个问题。 首先,用户可能不太清楚SMTP认证的具体配置位置,或者他们可能只是快速部署后想确认配置是否正确。作为管理员,验证SMTP认证是否开启是非常重要的,否则可能会导致开放中继,被垃圾邮件滥用。 接下来,我应该考虑用户的实际需求。他们可能担心服务器安全性,或者遇到了邮件发送的问题,比如无法通过认证发送邮件。需要引导他们检查PostfixDovecot的配置,确保两者都正确启用了认证机制。 Postfix的SMTP认证通常依赖于SASL,而Dovecot可以作为SASL的提供者。因此,需要检查Postfix的main.cf文件中是否启用了smtpd_sasl_auth_enable,以及是否正确指向了Dovecot的socket。同时,Dovecot的配置也需要确认是否允许认证,并且正确配置了用户数据库。 用户可能不太熟悉如何查看这些配置,所以需要给出具体的命令和配置文件路径。比如使用postconf命令检查Postfix的参数,查看Dovecot的10-master.conf文件中的service auth部分是否配置正确。 此外,测试认证是否实际工作也是重要的一步。可以使用telnet或swaks这样的工具来模拟SMTP认证过程,观察服务器的响应。如果返回了“235 2.7.0 Authentication successful”,则说明认证成功。 还需要考虑可能的错误,比如SELinux或防火墙设置阻止了认证过程,或者配置文件中的语法错误。建议用户检查日志文件,如/var/log/maillog,查看认证过程中的错误信息。 最后,提醒用户关于安全性的问题,比如使用加密连接(端口465或587)而不是明文传输密码,以及定期更新密码和监控日志,防止未授权访问。这些建议能帮助用户提升服务器的安全性,避免潜在的风险。</think>在 CentOS 上验证 Postfix + Dovecot 的 SMTP 认证配置是否生效,可通过以下步骤进行检查: --- ### 一、检查 Postfix 认证配置 #### 1. 查看核心参数 ```bash postconf -n | grep -E "smtpd_sasl|smtpd_relay_restrictions" ``` **关键参数验证**: - `smtpd_sasl_auth_enable = yes` (必须为 yes) - `smtpd_sasl_type = dovecot` (使用 Dovecot 作为 SASL 认证后端) - `smtpd_sasl_path = private/auth` (Dovecot 认证套接字路径) - `smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination`(必须包含 permit_sasl_authenticated) #### 2. 验证 SASL 服务状态 ```bash systemctl status saslauthd # 仅当使用 cyrus-sasl 时需要 ``` --- ### 二、检查 Dovecot 认证配置 #### 1. 查看认证模块配置 ```bash grep -v "^#" /etc/dovecot/conf.d/10-auth.conf | grep -E "auth_mechanisms|disable_plaintext_auth" ``` - 确认 `auth_mechanisms` 包含 `plain login`(明文认证需结合 SSL 使用- 若 `disable_plaintext_auth = yes` 则必须启用 SSL #### 2. 检查认证服务套接字 ```bash grep "service auth" /etc/dovecot/conf.d/10-master.conf ``` 应存在类似配置: ```nginx service auth { unix_listener /var/spool/postfix/private/auth { mode = 0660 user = postfix group = postfix } } ``` --- ### 三、实际功能测试 #### 方法1:Telnet 手动测试 ```bash telnet localhost 25 EHLO example.com 250-AUTH PLAIN LOGIN # 若看到此行表示认证已启用 QUIT ``` #### 方法2:使用 swaks 工具测试 ```bash swaks --to user@example.com --server localhost --auth-user testuser --auth-password 'password' ``` **成功标志**: ``` <- 235 2.7.0 Authentication successful ``` --- ### 四、日志验证 #### 查看认证过程记录 ```bash tail -f /var/log/maillog | grep -i sasl ``` **典型成功记录**: ``` postfix/smtpd[1234]: warning: hostname localhost does not resolve to address 127.0.0.1 postfix/smtpd[1234]: AUTH: PLAIN testuser postfix/smtpd[1234]: authenticated: user=testuser ``` --- ### 五、常见故障排查点 1. **SELinux 拦截**: ```bash sealert -a /var/log/audit/audit.log | grep postfix ``` 临时解决方案: ```bash setsebool -P allow_postfix_local_write_mail_spool 1 ``` 2. **目录权限问题**: ```bash ls -ld /var/spool/postfix/private/auth ``` 需确保权限为 `srw-rw----`,属组为 `postfix:postfix` 3. **密码数据库验证**: ```bash doveadm user testuser # 验证用户是否存在 doveadm auth test password # 测试密码认证 ``` --- ### 六、安全强化建议 1. **强制加密传输**: - 禁用 25 端口明文认证,改用 465 (SMTPS) 或 587 (Submission) ```postfix smtpd
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值