CentOS4.4下邮件服务器架设笔记之邮件网关功能实现

简介:
1.通过参考以上两篇文章:
        我们基本上实现了邮件收发,以及对垃圾邮件过滤的功能,但是目前面对企业来说,用microsoft exchange的比较多,我的想法,就是想要把这台邮件服务器的变成邮件网关,所有流进内部邮件服务器的邮件先经过MX GATEWAY扫描后,再往后面丢;虽然目前市面上很多这样功能的产品,但是价格却是一笔投资,但是LINUX却能容易做到;我在此写BLOG,把自己测试的情况与大家交流,相信对初学者是一个总结;
        包括此篇文章的总结,也是花费我了将近一个月的时间抽空测试总结出来的,我希望以此作为抛砖引玉的功能,让大家把自己更好的总结给贡献出来!我自己是一个LINUX初学者,我想通过此平台认识更多的朋友,大家互相交流一下! QQ:418027712
 
2.转入正题:
首先介绍下我的内网测试环境:
a.参考上面两篇文档:分别架设服务器A,其IP地址:10.6.6.111;
b.新安装一台邮件服务器B,只包含(postfix+dovecot),没有垃圾过滤功能;来替代现实环境的exchange服务器,因为安装linux邮件服务器比microsoft平台的exchange快,简单,更重要的,找个古董机器都能装;
c.两台机器都是同一个域,centos.eb.cn
A机器名:mail.centos.eb.cn         B机器名:mail1.cenots.eb.cn
3.开始配置:
a.配置邮件网关机器A,修改通过传输表实现转发;
即当邮件发给A机器时,A全部转发给B机器;
[root@mail ~]# cd /etc/postfix
[root@mail postfix]# vi main.cf
增加
transport_maps = hash:/etc/postfix/transport
然后保存退出,并编辑:
[root@mail postfix]# vi transport
增加
centos.eb.cn  relay:[10.6.6.120]
保存退出后,执行:
[root@mail postfix]# postmap /etc/postfix/transport
[root@mail postfix]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
b.配置MailScanner.conf实现,当A机器对收到的外部邮件判断垃圾邮件时,丢到B机器的指定帐户 [email]spam@centos.eb.cn[/email];
[root@mail postfix]# vi /etc/MailScanner/MailScanner.conf
#Spam Actions = deliver header "X-Spam-Status: Yes"      #将此行的配置注释掉;
Spam Actions = forward 
[email]spam@centos.eb.cn[/email]     #转发指定账户配置
#High Scoring Spam Actions = deliver header "X-Spam-Status: Yes"   #将此行的配置注释掉;
High Scoring Spam Actions = forward [email]spam@centos.eb.cn[/email]  #转发指定账户配置
 
重新启动一下MailScanner
[root@mail postfix]# service MailScanner restart
Shutting down MailScanner daemons:
         MailScanner:                                      [  OK  ]
         incoming postfix:                                 [  OK  ]
         outgoing postfix:                                 [  OK  ]
Waiting for MailScanner to die gracefully ....................................................................... dead.
Starting MailScanner daemons:
         incoming postfix:                                 [  OK  ]
         outgoing postfix:                                 [  OK  ]
         MailScanner:                                      [  OK  ]
