这篇文档展现了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"命令