配置SMTP发信认证

5.配置SMTP发信认证
问题
沿用练习一、二、三,根据现有的Postfix服务配置,基本上任何人都可以连接到邮件服务器,随意提交电子邮件。为了提高邮件系统的安全性、减少垃圾邮件,本案例要求针对SMTP发信功能开启认证限制。
需要完成的配置任务如下:
1)启用saslauthd 认证服务
2)调整postfix 服务配置,添加相关认证设置
3)测试SMTP发信认证
方案
RHEL6系统自带了SASL(Simple Authentication and Security Layer,简单认证安全层)组件,无需额外配置,可以利用其saslauthd服务来提供认证支持。当然,还需要修改Postfix服务的配置文件,以便启用认证,如图-8所示。
配置SMTP发信认证
图-8
步骤
实现此案例需要按照如下步骤进行。
步骤一:配置saslauthd 认证服务
1)安装、启动saslauthd服务
[[email protected] ~]# yum -y install cyrus-sasl-plain //若已安装,则此步跳过
… …
[[email protected] ~]# service saslauthd start
[[email protected] ~]# chkconfig saslauthd on
2)简单测试认证效果
使用testsaslauthd工具检查smtp服务,若用户名、密码正确,则测试通过,否则将会失败:
[[email protected] ~]# testsaslauthd -u hunter -p 1234567 -s smtp
0: OK “Success.” //认证通过

[[email protected] ~]# testsaslauthd -u hunter -p 1234 -s smtp
0: NO “authentication failed” //认证失败(不通过)
步骤二:调整 postfix 配置,启用SMTP认证
1)修改main.cf配置文件,添加认证相关配置
[[email protected] ~]# vim /etc/postfix/main.cf
… …
mynetworks = 127.0.0.1 //设置本地网络
smtpd_sasl_auth_enable = yes //启用SASL认证
smtpd_sasl_security_options = noanonymous //阻止匿名发信
smtpd_recipient_restrictions = //设置收件人过滤
permit_mynetworks, permit_sasl_authenticated,
reject_unauth_destination //拒绝向未授权的目标域发信
2)重新加载postfix服务
[[email protected] ~]# service postfix restart
… …
步骤三:测试 SMTP 发信认证
在客户机上利用mail命令或Thunderbird测试。
1)以前例配置的mail命令为例,未经过认证登录时,向外域发邮件会被拒绝
[[email protected] ~]# echo “SMTP Test.” | mail -s “Test Mail 3.” [email protected]
… …
smtp-server: 554 5.7.1 [email protected]: Relay access denied
“/root/dead.letter” 11/306
. . . message not sent. //被拒绝、邮件提交失败
2)修改mail的配置文件,添加SMTP认证信息
[[email protected] ~]# vim ~/.mailrc
set smtp=smtp://mail.tedu.cn
set [email protected]
set smtp-auth-user="[email protected]" //指定认证用户
set smtp-auth-password=“1234567” //指定认证密码
set folder=imap://[email protected]
set [email protected]=“1234567”
3)再次测试发信,邮件成功提交到服务器
[[email protected] ~]# echo “SMTP Test.” | mail -s “Test Mail 4.” [email protected]
[[email protected] ~]#
通过上述操作过程可以发现,用户nick经认证登录以后,成功将一封发给外域收件人[email protected]的邮件提交到postfix发信队列。
注意:邮件被成功提交到发信队列不表示发信就一定会成功,还取决于Internet连接、DNS解析、对方的邮件接收策略等一系列因素。