Complete Virtual Mail Server/amavisd spamassassin clamav/ko

도입부
스팸은 인터넷에서 더욱 문제가 될것이며 견고하고 탄탄한 해결책이 필요합니다. 스팸을 차단하는 유료 서비스가 있지만 필수는 아니며 이 글에서 언급하지 않겠습니다.

Postfix
The first line of defense, is postfix itself. Postfix offers a few basic means to block spam, or rather spammers. Using  it is possible to use public DNS blacklists. There are 3 popular DNS blacklists of which one is incorporated into the other. These two lists are also the most accurate ones. The most important one is zen.spamhaus.org and as a backup bl.spamcop.net can be used. Using them with postfix is very simple. Add these domains as  in :

도입부
Spam-assassin and ClamAV are the tools to block spam and viruses, however amavis is required to tie this all together. Amavis will actually behave as a mail server in itself, accept mail, filter it, and send it onwards again. For this to work, postfix will need to actually listen for mail twice. The default port 25 is where mail initially is received on. From there on it is sent to amavis, which will be listening on port 10024. When amavis is done with the message, it will be sent to postfix on a different port, 10025. The reason for this should be obvious. If mail would be offered again on port 25, it would be passed to amavis again and thus in an endless loop. Obviously, postfix on port 10025 would only be listening to known hosts, like localhost and not check for spam anymore.

설치
Amavis should have been installed already, if not, emerge it. This should pull in spam-assassin and clamav as its dependencies.

기본 설정
Amavisd offers an enormous amount of options and going over all them will take some time. The configuration file however is well documented and divided into clear sections. Each section will be examined as needed. Only options that will be changed will be mentioned to cut down the text for readability.

For this example amavisd will be running on host foo but this could be any other host as well, amavisd does not require to run on the same host as postfix. Also the domain used is only used to identify the server itself with, not the domains amavisd will be scanning.

The first step, is to disable all actual checks and to enable logging. Also some default values should be setup.

Normally restarting postfix should restart amavisd as well. For now, only amavisd should be started to see if there are any initial problems.

amavisd를 Postfix에 연동
With amavisd working in bare skeletal mode, it should theoretically just pass mail through. Perfect for testing the postfix -> amavisd -> postfix binding.

First, a second postfix transport, where amavis will inject its mail, is added. A lot of options are defaulted to empty, since either they have been checked already, or interfere otherwise.

With this transport in place, it should only listen on localhost and only accept mail from localhost. This should be extended if amavis is run elsewhere, but keep in mind anything is accepted.

Next another transport is added for, which could be considers 'being' amavis in a sense.

After the transport for amavis has been added, smtp should be told to route all mail through amavis. For this two option need to be added to smtpd and change the maxproc to match amavis's.

Restarting both amavisd and postfix then should pass all mail through amavisd.

시험
Sending a message to testuser@example.com remotely and locally should work fine. After the message has arrived, the headers should be checked.

Looking at the mail headers, it should be noticed that it was sent through amavisd and re-delivered to postfix.

Examining the above it is clearly visible that the mail was received by postfix via SMTPS even. It was then forwarded to amavisd on port 10024 via LMTP and finally redelivered to postfix using SMTP again.

도입부
ClamAV is the de facto open source virus scanner for linux. Amavis can be linked to many different free and commercial virus scanners, but here clamav will be used. ClamAV is specifically designed for scanning e-mail. It consists of two parts, clamav itself, and freshclam, the clamav updating service. By default it updates every two hours, which should be enough for anyone.

설치
ClamAV는 이미 설치했어야하지만, 설치하지 않았다면 이머지해야합니다.

설정
ClamAV will be configured to run in daemonized mode, e.g. it will be listening for connections (from amavisd). The other option (and the default fallback in amavisd) is to have amavisd use the commandline scanner, which is much slower and much much more resource intensive.

