Amavisd-new


http://code.google.com/p/iredmail/wiki/RHEL_Mail_Server_Solution

Introduction

以下介绍内容来自 amavsid-new 官方网站

amavisd-new is a high-performance interface between mailer (MTA) and content checkers: virus scanners, and/or SpamAssassin. It is written in Perl for maintainability, without paying a significant price for speed. It talks to MTA via (E)SMTP or LMTP, or by using helper programs. Best with Postfix, fine with dual-sendmail setup and Exim v4, works with sendmail/milter, or with any MTA as a SMTP relay. For Courier and qmail MTA integration there is a patch in the distributed package.

amavisd-new 是一个介于 MTA 和内容过滤软件之间的桥梁,其角色就像是两者之间的沟通者。 amavisd-new 本身也是个简单的 MTA,也可以用来架设一个独立的 Mail Gateway,提供多台 Mail Server 做邮件过滤。除此之外,amavisd-new 还可以结合十多种杀毒软件来做病毒防护。

amavisd-new 在这里的作用主要是:

  • 负责调用 ClamAV 对邮件进行病毒扫描
  • 负责调用 SpamAssassin 对邮件内容进行过滤

Installation

# yum -y install amavisd-new

Configuration

amavisd-new: /etc/amavisd.conf

amavisd-new 的配置文件为:/etc/amavisd.conf。这里我修改了以下几个参数:

#
# Part of file: /etc/amavisd.conf
#

$max_servers = 15;

$mydomain = 'mail.osspinc.com';

#
将你的虚拟域加到 "@local_domains_maps" 中,这样 Amavisd 在调用 SpamAssassin 检查完
邮件后才会在邮件 header 部分加入 'X-Spam-Status', 'X-Spam-Level' 等标记。
每个域都需要用引号包含起来,域之间用英文逗号分隔。
#
@local_domains_maps = ( [".$mydomain", "osspinc.com"] );  # list of all local domains

#
设置 amavisd  pid 文件。
#
$pid_file = "/var/run/amavisd.pid";

#
检测到病毒等邮件时发邮件通知到哪个邮件地址
#
$virus_admin                = "root\@$mydomain";
$mailfrom_notify_admin      = "root\@$mydomain";
$mailfrom_notify_recip      = "root\@$mydomain";
$mailfrom_notify_spamadmin  = "root\@$mydomain";

#
设置监听的 IP/Port
#
$notify_method  = 'smtp:[127.0.0.1]:10025';
$forward_method = 'smtp:[127.0.0.1]:10025';

#
检测到 virus/spam 等信件时的默认动作。各参数的含义是:
#
#    * $final_virus_destiny:        
检测到病毒时的动作
#    * $final_banned_destiny:       
检测到受禁止的内容时的动作
#    * $final_spam_destiny:         
检测到垃圾邮件、广告邮件(spam)时的动作
#    * $final_bad_header_destiny:   
检测到不良信件时的动作
#
默认有以下几种动作:
#
#    * D_PASS: 
无论信件是否有问题,都会将信件发给收件人
#    * D_DISCARD: 
信件将被丢弃,并且不会告知收件人及发件人
#    * D_BOUNCE: 
信件不会发送给收件人,但会通知发件人邮件没有被投递
#    * D_REJECT: 
邮件不会被投递给收件人,但会通知发件人邮件被拒绝
#
注意:除了 D_PASS,其它参数都会导致邮件最终不被投递到用户邮箱里。
由于担心误删资料,所以默认将 spam, banned, bad_header 的默认动作都
设置为 D_PASS 了,请根据自己的需要来修改。
#
$final_virus_destiny      = D_DISCARD;
$final_banned_destiny     = D_PASS;
$final_spam_destiny       = D_PASS;
$final_bad_header_destiny = D_PASS;

#
 @av_scanners 部分中,只保留 ClamAV 相关的内容,其它的都注释掉。
