Postfix Fastfood

Đầu tiên cần nói Pro thì không dùng Postfix mà dùng Qmail. Qmail luôn xứng danh với danh hiệu Mail Gateway của mình. Chẳng thế mà Yahoo cũng dùng Qmail.
Postfix cấu hình khá đơn giản, lại dễ kết hợp với các cái khác.
Gửi lời cám ơn tới a.Hạnh, a cũng là tác giả luôn:
Cấu hình Postfix + Dovecot:

Cài đặt mail server – dùng user hệ thống:

Cài đặt các file cần thiết:

yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain postfix dovecot

Thiết lập các cấu hình cơ bản:

postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
postconf -e 'mynetworks = 127.0.0.0/8'

Thêm cách thức xác thực:

vi /usr/lib/sasl2/smtpd.conf

pwcheck_method: saslauthd

mech_list: plain login

Tạo khóa bảo mật cho SMTP:

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024

chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr

openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt

openssl rsa -in smtpd.key -out smtpd.key.unencrypted

mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

Cấu hình cho Postfix nhận key bảo mật:

postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'

Cấu hình cho tên server trong bản tin Hello:

postconf -e 'myhostname = server.hbn.local'

Cấu hình Dovecot cho chạy các dịch vụ của POP3 và IMAP:

vi /etc/dovecot.conf

[...]

# Protocols we want to be serving: imap imaps pop3 pop3s

# If you only want to use dovecot-auth, you can set this to "none".

protocols = imap imaps pop3 pop3s

[...]

Cấu hình lưu trữ mail:

postconf -e 'home_mailbox = Maildir/'
postconf -e 'mailbox_command ='
/etc/init.d/postfix restart

Cấu hình khởi động cho các dịch vụ:

chkconfig --levels 235 sendmail off
chkconfig --levels 235 postfix on
chkconfig --levels 235 saslauthd on
chkconfig --levels 235 dovecot on
/etc/init.d/sendmail stop
/etc/init.d/postfix start
/etc/init.d/saslauthd start
/etc/init.d/dovecot start

Cấu hình cho tên miền cho server:

vi /etc/postfix/main.cf

Tìm đến dòng mydestination = và thay thế bằng dòng:

mydestination = /etc/postfix/local-host-names

Soạn thảo file /etc/postfix/local-host-names có nội dung như sau:

localhost

localhost.localdomain

server.hbn.local

hbn.local

Cấu hình user:

Postfix dùng user hệ thống nên để tạo user cho mail ta dùng lệnh adduser bình thường, sau đó khai báo map cho postfix:

Soạn thảo file /etc/postfix/virtualusesrtb có nội dung dạng:

user@domain user

Ví dụ:

hbn@hbn.local hbn

user2@hbn.local user2

Sau đó tạo cở sở dữ liệu user cho mail ta dùng lệnh:

postmap /etc/postfix/virtualusesrtb

Khai báo thêm cho Postfix biết nơi lưu trữ thông tin user:

Mở file /etc/postfix/main.cf

Thêm vào cuối dòng:

virtual_maps = hash:/etc/postfix/virtualusesrtb

Khởi động lại dịch vụ postfix ta có mail server chạy hoàn chỉnh.

Thêm User: Add như bt. Sau đó thêm vào file /etc/postfix/virtualusesrtb, postmap bình thường. Thực ra cái này là Virtual Domain + System User :))
Thanks for Reading
---------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------
All my Lab:
Linux Lab -- window and Cisco Lab
to be continued - I will update more.

Nam Habach