ClamAV does not have to be run on the same host, however it is recommended for performance reasons to keep it on the same host, depending on resource usage.

To be able to communicate, clamav needs to be part of amavisd's group.

It always helps to allow clamd to output some debug information.

Also clamd needs some settings setup in its configuration file so that amavis can talk to it.

When running clamav on a hardened kernel, there will be warnings about certain operations not being permitted:

This is expected and okay. ClamAV can run fine without JIT.

Before starting clamav for the first time, the virus database needs to be downloaded. Freshclam is responsible for downloading and keeping the virus database up to date. Freshclam gets automatically started by the clamd startup script, but clamd will fail to start due to a missing database.

Now monitor the clamav log file to see freshclam download the initial virus database.

Now that the database has been updated, restart clamd:

amavisd를 clamav에 연동
Amavisd should connect to the socket of clamd and thus clamav needs to be enabled as one of the main antivirus scanners. The fallback of invoking clamav from the commandline should not be changed. Also the virus check bypass needs to be disabled to be effective.

After restarting amavisd viruses should be able to detected and blocked:

시험
To test whether the virus filter works, an anti-malware testfile exists, sending an e-mail using this string should trigger the virus scanner.

{{CodeBox|title=EICAR-STANDARD-ANTIVIRUS-TEST-FILE| X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* }}

Looking at the file, the following should be revealed:

이론적으로, 바이러스 검색기는 완전한 기능을 수행해야합니다.

도입부
Spam Assassin is an excellent spam filter. It has become quite complex throughout the years and requires some effort to configure correctly.

설치
There really should be no need to install spamassassin separately. The  USE flag should have pulled it in as a dependency of amavisd-new.

설정
기본 설정은 표준 용도를 만족합니다.

업데이트
A key feature of Spam Assassin is its ability to self-update. Updates are handled via a so-called update channel.

Spam Assassin comes with the sa-update tool so updates can be fully automated. Spam Assassin updates can be done by using the  flag to ignore gpg keys, but should really only be done as a last resort. Adding the spamassassin GPG key is a simple 2 step process.

After adding the spamassassin update channel, it needs to be updated. After running this command, check for any errors.

Once these updates have completed they need to be compiled for use with Spam Assassin. Also any errors should be spotted here.

Unlike clamav, there is no 'freshassassin' and a cronjob is required to do updates. To keep Spam Assassin up to date, a cronjob should be created for the task.

Making the cronjob executable ensures it runs regularly:

amavisd를 스팸 어쌔신에 연동
Actually, Spam Assassin does not need to be linked to amavisd, it is an integral part of amavisd. Enabling the spamfilter in amavisd does spam filtering.

With this change, amavisd needs to be restarted:

시험
Testing is done again via a client connecting to port 25 that does not have its own spamfilter. For content GTUBE can be used. On that site there is also a suitable mail message in RFC-822 format.

Checking in the testusers inbox, or junkbox more likly, the message can be found and its header examined:

Amavisd 최적화
Amavis has a few more settings that can be changed to do some fine-tuning.

수신자 구분 문자
When using postfix with the  amavisd can be told to make use of this feature.

It might be interesting to add the following to, otherwise the user+foo@domain might not be delivered:

분산 격리
It is possible to disperse the quarantine over several sub-directories. For this directories need to be created first:

Also, setting a spam cutoff level helps in reducing stored spam. The cutoff level makes it that no spam is stored above a certain spam-score.

스팸 배달
is by default set to, meaning that even with a high score at which it gets marked as spam, it is still delivered to the users mailbox. Modern mail-clients, which trust Spam Assassin, can then automatically move it to their SPAM folder.

Bayes 데이터베이스 경로
Set the  option in SpamAssassin's configuration file so tools such as sa-learn write to the correct database location.

가상 호스트
If this server handles more than one domain, telling amavis can help here.

정리
With Spam Assassin and ClamAV working as expected, debugging information can be reduced to the normal minimal.