Postfix設定 · 3 min read · Jan 16, 2026
Postfixへのamavisd-newの統合 - スパムおよびウイルススキャン - ページ2
3 Debian Sarge
可変パッケージ(ClamAVなど、ClamAVのリリースは非常に頻繁に行われます)用のDebian-volatileリポジトリが存在します(この記事執筆時点ではSargeおよびWoodyのみ)。最新のClamAVパッケージをインストールするために、まず/etc/apt/sources.listを編集し、以下の行を追加します:
vi /etc/apt/sources.list| [...] deb http://volatile.debian.net/debian-volatile sarge/volatile main contrib non-free |
その後、以下のコマンドを実行してパッケージデータベースを更新します:
apt-get update次に、amavisd-new、SpamAssassin、ClamAVを他のいくつかのプログラム(主にamavisd-newがアーカイブを解凍するために必要なプログラム)と一緒にインストールします:
apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip unarj bzip2 unzoo libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzopいくつかの質問が表示されます:
ウイルスデータベースの更新方法: <– daemon
ローカルデータベースミラーサイト: <– db.de.clamav.net(ドイツ;最寄りのミラーを選択)
HTTPプロキシ情報(なしの場合は空白): <– (空白)
更新後にclamdに通知する必要がありますか? <– はい
その後、/etc/amavis/amavisd.confを編集してamavisd-newを構成する必要があります。このファイルは非常に長く、多くのコメントがあります。ほとんどのデフォルト設定は問題ありませんが、@bypass_virus_checks_aclと@bypass_spam_checks_aclがコメントアウトされていることを確認してください。そうしないと、amavisd-newはアンチスパム/ウイルスコードを読み込まなくなります(私のコピーでは@bypass_spam_checks_acl行がアクティブだったため、コメントアウトする必要がありました):
vi /etc/amavis/amavisd.conf| [...] # @bypass_virus_checks_acl = qw( . ); # uncomment to DISABLE anti-virus code [...] # @bypass_spam_checks_acl = qw( . ); # No default dependency on spamassassin [...] |
その後、同じファイル内のスパム設定とスパム/ウイルスメールのアクションを確認する必要があります。デフォルト設定が問題ない場合は、何も変更する必要はありません。このファイルには多くの説明が含まれているため、ここで設定を説明する必要はありません:
| [...] $final_virus_destiny = D_DISCARD; # (defaults to D_BOUNCE) $final_banned_destiny = D_BOUNCE; # (defaults to D_BOUNCE) $final_spam_destiny = D_REJECT; # (defaults to D_REJECT) $final_bad_header_destiny = D_PASS; # (defaults to D_PASS), D_BOUNCE suggested [...] $virus_admin = "postmaster\@$mydomain"; # due to D_DISCARD default [...] $QUARANTINEDIR = '/var/lib/amavis/virusmails'; #$virus_quarantine_method = "local:virus-%i-%n"; # default #$spam_quarantine_method = "local:spam-%b-%i-%n"; # default $virus_quarantine_to = 'virus-quarantine'; # traditional local quarantine $spam_quarantine_to = 'spam-quarantine'; [...] $sa_local_tests_only = 1; # (default: false) #$sa_auto_whitelist = 1; # turn on AWL (default: false) # Timout for SpamAssassin. This is only used if spamassassin does NOT # override it (which it often does if sa_local_tests_only is not true) $sa_timeout = 30; # timeout in seconds for a call to SpamAssassin # (default is 30 seconds, undef disables it) # AWL (auto whitelisting), requires spamassassin 2.44 or better # $sa_auto_whitelist = 1; # defaults to undef $sa_mail_body_size_limit = 150*1024; # don't waste time on SA is mail is larger # (less than 1% of spam is > 64k) # default: undef, no limitations # default values, can be overridden by more specific lookups, e.g. SQL $sa_tag_level_deflt = 4.0; # add spam info headers if at, or above that level $sa_tag2_level_deflt = 6.31; # add 'spam detected' headers at that level $sa_kill_level_deflt = $sa_tag2_level_deflt; # triggers spam evasive actions # at or above that level: bounce/reject/drop, # quarantine, and adding mail address extension $sa_dsn_cutoff_level = 10; # spam level beyond which a DSN is not sent, # effectively turning D_BOUNCE into D_DISCARD; # undef disables this feature and is a default; $sa_spam_subject_tag = '*SPAM* '; # (defaults to undef, disabled) [...] |
その後、clamavユーザーをamavisグループに追加し、amavisd-newとClamAVを再起動するために以下のコマンドを実行します:
adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-daemon restart次に、Freshclamデーモンの設定ファイルを編集する必要があります(これは、最新のウイルス署名をClamAVミラーから定期的に自動的に取得するデーモンです)が、小さなバグが含まれています。/etc/clamav/freshclam.confを開き、NotifyClamd行を以下のように修正します:
vi /etc/clamav/freshclam.conf| [...] NotifyClamd /etc/clamav/clamd.conf [...] |
その後、Freshclamを再起動します(他のFreshclamプロセス(別のClamAVインストールのものかもしれません)が実行されていないことを確認してください。そうでないと、Freshclamが起動に失敗します):
/etc/init.d/clamav-freshclam restart次に、Postfixを構成して、受信メールをamavisd-newを通してパイプする必要があります:
postconf -e 'content_filter = amavis:[127.0.0.1]:10024'
postconf -e 'receive_override_options = no_address_mappings'その後、以下の行を/etc/postfix/master.cfに追加します:
vi /etc/postfix/master.cf| [...] amavis unix - - - - 2 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes 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_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks -o smtpd_bind_address=127.0.0.1 |
その後、Postfixを再起動します:
/etc/init.d/postfix restart次に、以下のコマンドを実行します:
netstat -tapPostfix(master)がポート25(smtp)および10025でリッスンしており、amavisd-newがポート10024でリッスンしていることが確認できるはずです:
server1:~# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 localhost.localdo:10024 *:* LISTEN 4369/amavisd (maste
tcp 0 0 localhost.localdo:10025 *:* LISTEN 4895/master
tcp 0 0 *:874 *:* LISTEN 1964/rpc.statd
tcp 0 0 *:sunrpc *:* LISTEN 1553/portmap
tcp 0 0 *:auth *:* LISTEN 1932/inetd
tcp 0 0 *:smtp *:* LISTEN 4895/master
tcp6 0 0 *:imaps *:* LISTEN 3177/couriertcpd
tcp6 0 0 *:pop3s *:* LISTEN 3094/couriertcpd
tcp6 0 0 *:pop3 *:* LISTEN 3038/courierttcpd
tcp6 0 0 *:imap2 *:* LISTEN 3129/couriertcpd
tcp6 0 0 *:ssh *:* LISTEN 1943/sshd
tcp6 0 0 *:smtp *:* LISTEN 4895/master
tcp6 0 148 localhost:ssh localhost:4631 ESTABLISHED2052/0必要に応じて、Razor、Pyzor、DCCをSpamAssassinに追加して、そのフィルタリング性能を向上させることができます。Razor、Pyzor、DCCは、協調フィルタリングネットワークを使用するスパムフィルターです。これらをインストールするには、以下のコマンドを実行します:
apt-get install razor pyzor dcc-client次に、SpamAssassinにこれらの3つのプログラムを使用するよう指示する必要があります。/etc/spamassassin/local.cfを編集し、以下の行を追加します:
vi /etc/spamassassin/local.cf| [...] # dcc use_dcc 1 dcc_path /usr/bin/dccproc dcc_add_header 1 dcc_dccifd_path /usr/sbin/dccifd #pyzor use_pyzor 1 pyzor_path /usr/bin/pyzor pyzor_add_header 1 #razor use_razor2 1 razor_config /etc/razor/razor-agent.conf #bayes use_bayes 1 use_bayes_rules 1 bayes_auto_learn 1 |
その後、amavisd-newを再起動します:
/etc/init.d/amavis restartこれで完了です。amavisd-newが正常に動作しているかどうかを確認するために、メールログ(/var/log/mail.log)を監視してください。amavisd-newはスパムまたはウイルスメールを見つけるとログに記録します。(再)起動すると、スパムおよびウイルススキャンコードを読み込むことをログに記録するはずです(そうでない場合は、何か間違ったことをした可能性があります)。
メールログをライブで確認するには、以下のコマンドを使用できます:
tail -f /var/log/mail.log(ログを離れるにはCTRL + cを押してください。)
4 リンク
- amavisd-new: http://www.ijs.si/software/amavisd
- Postfix: http://www.postfix.org
- ClamAV: http://www.clamav.net
- SpamAssassin: http://spamassassin.apache.org
- Debian: http://www.debian.org
- Ubuntu: http://www.ubuntu.com
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。