[root@mail postfix]#
其实MailScanner在判定为垃圾邮件处理有多种方式,见如下参数;
# This is just like the "Spam Actions" option above, except that it applies
# to messages that are *NOT* spam.
#    deliver                 - deliver the message as normal
#    delete                  - delete the message
#    store                   - store the message in the (non-spam) quarantine
#    store-nonmcp            - store the message in the non-MCP quarantine
#    store-mcp               - store the message in the MCP quarantine
#    store-nonspam           - store the message in the non-spam quarantine
#    store-spam              - store the message in the spam quarantine
#    forward 
[email]user@domain.com[/email] - forward a copy of the message to [email]user@domain.com[/email]
#    striphtml               - convert all in-line HTML content to plain text
#    header "name: value"    - Add the header
#                                name: value
#                              to the message. name must not contain any spaces.
#    custom(parameter)       - Call the CustomAction function in /usr/lib/Mail-
#                              Scanner/MailScanner/CustomFunctions/CustomAction
#                              .pm with the 'parameter' passed in. This can be
#                              used to implement any custom action you require.
新建一个账户,收集垃圾邮件;
[root@mail postfix]# ssh root@10.6.6.120
mailto:root@10.6.6.120 password:
[root@mail1 ~]# adduser spam -s /sbin/nologin
Changing password for user spam.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
 
 
4.开始测试,分别发送一正常与垃圾信给 [email]leeki.yan@centos.eb.cn[/email]
a.首先从 [email]leeki.yan@trinet.com.cn[/email]测试一封正常信到 [email]leeki.yan@centos.eb.cn[/email],理论上正常信,经过A机器扫描后,会往后面B机器relay,并且寄给 [email]leeki.yan@centos.eb.cn[/email],查看日志如下:
Sep 30 16:38:36 mail postfix/smtpd[8637]: connect from unknown[10.0.0.1]
Sep 30 16:38:36 mail postfix/smtpd[8637]: 8002B170301: client=unknown[10.0.0.1]
Sep 30 16:38:36 mail postfix/cleanup[8639]: 8002B170301: hold: header Received: from mail.trinet.com.cn (unknown [10.0.0.1])??by mail.centos.eb.cn (Postfix) with ESMTP id 8002B170301??for <[email]leeki.yan@centos.eb.cn[/email]>; Sun, 30 Sep 2007 16:38:36 +0800 (CST) from unknown[10.0.0.1]; from=<[email]leeki.yan@trinet.com.cn[/email]> to=<[email]leeki.yan@centos.eb.cn[/email]> proto=ESMTP helo=<mail.trinet.com.cn>
Sep 30 16:38:36 mail postfix/cleanup[8639]: 8002B170301: hold: header Received: from triumphweihu ([10.0.0.1]) by mail.trinet.com.cn with Microsoft SMTPSVC(5.0.2195.6713);?? Sun, 30 Sep 2007 16:47:36 +0800 from unknown[10.0.0.1]; from=<[email]leeki.yan@trinet.com.cn[/email]> to=<[email]leeki.yan@centos.eb.cn[/email]> proto=ESMTP helo=<mail.trinet.com.cn>
Sep 30 16:38:36 mail postfix/cleanup[8639]: 8002B170301: message-id=<00da01c8033d$5e55aa60$de04040a@triumphweihu>
Sep 30 16:38:36 mail postfix/smtpd[8637]: disconnect from unknown[10.0.0.1]
Sep 30 16:38:38 mail MailScanner[8125]: New Batch: Scanning 1 messages, 2650 bytes
Sep 30 16:38:42 mail MailScanner[8125]: Virus and Content Scanning: Starting
Sep 30 16:38:53 mail MailScanner[8125]: Requeue: 8002B170301.BC8D5 to 52652170302
Sep 30 16:38:53 mail MailScanner[8125]: Uninfected: Delivered 1 messages
Sep 30 16:38:53 mail postfix/qmgr[8107]: 52652170302: from=<[email]leeki.yan@trinet.com.cn[/email]>, size=2872, nrcpt=1 (queue active)
Sep 30 16:38:53 mail postfix/smtp[8647]: 52652170302: to=<[email]leeki.yan@centos.eb.cn[/email]>, relay=10.6.6.120[10.6.6.120], delay=17, status=sent (250 Ok: queued as 122AF2206E0)
Sep 30 16:38:53 mail postfix/qmgr[8107]: 52652170302: removed
 
见上面红色字体部分,说明已经往后B机器relay成功了!
 
b.从 [email]418027712@qq.com[/email]测试一封垃圾信到 [email]leeki.yan@centos.eb.cn[/email],理论上垃圾信,经过A机器扫描后,会往后面B机器relay,寄给 [email]spam@centos.eb.cn[/email],查看日志如下:
Sep 30 17:05:01 mail postfix/smtpd[3496]: connect from smtpbg12.qq.com[58.60.13.110]
Sep 30 17:05:01 mail postfix/smtpd[3496]: C9D89170301: client=smtpbg12.qq.com[58.60.13.110]
Sep 30 17:05:01 mail postfix/cleanup[3504]: C9D89170301: hold: header Received: from smtpbg12.qq.com (smtpbg12.qq.com [58.60.13.110])??by mail.centos.eb.cn (Postfix) with ESMTP id C9D89170301??for < [email]leeki.yan@centos.eb.cn[/email]>; Sun, 30 Sep 2007 17:05:01 +0800 (CST) from smtpbg12.qq.com[58.60.13.110]; from=< [email]418027712@qq.com[/email]> to=< [email]leeki.yan@centos.eb.cn[/email]> proto=ESMTP helo=<smtpbg12.qq.com>
Sep 30 17:05:01 mail postfix/cleanup[3504]: C9D89170301: message-id=< [email]tencent_46D546001FA9FA1C63F8C299@qq.com[/email]>
Sep 30 17:05:01 mail postfix/smtpd[3496]: disconnect from smtpbg12.qq.com[58.60.13.110]
Sep 30 17:05:02 mail MailScanner[3341]: New Batch: Scanning 1 messages, 1614 bytes
Sep 30 17:05:36 mail MailScanner[3341]: Spam Checks: Found 1 spam messages
Sep 30 17:05:36 mail MailScanner[3341]: Virus and Content Scanning: Starting
Sep 30 17:06:20 mail MailScanner[3341]: Requeue: C9D89170301.4D561 to 1B757170304
Sep 30 17:06:20 mail MailScanner[3026]: Uninfected: Delivered 1 messages
Sep 30 17:06:20 mail postfix/qmgr[2587]: 1B757170304: from=< [email]418027712@qq.com[/email]>, size=1834, nrcpt=1 (queue active)
Sep 30 17:06:30 mail postfix/smtp[3591]: 1B757170304: to=< [email]spam@centos.eb.cn[/email] >, relay=10.6.6.120[10.6.6.120], delay=89, status=sent (250 Ok: queued as 19B222206E0)
Sep 30 17:06:30 mail postfix/qmgr[2587]: 1B757170304: removed
由面日志红色字体部分可以看出,首先检测发现邮件为垃圾邮件,然后,在往B机器relay时,投寄到 [email]spam@centos.eb.cn[/email];
 
