這篇文檔展現了postfix的典型配置參數。在你按照《BASIC_CONFIGURATION_README》設置完之後,應該回顧《postfix標準配置示例》這篇文檔。需要注意的是,如果你的postfix還不能進行本地郵件發送和本地郵件傳遞,那麼先安裝好postfix,在閱讀下面的內容。
•internet獨立主機的postfix
•無客戶端的postfix(即只發送郵件,不接收郵件)
•本地網絡的postfix
•postfix的郵件網關/防火牆
•部分用戶可以給internet發郵件
•在防火牆後面運行postfix
•爲遠程站點配置主/備份mx
•撥號主機的postfix配置
•沒有公網地址的主機上配置postfix
你能用"postconf -n"查看你的main.cf忽略了那些參數。
#proxy_interfaces = 1.2.3.4
mynetworks_style = host
relay_domains =
# mynetworks = 192.168.1.0/28
# relay_domains =
無客戶端的意思是隻發送郵件不接收郵件。它不接收來自網絡的任何郵件,也不把郵件投遞到本地。空客戶端的postfix典型應用環境是提供POP,IMAP或NFS。
2 myorigin = $mydomain
3 relayhost = $mydomain
4 inet_interfaces = loopback-only
5 local_transport = error:local delivery is disabled
6
7 /etc/postfix/master.cf:
8 Comment out the local delivery agent entry
解釋:
•第2行的意思:郵件以[email protected]發送,而不是以[email protected]發送。
本地網絡的postfix
這部分描述了一個主postfix服務器和其他郵件系統並存的局域網環境。我們仍然假設internet域名爲:example.com。所有的系統都被配置爲以[email protected]發送郵件;所有的系統接收[email protected]的郵件。這個主服務器也接收[email protected]的郵件。我們把這臺機器命名爲:mailhost.example.com。
以[email protected]發送郵件的缺點是:root和其他系統帳戶的郵件也發送到網關郵件服務器。這個缺點的解決辦法參見“Delivering some but not all accounts locally”
2 myorigin = $mydomain
3 mynetworks = 127.0.0.0/8 10.0.0.0/24
4 relay_domains =
5 # Optional: forward all non-local mail to mailhost
6 #relayhost = $mydomain
解釋:
•第2行:以[email protected]發送郵件
接下來,我們展現含mailhost的配置。郵件服務器以[email protected]發送郵件,接收[email protected]和[email protected]的郵件
2 example.com IN MX 10 mailhost.example.com.
3
4 /etc/postfix/main.cf:
5 myorigin = $mydomain
6 mydestination = $myhostname localhost.$mydomain localhost $mydomain
7 mynetworks = 127.0.0.0/8 10.0.0.0/24
8 relay_domains =
9 # Optional: forward all non-local mail to firewall
10 #relayhost = [firewall.example.com]
•第2行:發送給example.com域名的郵件全部傳遞到mailhost.example.com這臺機器上。記住這行最後面的點號“.”
•第5行: 以[email protected]發送郵件
•第6行:這個主機是發給example.com域的郵件的終點。
•第7行:指定信任的網絡
•第8行:這個主機不中繼不信任網絡的郵件
•第10行:當mailhost需要通過防火牆上的郵件網關傳遞外部郵件時,需要設置這個參數。中括號“[]”是提示postfix不要進行mx查詢。
•通過NFS訪問郵箱
•通過POP或者IMAP訪問郵箱
•在用戶傾向的機器上訪問郵箱
安裝postfix防火牆/網關的目的是:把example.com的郵件轉發到內部的網關,但是拒絕"anything.example.com"的郵件。這兒僅有一個問題:使用relay_domains=example.com參數,防火牆也會接收anything.example.com的郵件。
2 myorigin = example.com
3 mydestination =
4 local_recipient_maps =
5 local_transport = error:local mail delivery is disabled
6
7 /etc/postfix/master.cf:
8 Comment out the local delivery agent
解釋:
•第2行:以[email protected]發送郵件
•第3-8行:關閉防火牆上的本地郵件傳遞功能
2 virtual_alias_maps = hash:/etc/postfix/virtual
3
4 /etc/postfix/virtual:
5 postmaster [email protected]
6 abuse [email protected]
•由於mydestination參數的值爲空(參見前文的設置),只有與$inet_interfaces或$proxy_interfaces匹配的地址才被認爲是本地。所以localpart@[a.d.d.r]能夠匹配爲localpart in canonical(5) and virtual(5)。這樣就不需要把防火牆的ip地址寫到postfix配置文中去了。
2 mynetworks = 127.0.0.0/8 12.34.56.0/24
3 relay_domains = example.com
4 parent_domain_matches_subdomains =
5 debug_peer_list smtpd_access_maps
6 smtpd_recipient_restrictions =
7 permit_mynetworks reject_unauth_destination
8
9 relay_recipient_maps = hash:/etc/postfix/relay_recipients
10 transport_maps = hash:/etc/postfix/transport
11
12 /etc/postfix/relay_recipients:
13 [email protected] x
14 [email protected] x
15 . . .
16
17 /etc/postfix/transport:
18 example.com smtp:[inside-gateway.example.com]
解釋:
•第1-7行:接受來自$mynetworks的郵件,接受發給[email protected]的郵件,但是不接受來自[email protected]的郵件。關鍵在第4-5行。
以[email protected](而不是[email protected])發送郵件的缺點是:發送給root和其他系統賬號的郵件也被傳遞到了中心mailhost服務器上了。爲了實現給這些賬戶的郵件在本機上傳遞,你可以按照下面的方法使用虛擬別名的辦法:
1 /etc/postfix/main.cf:
2 virtual_alias_maps = hash:/etc/postfix/virtual
3
4 /etc/postfix/virtual:
5 root root@localhost
6 . . .
解釋:
•第5行:正如virtual(5)手冊中描述的那樣:root匹配root@site,當site等於$myorigin時,或者當site在$mydestination的之中,或者他與$inet_interfaces/$proxy_interfaces值匹配。
在防火牆後面安裝postfix的最簡單方法是:把所有的郵件發送給網關服務器,讓郵件網關負責內外部郵件的轉發。示例參見上文的本地網絡部分。防火牆後面安裝postfix更好的方法是:僅把發送到公網的郵件傳遞給郵件網關,發送到內部的郵件直接進行投遞。
注意:這個例子要求postfix2.0及以後的版本。使用"postconf mail_version"查看postfix的版本
2 transport_maps = hash:/etc/postfix/transport
3 relayhost =
4 # Optional for a machine that isn't "always on"
5 #fallback_relay = [gateway.example.com]
6
7 /etc/postfix/transport:
8 # Internal delivery.
9 example.com :
10 .example.com :
11 # External delivery.
12 * smtp:[gateway.example.com]
解釋:
•第2,7-12行:要求內部的郵件直接進行投遞,外部的郵件傳遞給郵件網關。這個例子假設使用內部DNS的MX記錄。中括號[]提示postfix不要進行mx查找。
配置postfix作爲主/備份mx主機
這部分展現了額外的配置參數。你需要把它與該文檔上半部分的基本配置參數結合起來。
當你的系統是備份的MX郵件主機時,參見下面的設置:
2 the.backed-up.domain.tld IN MX 100 your.machine.tld.
3
4 /etc/postfix/main.cf:
5 relay_domains = . . . the.backed-up.domain.tld
6 smtpd_recipient_restrictions =
7 permit_mynetworks reject_unauth_destination
8
9 # You must specify your NAT/proxy external address.
10 #proxy_interfaces = 1.2.3.4
11
12 relay_recipient_maps = hash:/etc/postfix/relay_recipients
13
14 /etc/postfix/relay_recipients:
15 [email protected] x
16 [email protected] x
17 . . .
18 /etc/postfix/main.cf:
19 transport_maps = hash:/etc/postfix/transport
20
21 /etc/postfix/transport:
22 the.backed-up.domain.tld relay:[their.mail.host.tld]
重要提示:
不要在mydestination,virtual_alias_domains和virtual_mailbox_domains中the.backed-up.domain.tld寫進來。
•在master.cf中的relay入口的結尾指定"-o fallback_relay ="(不包括引號)
•在傳輸表中,指定"relay:nexthop..."(不包括引號)作爲右邊的內容。
撥號主機上的postfix
這部分內容應用於撥號的主機(也指該主機經常不在線)。
如果你的郵件主機經常關機,postfix沒有太多的機會把郵件投遞到難以到達的某個internet角落。把這個郵件傳遞給那些一直在線的郵件服務器是一個很好的選擇。在下面的例子中,中括號[]是爲了告訴postfix不要進行mx查找。
/etc/postfix/main.cf:
relayhost = [smtprelay.someprovider.com]
正常情況下,postfix將嘗試以它便利的方式傳遞出站郵件。如果你的郵件主機使用使用了on-demand撥號IP,這將會導致你的郵件系統在發送新郵件時,自動撥號。爲了阻止這樣的撥號,禁用自發的SMTP郵件傳遞。
/etc/postfix/main.cf:
defer_transports = smtp (Only for on-demand dialup IP hosts)
/etc/postfix/main.cf:
disable_dns_lookups = yes (Only for on-demand dialup IP hosts)
把下面的命令複製到PPP或SLIP撥號腳本中:
/usr/sbin/sendmail -q (whenever the Internet link is up)
#!/bin/sh
/usr/sbin/sendmail -q
sleep 10
while mailq | grep '^[^ ]*\*' >/dev/null
do
sleep 10
done
沒有公網主機名的postfix主機
這部分適用於那些沒有公網主機名的主機。一般情況是:這些主機通過ISP的DHCP獲得動態的IP地址。postfix可以讓你用假想(fantasy)的名字來收發郵件系統帳戶間的郵件。但是你不能用假想(fantasy)名字來收發公網的郵件,因爲這會導致公網用戶無法回覆你的郵件。實際上,越來越多的郵件系統會拒絕域名不存在的郵件。
postfix 2.2使用通用的地址映射方法用internet有效地址來替換本地假想(fantasy)的郵件地址。這個地址映射僅當郵件出站時纔會被使用;
1 /etc/postfix/main.cf:
2 smtp_generic_maps = hash:/etc/postfix/generic
3
4 /etc/postfix/generic:
5 [email protected] [email protected]
6 [email protected] [email protected]
7 @localdomain.local [email protected]
老版本的postfix解決方案是使用一個有效的internet地址,讓postfix把有效的internet地址轉換爲本地的假想(fantasy)地址。你能給內網和公網用戶發送郵件。
2 myhostname = hostname.localdomain
3 mydomain = localdomain
4
5 canonical_maps = hash:/etc/postfix/canonical
6
7 virtual_alias_maps = hash:/etc/postfix/virtual
8
9 /etc/postfix/canonical:
10 your-login-name [email protected]
11
12 /etc/postfix/virtual:
13 [email protected] your-login-name
解釋:
•第2-3行:這裏替換你的假想(fantasy)主機名。
當改變了virtual表的內容時,執行"postmap /etc/postfix/virtual"命令