#
注意:这里需要修改 clamd  Socket 路径,修改为:/tmp/clamd.socket
#
@av_scanners = (

# ### http://www.clamav.net/
['ClamAV-clamd',
   \&ask_daemon, ["CONTSCAN {}\n", "/tmp/clamd.socket"],
   qr/\bOK$/, qr/\bFOUND$/,
   qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],

);

#
 @av_scanners_backup 部分,只保留 ClamAV 相关的内容,其它的都注释掉。
#
@av_scanners_backup = (

  ### http://www.clamav.net/   - backs up clamd or Mail::ClamAV
  ['ClamAV-clamscan', 'clamscan',
    "--stdout --disable-summary -r --tempdir=$TEMPBASE {}", [0], [1],
    qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],

);

#
调试 SpamAssassin
#   0:  disable
#   1:  enable
#
$sa_debug = 0;

#
当邮件被认为是垃圾邮件时,是否修改邮件的主题。即在邮件主题里加上
# '*** SPAM ***' 
字符串。
#
#   1:  enable
#   0:  disable
#
$sa_spam_modifies_subj = 1;

#
# remove existing headers
#
#$remove_existing_x_scanned_headers= 1;
#$remove_existing_spam_headers = 1;

#
默认情况下,凡是经过 Amavisd 过滤的邮件,都会在邮件头中被加入一行
邮件头信息,例如:
#
#    X-Virus-Scanned: amavisd-new at osspinc.com
#
将参数留空则不会添加邮件头。
#
如果需要自定义插入的邮件头信息,可以修改 /usr/sbin/amavisd 文件里
的对应内容:
#
#   sub add_forwarding_header_edits_per_recip
#
#$X_HEADER_TAG = 'X-Virus-Scanned';
#$X_HEADER_LINE = "by amavisd at $myhostname";

1;  # insure a defined return

编辑完后,可以执行以下命令以检查 amavisd 是否配置正确:

# amavisd debug

如果顺利启动,则表示配置没有错误。可以用 Ctrl + C 的组合键终止进程, 然后用以下命令启动它:

# /etc/init.d/amavisd restart

Postfix: /etc/postfix/master.conf

配置好 Amavisd-new 后,还需要通知 Postfix 使用 Amavisd 作为内容过滤 程序。

操作步骤:

  •  /etc/postfix/master.cf 中添加以下内容:

smtp-amavis unix -  -   -   -   2  smtp
    -o smtp_data_done_timeout=1200
    -o smtp_send_xforward_command=yes
    -o disable_dns_lookups=yes
    -o max_use=20

127.0.0.1:10025 inet n  -   -   -   -  smtpd
    -o content_filter=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o smtpd_restriction_classes=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks_style=host
    -o mynetworks=127.0.0.0/8
    -o strict_rfc821_envelopes=yes
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
    -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

  • 通知 Postfix 使用 amavisd 进行过滤,并重新启动 Postfix

# postconf -e 'content_filter=smtp-amavis:[127.0.0.1]:10024'
# postfix restart

Testing Amavisd-new

no-spam

# mail -s "subject" [email protected] < /etc/hosts

以下是在 /var/log/maillog 里的日志信息

Dec  5 11:04:01 mail amavis[18411]: (18411-02) Passed CLEAN, <[email protected]> -> 
<[email protected]>, Message-ID: <[email protected]>, mail_id: 
3agVrt7nAgxM, Hits: 1.406, 899 ms

这里有一个 '''amavis18411''',这就表示 clamav, amavisd-new 正常工作。

spam

SpamAssassin 提供了一个 sample 文件,可以用它来测试对 spam 的过滤是否成功:

# mail -s "hello" [email protected] < /usr/share/doc/spamassassin-3.1.9/sample-spam.txt

以下是 /var/log/maillog 里的日志信息

Dec 25 09:53:58 mail amavis[3879]: (03879-01) Passed SPAM, <[email protected]> -> 
<[email protected]>, Message-ID: <[email protected]>, mail_id: 
HHhO-Vb1NCGo, Hits: 1001.351, 1855 ms