5.测试完成!
 
 
6.2007年10月8日22时补充说明:
,但是经与jacky网友聊天得知:理论上,邮件网关配置好了后,外部发过的来的邮件到邮件网关时,是不需要查询本地用户组的,他只管往后面丢,所以我测试查找发现,要修改邮件网关的main.cf文件,找到:
#local_recipient_maps =
修改成:
local_recipient_maps = 
即把注释给取消掉,就可以!

本文转自 godoha 51CTO博客,原文链接:http://blog.51cto.com/godoha/44512 ,如需转载请自行联系原作者

相关文章
|
2月前
|
安全 Linux Shell
使用SCP命令在CentOS 7上向目标服务器传输文件
以上步骤是在CentOS 7系统上使用SCP命令进行文件传输的基础,操作简洁,易于理解。务必在执行命令前确认好各项参数,尤其是目录路径和文件名,以避免不必要的传输错误。
241 17
|
4月前
|
Kubernetes Ubuntu Linux
阿里云服务器使用centos还是ubuntu?
在选择阿里云服务器操作系统时,CentOS和Ubuntu各有优势。CentOS以企业级稳定性著称,适合数据库、ERP等长期稳定需求;而Ubuntu开发者友好,支持最新硬件与功能,更适合开发/测试环境及云计算场景。两者在阿里云上均有官方镜像支持,性能差异可忽略。无特殊需求时推荐Ubuntu 22.04 LTS,若需RHEL生态则选AlmaLinux。根据实际需求、团队技术栈及场景灵活决策,阿里云还支持更换系统盘降低试错成本。
|
6月前
|
Linux 虚拟化 数据安全/隐私保护
系统崩溃不用慌!VMware这个逆天功能竟能让CentOS一键回档?后悔药真实存在!
备份的重要性在于它能在系统出现异常或错误时,帮助我们快速恢复到正常状态,避免重新安装系统和配置环境。VMware 提供了两种备份方式:快照和克隆。 **快照**是保存虚拟机某一时刻的完整状态(包括内存、CPU、磁盘数据),便于快速回滚,适合临时保存状态。操作简单,可在系统运行时创建。 **克隆**则是复制整个虚拟机系统,侧重长期备份,需在系统关闭时进行。分为完整克隆和链接克隆,前者独立于源系统,占用更多空间,但更安全可靠。
214 17
系统崩溃不用慌!VMware这个逆天功能竟能让CentOS一键回档?后悔药真实存在!
|
6月前
|
存储 安全 Linux
CentOS 7.9系统备份:每日定期发送最新备份文件到另一台服务器。
注意,这个解决方案忽略了很多细节,例如错误处理和通知、备份版本控制、循环处理旧的备份文件等等。此外,你也应该尽量保持源服务器和目标服务器之间快速,稳定且安全的网络连接,并且目标服务器应该有足够的空间用于存放每天的备份文件。如果你需要更高级的备份解决方案,可能需要考虑一下使用专门的备份工具或者服务。
256 18
|
6月前
|
存储 运维 网络协议
【Syslog】Centos下的syslog服务器配置
通过本文的配置指导,您不仅学会了如何安装和配置 `rsyslog`,还掌握了如何在防火墙中开放必要的端口,并验证服务器的配置是否正确。希望这些知识能够帮助您更好地管理和维护您的Linux系统。
901 15
|
6月前
|
弹性计算
【已解决】Matomo本地SMTP配置可以发邮件,但部署到阿里云ECS就发不了邮件
在阿里云ECS上使用Matomo和PHPMailer发送邮件时遇到问题,邮件无法发出且接口调用Pending。经过排查,发现是ECS安全组未开放25/465端口,导致SMTP请求无法正常通信。解决方法为在安全组中配置并开放25/465端口,从而恢复邮件发送功能。
|
7月前
|
存储 Prometheus 监控
Centos7.9版本安装collectd并开启写入rrd文件功能
Centos7.9版本安装collectd并开启写入rrd文件功能
186 13
|
8月前
|
安全 大数据 Linux
云上体验最佳的服务器操作系统 - Alibaba Cloud Linux | 飞天技术沙龙-CentOS 迁移替换专场
本次方案的主题是云上体验最佳的服务器操作系统 - Alibaba Cloud Linux ,从 Alibaba Cloud Linux 的产生背景、产品优势以及云上用户使用它享受的技术红利等方面详细进行了介绍。同时,通过国内某社交平台、某快递企业、某手机客户大数据业务 3 大案例,成功助力客户实现弹性扩容能力提升、性能提升、降本增效。 1. 背景介绍 2. 产品介绍 3. 案例分享
183 1
|
11月前
|
NoSQL Linux Redis
在 centos7 下重启/开启 redis 服务器
本文提供了一种在Centos 7操作系统下如何重启Redis服务器的步骤,包括停止Redis服务、确认停止成功以及重新启动Redis服务。
990 2
在 centos7 下重启/开启 redis 服务器

热门文章

最新文章