Xây Dựng Mail Server Với Postfix - Phần 5

Cài Đặt Bộ Lọc Spam và AntiVirus

 

Lọc Spam và quét Virus là hai thành phần không thể thiếu trong bất cứ một Mail Server nào, phần này sẽ hướng dẫn cho các bạn tích hợp các bộ lọc Spam và AntiVirus Cho Postfix.

I. Cài Đặt Bộ Lọc Spam

1. Lọc Spam Dùng DNS-Base Blocklists (DNSBL, RBL)

Ghi thêm vào file main.cf (/etc/postfix/main.cf) những dòng sau:

smtpd_client_restrictions = permit_mynetworks, reject_rbl_client list.dsbl.org, reject_rbl_client relays.ordb.org, reject_rbl_client sbl-xbl.spamhaus.org

smtpd_recipient_restrictions = permit_mynetworks, reject_rbl_client list.dsbl.org, reject_rbl_client relays.ordb.org, reject_rbl_client sbl-xbl.spamhaus.org

Reload postfix.

[root@localhost ~]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
[root@localhost ~]#

Nói thêm về cách block spam bằng cách kiểm tra trước khi email thực sự được gửi đi. Không liên quan đến RBL, tuy nhiên có những đặc điểm giống cách lọc spam bằng RBL: chỉ kiểm tra header, dựa vào DNS. Chèn thêm các dòng sau vào file main.cf (/etc/postfix/main.cf):

  • Yêu cầu client phải gửi lệnh HELO (EHLO)

smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks, reject_invalid_hostname

  • Từ chối relay (Reject) nếu không tìm thấy A, MX record

smtpd_sender_restrictions = reject_unknown_sender_domain

  • Từ chối relay từ một số địa chỉ IP nhất định (vì nhiễm virus?)

 

# ví dụ 192.168.1.100, 172.16.1.0/24
smtpd_client_restrictions = permit_mynetworks, check_client_access hash:/etc/postfix/reject_client

-    Nội dung file /etc/postfix/reject_client
192.168.1.100 REJECT
172.16.1 REJECT


-     Tạo database /etc/postfix/reject_client.db bằng lệnh sau
/usr/sbin/postmap /etc/postfix/reject_client

  • Từ chối relay từ một số người nhất định (spammer)

# ví dụ This e-mail address is being protected from spambots. You need JavaScript enabled to view it , *@domain2.name
smtpd_sender_restrictions = reject_unknown_sender_domain, reject_non_fqdn_sender, hash:/etc/postfix/reject_sender

-     File /etc/postfix/reject_sender có nội dung như sau:
This e-mail address is being protected from spambots. You need JavaScript enabled to view it REJECT
domain2.name REJECT


-    Tạo database /etc/postfix/reject_sender.db
/usr/sbin/postmap /etc/postfix/reject_sender

Sau khi thêm các dòng cần thiết vào ta phải reload postfix.

Đây là danh sách hàng trăm RBL. Hãy tìm kiếm và lựa chọn những RBL phù hợp với nhu cầu. http://moensted.dk/spam/.

2. Lọc Spam Dùng SpamAssassin

-    Cài đặt procmail và SpamAssassin:

[root@localhost ~]# yum install procmail
[root@localhost ~]# yum install spamassassin

-    Sửa file main.cf (/etc/postfix/main.cf) để procmail xử lý mail. Tìm và uncomment (bỏ dấu thăng (#)) dòng sau:

mailbox_command = /some/where/procmail

Sửa dòng trên lại thành:

mailbox_command = /usr/bin/procmail

-    Tiếp đến tạo một file /etc/procmailrc như sau:

MAILDIR=$HOME
DEFAULT=$MAILDIR/Maildir/
DROPPRIVS=yes

# spam thường có size nhỏ hơn 10 KiB (10*1024=10240 bytes),
# Ấn định kích thước mail cần kiểm tra

:0fw
* < 10240
| /usr/bin/spamc

-    Lập các qui tắc kiểm tra mail cho SpamAssassin, File local.cf (/etc/mail/spamassassin/local.cf) ghi quy tắc chung cho mọi user.


# Ngôn ngữ trong mail thường sử dụng tiếng anh và tiếng viêt

ok_locales vi en

# These should be safe assumptions and allow for simple visual sifting
# without risking lost emails.

required_hits 5
report_safe 0
rewrite_header Subject [SPAM]

# Những mail quan trọng không đánh dấu là spam

whitelist_from This e-mail address is being protected from spambots. You need JavaScript enabled to view it
whitelist_from *@fpt.com.vn

-    Khởi động SpamAssassin

[root@localhost ~]# service spamassassin start


II. Cài Đặt AntiVirus

1. Cài Đặt ClamAV

Để cài ClamAV từ bằng lệnh yum ta phải cài yum-priorities và rpmforge

[root@localhost ~]# yum install yum-priorities
[root@localhost ~]# rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

Kiểm tra phiên bản mới.

[root@localhost ~]# yum check-update

Cài đặt ClamAV.

[root@localhost ~]# yum install clamav clamd

File /etc/freshclam.conf (tự động cập nhật thông tin virus), File /etc/clamav.conf (chương trình chính). Thường thì khi cài từ binary  thì ta để các file này mặc định.

Khởi động ClamAV

[root@localhost ~]# service clamd start

Để kiểm tra xem ClamAV ta có thể chạy lệnh:

[root@localhost ~]# clamscan

Để Update database cho ClamAV ta dùng lệnh:

[root@localhost ~]# freshscan

2. Cài Đặt Amavisd-new

Cài Amavisd-new với lệnh yum.

[root@localhost ~]# yum install amavisd-new

Cấu hình Amavisd-new. File amavis.conf (/etc/amavisd.conf), thường thì để mặc định. Chỉnh sửa Postfix để Amavisd-new có thể hoạt động. File master.cf (/etc/postfix/master.cf) thêm các dòng sau vào:

127.0.0.1:10025 inet    n       -       y       -       -       smtpd
-o content_filter=
-o local_recipient_maps=
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks, reject_unauth_destination
-o mynetworks=127.0.0.0/8
smtp-amavis     unix    -       -       y       -       2       smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes

Thêm dòng sau vào file main.cf (/etc/postfix/main.cf):

content_filter = smtp-amavis:[127.0.0.1]:10024

Khởi động lại Postfix.

Sau 5 phần hướng dẫn của bài viết "Xây dựng mail Server với Postfix" Bạn đọc có thể dễ dàng triển khai một mail server với postfix + dovecot + SquirrelMail + SpamAssassin + ClamAV + Amavid-New. Cám ơn các bạn đã đọc bài, Chúc các bạn thành công!

Phần 6 sẽ giới thiệu với các bạn các hướng mở rộng và nâng cao của Mail Server với Postfix

* Xây Dựng Mail Server với Postfix - Phần 1
* Xây Dựng Mail Server với Postfix - Phần 2
* Xây Dựng Mail Server với Postfix - Phần 3
* Xây Dựng Mail Server với Postfix - Phần 4
* Xây Dựng Mail Server với Postfix - Phần 5
* Xây Dựng Mail Server với Postfix - Phần 6

This e-mail address is being protected from spambots. You need JavaScript enabled to view it
www.UITnetwork.com


Newer news items:
Older news items:

 

Add comment


Security code
Refresh


Thăm dò

Bạn quan tâm đến nội dung nào nhất?
 

Hot nhất