CentOS 7 Pofix & Dovecot - 工作雜記

工作雜記

My working blogger,In my daily work log, I meticulously record all the matters and processes I encounter during the day. From the task planning that begins in the morning and the discussions and collaborations with colleagues, to the tools, methods, and processes used in the actual execution of the work, I organize and write them down one by one. Problems encountered during the process, the directions of thought, and the solutions finally found are also clearly recorded in writing

工作雜記

搜尋此網誌

標籤

2016年12月7日 星期三

CentOS 7 Pofix & Dovecot



postfix:

設定檔/etc/postfix/main.cf

myhostname = (完整FQDN hostname)
mydomain = (網域domain name)
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.0.0/24, 127.0.0.0/8, hash:/etc/postfix/access
relay_domains=$mydestination
home_mailbox =
postfix預設的home mailbox 在/var/mail/
若是改為使用者家目錄可設為 Maildir/
這裡的設定需和dovecot設定一致,否則會出錯

systemctl enable postfix.service
systemctl restart postfix.service

2020/05 mynetworks網段或單獨ip要分清楚,單獨IP後面不要加/24,網段要計算子網路遮罩

relay_domains要將非本網域的使用者納入,否則會被阻檔

postfix與dovecot同時使用家目錄設定較簡單


dovecot: (不使用加密)

設定檔/etc/dovecot/conf.d/10-mail.conf

mail_location =
1.若使用postfix預設的位址
mail_location = mbox:~/mail:INBOX=/var/mail/%u
2.若使用home家目錄位址
mail_location = maildir:~/Maildir

設定檔/etc/dovecot/dovecot.conf
protocols =imap pop3 (imap是給roundcube webmail用的)

設定檔/etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login

設定檔/etc/dovecot/conf.d/10-master.conf
user = postfix
group = postfix

設定檔/etc/dovecot/conf.d/10-ssl.conf
ssl = no  ( 若啟用將只允許pop3+TLS, pop3s, imap+TLS and imaps加密協定)

systemctl enable dovecot.service

systemctl restart dovecot.service

測試:
telnet localhost pop3
user (username)
pass (passwd)
list
quit

若是發現信件呆在QUEUE裡久久才動
請查一下maillog,如果出現以下錯誤
KickMessage failed as couldn't write to /var/spool/postfix/public/qmgr, No such device or address,
請修改/etc/postfix/master.cf
qmgr unix n - n 300 1 qmgr
qmgr fifo n - n 300 1 qmgr
systemctl restart postfix 

垃圾信阻擋相關設定:

寄件人過濾選項
reject_unknown_sender_domain 寄信人的網域名稱無法從 DNS 查詢驗證時,拒絕連線。
reject_rhsbl_sender 寄信人信箱如果被紀錄在 SPAM 資料庫站台,就拒絕他連線。
check_sender_access 根據 access 設定過濾存取權限。
reject_non_fqdn_sender 寄信人的網域名稱不是完整 FQDN 格式時,拒絕其連線。

收件人過濾選項
permit_auth_destination 收信人網域符合 $relay_domains、$mydestination、$inet_interfaces、$vitual_alias_domains、$virtual_mailbox_domains 的定義時,接受連線。
reject_unauth_destination 收信人網域不符合上述設定時,拒絕連線。
permit_mx_backup 當從 DNS 上查到本機為收信人網域的備份 MX 時,接受連線。使用此功能有安全漏洞,可以配合 permit_mx_backup_networks = 172.16.0.0/16 來檢查主要 MX 是否在該網段內,來加強過濾功能(避免被不信任的網域設定為轉信 MX)。
check_relay_domains 允許代收要給 relay_domians 的信件。
check_recipient_access 根據 access 設定過濾存取權限。
check_recipient_maps 當收信人網域不符合 permit_auth_destination 之要求,或是收信人信箱不符合 $local_recipient_maps、$virtual_alias_maps、$virtual_mailbox_maps、$relay_recipient_maps 的定義時,拒絕連線。此參數可以放在收信人過濾規則的最後面,當作過濾政策。
reject_unknown_recipient_domain 收信人的網域名稱無法從 DNS 查詢驗證時,拒絕連線。
reject_rhsbl_recipient 收信人信箱如果被紀錄在 SPAM 資料庫站台,就拒絕他連線。
reject_non_fqdn_recipient 收信人的網域名稱不是完整 FQDN 格式時,拒絕其連線。

#收件人過濾(直接覆製貼上)
smtpd_recipient_restrictions =permit_mynetworks,permit_sasl_authenticated,reject_non_fqdn_hostname,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_invalid_hostname,reject_unknown_sender_domain,reject_unknown_recipient_domain,reject_rbl_client cbl.abuseat.org,reject_rbl_client bl.spamcop.net,reject_rbl_client cblless.anti-spam.org.cn,reject_rbl_client sbl-xbl.spamhaus.org

#防範垃圾郵件,不發送回頭信
non_fqdn_reject_code = 450
unknown_local_recipient_reject_code = 450
unknown_virtual_alias_reject_code = 450
unknown_virtual_mailbox_reject_code = 450
maps_rbl_reject_code = 450

其他設定:

#調整單封郵件大小
message_size_limit = 40000000

2018/11/26備註:

message_size_limit似乎有上限

一旦設超過上限之後,信件將卡在佇列無法寄出

這點要注意一下

2022/11/23

設定SMTP身份驗證 防止被open relay

1.安裝 yum install -y cyrus-sasl
systemctl enable saslauthd
systemctl restart saslauthd

2.vim /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
log_level: 3

3.讓postfix 使用 SMTP 身份驗證
vim /etc/postfix/main.cf

# 使用SMTP登入認證
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
#SMTP登入認證條件(每行前面要加空白)
smtpd_recipient_restrictions =
 permit_mynetworks,
 permit_sasl_authenticated,
 reject_unauth_destination
 reject_non_fqdn_hostname,
 reject_non_fqdn_sender,
 reject_non_fqdn_recipient,
 reject_invalid_hostname,
 reject_unknown_sender_domain,
 reject_unknown_recipient_domain,
 reject_rbl_client cbl.abuseat.org,
 reject_rbl_client bl.spamcop.net,
 reject_rbl_client cblless.anti-spam.org.cn,
 reject_rbl_client sbl-xbl.spamhaus.org

2022/12/1
設定某些大型SERVER被黑名單後使用transport轉寄功能

設定檔/etc/postfix/main.cf
加入transport_maps = hash:/etc/postfix/transport

設定檔/etc/postfix/transport
aaa.com smtp:[xxxx.xxxx.xxxx.xxxx]:25
將所有要寄給aaa.com的信件轉由xxxx.xxxx.xxxx.xxxx寄出
xxxx.xxxx.xxxx.xxxx必需為可轉址的SERVER

產生transport.db資料庫
/usr/sbin/postmap /etc/postfix/transport

重啟postfix
systemctl restart postfix.service

2023/11/10
禁用 NDR,不回應有效電子郵件清單
vim /etc/postfix/master.cf
bounce unix - - n - 0 bounce
改成
bounce unix - - n - 0 discard

重啟postfix
systemctl restart postfix

沒有留言:

張貼留言

Post Top Ad

Your Ad Spot