Postfix允许dynamic更改“myhostname”吗? 我遇到了很多,但没有发现任何质的。 我的安装是一个后缀多个域,多个ip(在master.cf中调整)和多个dkim sig,但master.cf中的myhostname指令不包括在内。
那种东西:
192.168.1.12:smtp inet n - n - - smtpd -o myhostname=mail.mail2.com -o smtpd_banner=mail.mail2.com -o smtp_helo_name=mail.mail2.com
无论如何,banner和helo都可以,但myhostname仍然是main.cf中包含的
Postfix是高度可configuration的。 以至于看起来似乎只比看细意(仅在开玩笑)稍微有点优势。
事实上有很多种dynamic覆盖静态configuration的方法。 至less要了解一下Postfix工作stream程。 这是在概述 。
了解以下内容也很有用:
main.cf静态configuration的不同部分。 main.cf和master.cf静态configuration 感兴趣的方法是有条件的:
smptd监听端口 显然,在这方面,由于原因很快有希望变得清晰起来,Wietse Venema在Postfix 2.7中做了一些关键的改变来处理内容过滤 ,所以总结一下:
Postfix 2.7之前:
在未指定的情况下,默认的nexthop目标是$ myhostname(即:
localhost)。
Postfix 2.7及以上版本:
在未指定的情况下,默认的nexthop目标是收件人域。
通过使用
sender_dependent_default_transport_maps支持通过发件人域进行传输的开箱即用
这个区别是有问题的,因为还有一些人坚持使用2.7以前的postfix安装。例如:对于一些依赖官方rpms的红帽用户,例如用户仍然使用centOS 5x => Postfix 2.3和centOS 6x =>后缀2.6(但我可能是错的, dyor等 )
事情变得更容易! 下面是一些方法。
第一种方法包括设置一些smtpd守护进程,监听不同的非标准端口,并使用自定义传输条件,根据哪个smtpd端口将我们的出站邮件提交给:
这是通过dynamic定义一个自定义filter服务和覆盖smtpd服务中的content_filter指令来实现的。 filter是一个虚拟的。 我们不是真的要写和部署我们自己的自定义filter服务。 相反,我们只是劫持一个postfix smtp服务实例,以便在电子邮件最终被推广之前获取访问权限并dynamic覆盖myhostname指令。
这只能发生在Postfix 2.7及以上,因为指定的传输的默认nexthop目标被定义为收件人域 。 在Postfix 2.7以下的版本中,它被定义为$myhostname ,所以电子邮件循环回到Postfix,导致它成为博克。
第二种方法是通过本书,并使用sender_dependent_default_transport_maps有条件地将我们的出站电子邮件路由到几个自定义传输; 并取决于发件人的域名:
sender_dependent_default_transport_maps行为与sender_dependent_relayhost_maps相似,但不是将发送邮件从指定的发件人域路由到指定的目标域, sender_dependent_default_transport_maps使用sender_dependent_default_transport_maps将发送邮件从指定的发件人(域)内部路由到在master.cf 定义的指定(自定义)传输 master.cf 。
我们将以下指令添加到/etc/postfix/main.cf :
sender_dependent_default_transport_maps = hash:/etc/postfix/sender_transports
然后创build映射文件/etc/postfix/sender_transports :
@parrots.tld custom3_smtp: @penguins.tld custom4_smtp:
使用postmap构build数据库:
postmap hash:/etc/postfix/sender_transports
然后我们在/etc/postfix/master.cf定义所有的自定义传输:
custom4_smtp unix - - n - - smtp -o myhostname=mailer.external.penguins.tld -o smtp_bind_address=mnop -o smtp_helo_name=penguins.tld custom3_smtp unix - - n - - smtp -o myhostname=mailer.external.parrots.tld -o smtp_bind_address=ijkl -o smtp_helo_name=parrots.tld custom2_smtp unix - - n - - smtp -o myhostname=mailer.external.cats.tld -o smtp_bind_address=efgh -o smtp_helo_name=cats.tld custom1_smtp unix - - n - - smtp -o myhostname=mailer.external.dogs.tld -o smtp_bind_address=abcd -o smtp_helo_name=dogs.tld # our main internal entry for the dogs site; all outgoing dogs traffic is # sent to this (non-standard) port and routed to our custom1_smtp transport 10026 inet n - n - - smtpd -o myhostname=mailer.internal.dogs.tld -o content_filter=custom1_smtp: # our main internal entry for the cats site; all outgoing cats traffic is # sent to this (non-standard) port and routed to our custom2_smtp transport 10027 inet n - n - - smtpd -o myhostname=mailer.internal.cats.tld -o content_filter=custom2_smtp: # default smtpd entry; outgoing traffic sent to this port (25) will get routed # subject to the conditions in our sender_dependent_default_transport_maps file smtp inet n - n - - smtpd -o myhostname=mailer.internal.tld # hoorah. #
Postfix像素通常build议的方式是设置多个Postfix实例。
但是,在这里,对Postfix工作stream程的理解能够派上用场……因为通过devise一个定制的Postfix服务链 ,只需一个Postfix实例也可以实现。 main.cf没有任何内容需要更改。 静态configuration可以在我们在master.cf定义的自定义服务链中dynamic覆盖。
每个服务读取它自己的子集,位于main.cfconfiguration中的所有指令。 因此,当我们沿着我们的定制服务链前进时,我们可以覆盖链中每个相应Postfix服务中可能允许的任何设置。
(另外,请注意,我们甚至可以为我们自己定制的任何默认Postfix守护进程replace,这非常酷)。
在/etc/postfix/master.cf :
# each Postfix service reads it's own subset of directives from main.cf config. # many settings can be dynamically overridden as we move thro the service chain.. # here we override the $myhostname setting depending upon which port we send our # outgoing smtp email to. # custom2 cats service chain custom2_cleanup unix n - - - 0 cleanup -o queue_service_name=custom2_qmgr custom2_qmgr fifo n - n 300 1 qmgr -o rewrite_service_name=custom2_rewrite custom2_rewrite unix - - n - - trivial-rewrite -o default_transport=custom2_smtp: custom2_smtp unix - - n - - smtp -o myhostname=mailer.external.cats.tld -o smtp_bind_address=efgh -o smtp_helo_name=cats.tld # custom1 dogs service chain custom1_cleanup unix n - - - 0 cleanup -o queue_service_name=custom1_qmgr custom1_qmgr fifo n - n 300 1 qmgr -o rewrite_service_name=custom1_rewrite custom1_rewrite unix - - n - - trivial-rewrite -o default_transport=custom1_smtp: custom1_smtp unix - - n - - smtp -o myhostname=mailer.external.dogs.tld -o smtp_bind_address=abcd -o smtp_helo_name=dogs.tld # our main internal entry for the dogs site; all outgoing dogs traffic is # sent to this (non-standard) port and routed to our custom1 service chain 10026 inet n - n - - smtpd -o myhostname=mailer.internal.dogs.tld -o cleanup_service_name=custom1_cleanup # NB: attempting to override the content_filter directive # *will not work* in postfix < 2.7 since an unspecified nexthop # destination defaults to localhost and causes the email to loop # -o content_filter=custom1_smtp: # our main internal entry for the cats site; all outgoing cats traffic is # sent to this (non-standard) port and routed to our custom2 service chain 10027 inet n - n - - smtpd -o myhostname=mailer.internal.cats.tld -o cleanup_service_name=custom2_cleanup # yeehar! acu ;) #
注1 :是一个警告:
虽然指令(如cleanup_service_name和rewrite_service_name 被logging在configuration参数中 ,但它们似乎没有被logging为任何Postfix 守护进程的可configuration选项参数。
因此,至less这似乎是一个无证的方法,因此可能会被官方圈起来,甚至可能被视为邪恶。 〜我不会知道,因为我永远无法形成一个足够的问题,永远勇敢[email protected]官方邮件列表!
注2 :
有一些人试图以其他想象力的方式做这种事情,比如设置一个header_checks FILTER,以便通过dynamic烹饪一个完整的transport:recipient-domain-destination克服默认的localhost nexthop transport:recipient-domain-destination :
在/etc/postfix/master.cf :
custom2_smtp unix - - n - - smtp -o myhostname=mailer.external.cats.tld -o smtp_bind_address=efgh -o smtp_helo_name=cats.tld custom2_cleanup unix n - - - 0 cleanup -o header_checks=regexp:/etc/postfix/custom2_header_checks #conditional processing contingent upon entry via some non-standard port 10027 inet n - n - - smtpd -o myhostname=mailer.internal.cats.tld -o cleanup_service_name=custom2_cleanup
然后在/etc/postfix/custom2_header_checks ,使用正则expression式将接收者域/etc/postfix/custom2_header_checks中提取出来,并将其提供给filter指令:
/^To:.*@(.*)$/ FILTER custom2_smtp:$1
虽然这似乎是一个好主意,并且部分工作,但它肯定是一个可怕的黑客; 可能是不安全的,至less在传出电子邮件包含多个收件人的情况下会失败。 咄!
注3 :
如果以上都没有任何意义,那么你可能需要做更多的rtfming;)
但严重的是,我知道这里有很多东西..由于各种原因,我无法控制, 业务停滞在Postfix 2.3上,我需要花费5分钟以上的时间来整理它们的需求。 我的小时费率已经下降到哥斯达黎加菠萝采摘者的水平 (只有我没有从他们的哥斯达黎加生活中受益)。 所以我试图把这一切都放在脑海里,而不仅仅是鹦鹉官方的文件。 希望这样可以帮助下一个发生在这条路上的可怜的灵魂;)
经过很多testing,我必须得出结论,你不能这样做。 有可能dynamic更改myhostname,它不会影响Received头。
有横幅使用$ myhostname的testing,我可以看到它改变时,我使用
-o myhostname=test.test.test
但收到的标题没有。
我尝试在main.cf中使用
mydomain=test.test.test myhostname=$mydomain
这确实会影响Received头和横幅。 但试图重写$ mydomain
-o mydomain=test.test.test
只会再次影响到旗帜。
因此,似乎在Received头中使用的variables是从$ myhostname填充的, 然后从命令行参数中覆盖$ myhostname。