由于 $final_spam_destiny 的值设置为 'D_PASS',所以即使检测到是 spam 邮件,也还是会发给收件人。 这里的 '''Passed SPAM''' 表示 amavisd-new 对邮件的识别情况。

debug

如果需要让 amavisd-new 输出更多调试信息,可以修改 /etc/amavisd.conf 文件中的 log 参数:

$log_level = 5;   # 范围:0 ~ 5

如果需要同时调试 SpamAssassin 的信息,还需要设置:

$sa_debug = 1;

也可以使用 debug 参数来启动 amavisd 进行调试:

# amavisd debug

FAQ & Trouble Shooting

Amavisd 为何没有在邮件头中插入 'X-Spam-Status' 等标记?

 

参考链接:http://marc.info/?l=amavis-user&m=121371334007085&w=2

 

Amavisd 只有在以下两个条件同时满足的时候才会在邮件头中插入 'X-Spam-Status', 'X-Spam-Level' 等标记:

 

    接收邮件的域名被列在 '@local_domains_maps' 参数中,例如:

 

      @local_domains_maps = ( [".$mydomain","a.cn"] );  # list of all local domains

 

    除了这里列出的 '.$mydomain'  'a.cn' 这几个域外,其他域的邮件都不会被插入 'X-Spam-' 标记。

 

    邮件扫描的结果,分值(score)大于或等于 '$sa_tag_level_deflt''@spam_tag_level_deflt' 中定义的分值时才会插入 'X-Spam-Status' 等标记。'$sa_tag_level_deflt' 的分值默认是 '2.0'。可以按照自己的实际需求进行调整:

 

      $sa_tag_level_deflt  = 2.0;  # add spam info headers if at, or above that level

 

Do not scan outbound mails

 

Q: 如何让 Amavisd 不调用 SpamAssassin  ClamAV 扫描外发的邮件?

 

A:  /etc/amavisd.conf 文件中指定了这两个参数:

 

#

这里指定了对 @mynetworks 里的客户端使用的规则

#

$policy_bank{'MYNETS'} = {   # mail originating from @mynetworks

  originating => 1,  # is true in MYNETS by default, but let's make it explicit

  os_fingerprint_method => undef,  # don't query p0f for internal clients

};

 

#

这里指定了对本地用户、虚拟用户使用的规则

#

$policy_bank{'ORIGINATING'} = {  # mail supposedly originating from our users

  originating => 1,  # declare that mail was submitted by our smtp client

  allow_disclaimers => 1,  # enables disclaimer insertion if available

  # notify administrator of locally originating malware

  virus_admin_maps => ["virusalert\@$mydomain"],

  spam_admin_maps  => ["virusalert\@$mydomain"],

  warnbadhsender   => 1,

  # forward to a smtpd service providing DKIM signing service

  forward_method => 'smtp:[127.0.0.1]:10027',

  # force MTA conversion to 7-bit (e.g. before DKIM signing)

  smtpd_discard_ehlo_keywords => ['8BITMIME'],

  bypass_banned_checks_maps => [1],  # allow sending any file names and types

  terminate_dsn_on_notify_success => 0,  # don't remove NOTIFY=SUCCESS option

};

 

如果要让 Amavisd 对本地外发的邮件不做邮件内容过滤和病毒扫描,可以在 policy_bank 里增加参数:

 

$policy_bank{'MYNETS'} = {   # mail originating from @mynetworks

  originating => 1,  # is true in MYNETS by default, but let's make it explicit

  os_fingerprint_method => undef,  # don't query p0f for internal clients

 

  #

  增加以下三个参数

  #

  bypass_spam_checks_maps   => [1],  # don't spam-check internal mail

  bypass_banned_checks_maps => [1],  # don't banned-check internal mail

  bypass_header_checks_maps => [1],  # don't header-check internal mail

};

 

要对虚拟用户使用此规则,加同样的参数即可。

Resource Links

 

    * Amavisd-new

          o README.postfix

    * Bypass amavisd-new scanning - Postfix integratio

你可能感兴趣的:(职场,休闲,amavisd)