寫在前面 這篇是我讀 SAMS POSTFIX 一書的心得及筆記,筆記不照順序,內容前後不按照書,很多我讀過的東西我不再寫上去,若有錯誤,請告訴我,以便更正 該書的 ISBN 是 0-672-32114-9 基本設定 main.cf myhostname and mydomain 若末設定 myhostname 和 mydomain 時,預設使用系統設定的 hostname ,可以用 #uname -n 查看hostname . myorigin 用 sendmail 寄信出去,預設的 mail From FQDN relay_host 指示收進來的信要送到那一台 SMTP Server 做 Relay HOST .... 常用在內部有專用的 Relay SMTP Server ,或是偷用 ISP Mail Server 的頻寬 mydestination Postfix 收信的 Domain 不過要注意,若是有用 Virtual Domains 的功能,就不能設 mydestination. smtpd_banner 這是用來設定當 SMTP 連進來時,要顯示的版本資訊 default_destination_concurrency_limit 同時送信到遠端的 SMTP Server 的限制,預設值 default_destination_concurrency_limit = 10 default_local_concurrency_limit 同時送信到本機的的 SMTP Server 的限制,預設值 default_destination_concurrency_limit = 2 default_destination_recipient_limit 送信到遠端 SMTP Server 時,一封信內最多可以有多少收件者,預設值 default_destination_recipient_limit = 10 message_size_limit 進來的信件最大限制,預設值 message_size_limit = 10240000 單位是 Byte,包含信件檔頭的訊息 line_length_limit 使用 SMTP 寄信進來,每一行最大可以傳送多少 bytes,預設值 line_length_limit = 2048 header_size_limit 每一封信寄進來,最大的 header 大小,預設值 header_size_limit = 102400 Look Up Table regexp 格式有 pattern value pattern1!pattern2 value example: /^postmaster@.*$/ OK /^(.*)-outgoing@(.*)$/!/^owner-.*/ 550 Ise ${1}@${2} instead pcre postfix 也支援 PCRE 的格式. format 同 regexp Database NIS NIS, Network Informaion System 用法如下 alias_maps = hash:/etc/postifx/alias, nis:nis.server.com MySQL postfix 同樣也支援 MySQL 用法 alias_maps = mysql:/etc/postfix/mysql-alias.cf 至於 mysql-alias.cf 的內容如下 user = rich password = richard dbname = postfix table = alias select_field = real_address where_field = alias_address additional_conditions = and status = 'current' hosts = mysql.server.com 這樣下會如下的 SQL 指令 SELECT real_address from postfix_aliases where alias_address = '$lookup' and status = 'current' $lookup 會被換作 pattern 值 LDAP 以 LDAP 相關參數 alias_map = hash:/etc/postfix/aliases, ldap:myldap myldap_server_host = meshach.server.com myldap_search_base = dc = server, dc = com myldap_result_attribute = mailbox Access Table Access Table 可以控制那些來源的信件可以進來,那些不行,來源可以有以下的格式 user@domain hostname.domain domain user@ aaa.bbb.ccc.ddd (IP) aaa.bbb.ccc 而結果會有以下的格式 OK 允許 REJECT 拒絕 XXX text 用 XXX 作 retuen code ,並且以 text 作為訊息 text 允許 SMTP ,並且以 text 作為訊息 會用到 Access 的參數 smptd_client_restrictions 限制那一個 clinet 可以送信 smtpd_helo_restrictions 限制那個用 SMTP HELO和 EHLO 指令時,那個 hostname 可以送信 smtpd_sender_restrictions 限制 SMTP MAIl FROM 指令 smtpd_recipient_restrictions 限制 SMTP RCPT TO 指令 記得存檔以後要執行 #postmap /etc/postfix/access 在 /etc/postfix/main.cf 加上類似以下的語法 smtpd_sender_restrictions = hash:/etc/postfix/access aliases Tables aliases 最簡單的說法就是可以用來做 "假" email 位置,有幾種用法 送信到相關的 e-mail 位置 用 pipe 的方式送到一個命令列 加入到一個檔案 送到一組 e-mail ,而這組列表存在於一個檔案 基本的語法 pattern: result 實務用法 name: name_1,name_2,name_3 送給 name_1,name_2,name_3 name: | program 送給 program 這隻程式處理 name: file 檔案是要 full path 的文字檔,記得處理權限問題,並且要在 main.cf 內加上 allow_mail_to_files name: :include:filelist 送給在 filelist 內所有有郵件名單的. canonical table postfix 內的 cleanup 這隻程式會用 canonical table 重寫message header 內的 message address. 通常會配合 aliases ,用在公司會使用 Firstname.Lastname 這樣格式的 E-mail 上,例如在 Aliases 內寫 Richard.Liu richliu Kevin.lin kevinlin 而在 canonical 內寫 richliu Richard.Liu kevinlin Kevin.Lin 預設值是sender 和 recipient 用同一個 canonical file ,你可以在 main.cf 內指定 sender_canonical_maps = hash:/etc/postfix/canonical recipient_canonical_maps = hash:/etc/postfix/canonical relocate table 當你的使用者換一個名字,你的系統可以傳一段訊息給他,並且可以告訴他新的 E-mail Address 在那邊 fireduser fireduser@lostspace.com Please Change Your AddressBook 當 someone 寄給 fireduser 時,你的系統會自動回信寫 user has moved to fireduser@lostspace.com, Please Change Your AddressBook 在 main.cf 內的設定值是 relocated_maps = hash:/etc/postfix/relocated 注意: relocte table 並不會幫你將信件轉給新的位置,如果你要會自動轉給新的位置,請用 aliases transport table 在遞送 mail 的時候,可以用個人指定的 protocol 傳送到遠端的 Server 語法 destination transport:[nexthop] Example smtp.server.com local: pop3.server.com local: lostworld.org uucp:lostworld remote.org smtp: remote2.org smtp:relay.server.com remote3.org smtp:relay.server.com:1025 當然,在 main.cf 內要設定 transport_maps = hash:/etc/postfix/transport 注意:當你在 tansport 內指定一個 protocol 時,必需同意也在 master.cf 內設定 virtual table orz ..... UCE(Unsolicited Commercial Email) UCE 通常被稱作 Spam ..... header_checks 最簡單的就是檢查檔頭 header_checks = regexp:/etc/postfix/header_checks Setting Relaying Parameters 設定可以 relay 的 Domain,基本設定如下,後面接的是預設值 smtpd_recipient_restrictions = permit_mynetworks, check_relay_domains 這邊可以用多個參數,而參數和參數之間可以用逗號(,)或是空白分開,個人比較喜歡用逗號 check_relay_domains 允許以下幾種狀況的 Client 進行 relay 任何列在 $relay_domains 參數內的 client,預設會加入 $mydestination 這個參數 列在 $relay_domains 的目的地 列在 $inet_interfaces 參數內的目的地 列在 virtual table 內的目的地 Reject 參數 reject 所有的要求,包含 Local reject_invalid_hostname 錯誤的 HELO hostname reject_maps_rbl 如果 client 列在 $maps_rbl_domains reject_non_fqdn_hostname HELO 的hostname非FQDN,請注意, MS 產品不按 SPEC 來,常送出 non fqdn hostname reject_non_fqdn_recipient 收件人位置非FQDN reject_non_fqdn_sender 寄件人非FQDN reject_unauth_destination 收件人位置不符合 $mydestination,$inet_interfaces,$virual_maps 或 $relay_domain reject_unauth_pipelining 用 SMTP pipelining 送出的郵件(似乎是給 local 用?) reject_unknown_client clinet 的 hostname 未知 reject_unknown_hostname client 的 HELO 沒有 DNS A or MX 記錄, 請注意 MS 產品不照規格來 reject_unknown_recipient_domain 收件者的位置的 domain 沒有 DNS A or MX 記錄 reject_unknown_sender_domain 寄件者的位置的 domain 沒有 DNS A or MX 記錄 Permit 參數 permit permit_auth_destination permit_mx_backup Database Check 並不是做資料庫檢查,而是 Postfix 可以讀取檔案,檢查該 client 是不是符合該檔 domain 允許或是禁止通過的列表目前支援以下幾個查詢表格 %26#8226; check_client_access %26#8226; check_helo_access %26#8226; check_recipient_access %26#8226; check_sender_access 使用方法,在 main.cf 你想設定的的參數,加上 check_helo_access 之類的語法 smtpd_recipient_restrictions = check_helo_access hash:/etc/postfix/heloaccess , reject 而內容大致上就是 server.com OK richliu.com OK poorman.org OK 這個參數在上下文有提到 (fixme) 這樣 應該可以用 pcre 的function ,例如 check_helo_access pcre:/etc/postfix/heloaccess 確認 HELO 位置 由於 Microsoft 程式的問題,讓我在這邊吃了很多苦頭,Microsoft 在破壞 RFC 和製造 RFC 的混亂不遺餘力,在此大力遣責 Microsoft 所寫的任何有問題的 Mail Client 及 Mail Server 本人最幹的就是 HELO 只會送出主機名稱,並不會送出 FQDN . 在 main.cf 內確認 HELO 的參數是 smtpd_helo_restrictions = value POSTFIX HELO 限制的參數 check_helo_access maptype:mapname check_client_access maptype:mapname permit permit_mynetworks 允許在 mynetworks 內的 client sendmail permit_naked_ip_address 允許沒有被 brackets(應該為 [])框起來的 IP reject 所有的要求,包含 Local reject_unknow_client 拒絕沒有 DNS PTR Record reject_maps_rbl 如果 client 列在 $maps_rbl_domains reject_invalid_hostaname Reject 不正確的 HELO hostname reject_unauth_pipelining 用 SMTP pipelining 送出的郵件(似乎是給 local 用?) reject_unknown_hostname client 的 HELO 沒有 DNS A or MX 記錄 reject_non_fqdn_hostname HELO 的hostname非FQDN 確認 MAIL FROM: 位置 在 main.cf 內 確認 MAIL FROM: smtpd_sender_restrictions = value 而其他的參數,和碓認 HELO 位置大致相同,但是多了以下幾個 check_sedner_accress maptype:mapname reject_non_fqdn_sender 拒絕 sender 的 connect 是沒有 fqdn 的. RBL RBL(The Realtime Blackhole List) 要靠以上這幾招要擋廣告信幾乎是不可能的,所以有時要籍助外部的力量,比較常見的參數是 reject_maps_rbl maps_rbl_domains reject_rbl_client 比較常見的 RBL 提供者 %26#8226; http://www.mail-abuse.com/ %26#8226; http://www.ordb.org/ %26#8226; http://www.spamhaus.org/ 原書上用 www.mail-abuse.org ,但是該網站己經改到 www.mail-abuse.com 了. 只要做如下的設定,你就可以用 RBL 的力量了 maps_rbl_domains = blackholes.mail-abuse.org, dialups.mail-abuse.org smtpd_helo_restrications = reject_maps_rbl smtpd_sedner_restrictions = reject_maps_rbl 我個人是用 maps_rbl_domains = relays.ordb.org,sbl-xbl.spamhaus.org smtpd_sender_restrictions = permit_mynetworks, pcre:/etc/postfix/access, reject_maps_rbl, reject_unknown_sender_domain, reject_non_fqdn_sender
Advanced Postfix Server Topic Using MySQL = Using OpenLDAP Using POP3 and IMAP Using SqWebMail Performance Tuing main.cf Inbound Message Control %26#8226; smtpd_recipient_limit 限制收件者的數量,default value is 1000 (預設值似乎很高?),不過限制這個數量並不會減低系統資源,因為信還是會送進來 %26#8226; smtpd_timeout = value 在回應給 SMTP Client 後,等待回應的時間,這可以擋掉一些不是真的要送資料的 client m=分 n=小時 d=日 w=week %26#8226; smtpd_error_sleep_time 當回一個 error code 給 remote smtp server 後,會 delay 一小段時間不讓他連上來 %26#8226; smtpd_soft_error_limit %26#8226; smtpd_hard_error_limit Outbound Message Control %26#8226; initial_destination_concurrency postfix 一開始最會建立二個連線到要送信的 SMTP Client,若是送信之間沒有什麼大問題,而又有信要送,postfix 會自動增加這個量 %26#8226; default_destination_concurrency_limit 最大連線到遠端的 Server 的數量,這個參數和 master.cf 內 SMTP maxprocess 是相關的,設超過時,會被 max process 限制 %26#8226; default_destination_reipient_limit 一次最多可以發給幾個收信人,預設值是 50 Unreachable Hosts %26#8226; queue_run_delay 告訴 postfix 多久掃描一次 deferred mail (延遲送出的信),預設值是 1000(秒) %26#8226; maximal_queue_lifetime deferred mail,最多會保存多久,預設值是 5 (天),請注意,如果設太短,某些 mail server 會當機很久,這不是一件好事. %26#8226; minimal_backoff_time 留在 deferred 內的信及遠端 mail server 被標記為無法連線的最小處理間隔,預設值是 1000(seconds) %26#8226; maximal_backoff_time 無法送信出去的最大處理間隔,如果你希望處理 mail server deferred 快一點,就減少這個數值,如果你不在意處理速度,就加大這個數值,預設值是 4000 %26#8226; qmgr_message_recipient_limit places an upper limit on the size of many in-memory queue manageer data structures. Default value is 10000 Tuning Unix System %26#8226; Mount 時 在 mount 時,一般現在都會設上 noatime ,因為 atime 實在是用不到. 也可以增加些許讀寫速度
Testing Postfix Performance %26#8226; smtp-sink 測試 postfix 送信速度. /usr/bin/smtp-sink -c :25 100 %26#8226; smtp-source smtp-source -c -l 1000 -m 100 -s 20 -t richliu@server.com -c display a running count of SMTP DATA commands send. -l length Sends test messages that are length bytes long. -m count Sends count number of messages; the default is 1 -s count Runs count number of SMTP sessions concurrently. The Default is 1 -t to Uses the adddress to as the message recipient. The default is the address foo@myhostname Common Postifx Problems 相關觀念 postfix 支援的 Mailbox 種類 %26#8226; sendmail-style /var/spool/mail %26#8226; Individual $HOME/Mailbox %26#8226; Qmail-sytle $HOME/Maildir
|