Setting up ClamAV

Published on December 29, 2020

Installation

Install ClamAV:

apk add acf-clamav clamsmtp

Add the postfix user to the clamav group:

usermod -aG clamav postfix

Configuration

Start the services:

/etc/init.d/clamd start
/etc/init.d/clamsmtpd start
rc-update add clamd
rc-update add clamsmtpd

Check if the ClamAV service is listening:

netstat -anp | grep clamsmtpd

Edit /etc/postfix/main.cf:

content_filter = scan:[127.0.0.1]:10025

Add the following to /etc/postfix/master.cf:

# AV scan filter (used by content_filter)
scan      unix  -       -       n       -       16      smtp
        -o smtp_send_xforward_command=yes
        -o smtp_enforce_tls=no
# For injecting mail back into postfix from the filter
127.0.0.1:10026 inet  n -       n       -       16      smtpd
        -o content_filter=
        -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
        -o smtpd_helo_restrictions=
        -o smtpd_client_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o mynetworks_style=host
        -o smtpd_authorized_xforward_hosts=127.0.0.0/8

Reload the Postfix configuration:

/etc/init.d/postfix reload

Testing

To test your ClamAV installation, you can send an e-mail from another domain to yourself and check the e-mail headers. They should contain a X-Virus-Scanned field if ClamAV is operational.

X-Virus-Scanned: ClamAV using ClamSMTP

If you like my work or if my work has been useful to you in any way, then feel free to donate me a cup of coffee. Any donation is much appreciated!