Postfix

virtual_alias_domains - 轉發郵件時如何使用不同的 IP 地址?

  • February 9, 2015

我在具有 4 個 IP 地址的 CentOS 6.6 Linux 伺服器上託管 2 個 Web 域(domain1.com 和 domain2.com)。

Postfix 2.6.6 接受郵件到info@domain1.cominfo@domain2.com並將它們轉發到person1@gmail.comperson2@gmail.com。這裡是配置文件的摘錄:

/etc/postfix/main.cf

inet_interfaces = all
inet_protocols = ipv4

virtual_alias_domains = domain1.com domain2.com
virtual_alias_maps = hash:/etc/postfix/virtual
smtp_generic_maps = hash:/etc/postfix/generic

/etc/postfix/虛擬

info@domain1.com        person1@gmail.com
info@domain2.com        person2@gmail.com

我的問題是第一個人(我父親,他從 1990 年開始從事網際網路業務)變成了很多垃圾郵件。我使用 Spamassassin 拒絕這些郵件,但有些郵件仍然通過,當轉發到person1@gmail.com時,它們會導致 Google 限制我的伺服器:

DFC32800849 3412 Fri Jan 30 11:40:38 PPQDikzMMZTedKR@hotmail.com(主機 alt1.gmail-smtp-in.l.google.com

$$ 74.125.130.26 $$說:421-4.7.0 $$ 144.76.123.123 15 $$我們的系統檢測到來自您的 IP 地址的不尋常的 421-4.7.0 未經請求的郵件。為了保護我們的 421-4.7.0 使用者免受垃圾郵件的侵害,從您的 IP 地址發送的郵件暫時受到 421-4.7.0 速率限制。請訪問 421-4.7.0 http://www.google.com/mail/help/bulk_mail.html查看我們的批量 421 4.7.0 電子郵件發件人指南。fl14si17784804pdb.81 - gsmtp(回复 DATA 命令的結尾)) person1@gmail.com

這會影響第二個人,他會在長時間延遲後將郵件發送到 person2@gmail.com

我的問題是是否可以配置 Postfix 以便它使用不同的 IP 地址(因為我的伺服器有 4 個)來轉發郵件?

謝謝,下面是目前的“postconf -n”輸出:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
header_checks = pcre:/etc/postfix/header_checks
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost
myhostname = www.domain1.com
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_destination_concurrency_limit = 2
smtp_destination_rate_delay = 40s
smtp_generic_maps = hash:/etc/postfix/generic
unknown_local_recipient_reject_code = 550
virtual_alias_domains = domain1.com domain2.com
virtual_alias_maps = hash:/etc/postfix/virtual

更新:

我已經按照undefined的建議修改了我的配置文件(謝謝!)然後postmap /etc/postfix/transport執行service postfix restart-

/etc/mail/master.cf:

smtp      unix  -       -       n       -       -       smtp
smtp-1    unix  -       -       n       -       -       smtp -o smtp_bind_address=my_ip_3
smtp-2    unix  -       -       n       -       -       smtp -o smtp_bind_address=my_ip_4

/etc/mail/transport

person1@gmail.com smtp-1:
person2@gmail.com smtp-2:

不幸的是,我仍然在傳遞的郵件標題中看到舊的問題my_ip_2 。

我怎樣才能驗證正在使用新的“運輸”?

以下是更改後的日誌摘錄:

Feb  7 14:56:50 www postfix/postsuper[14206]: Deleted: 92 messages
Feb  7 14:57:06 www postfix/anvil[14172]: statistics: max connection rate 1/60s for (smtp:37.233.142.116) at Feb  7 14:53:45
Feb  7 14:57:06 www postfix/anvil[14172]: statistics: max connection count 1 for (smtp:37.233.142.116) at Feb  7 14:53:45
Feb  7 14:57:06 www postfix/anvil[14172]: statistics: max cache size 1 at Feb  7 14:53:45
Feb  7 14:57:07 www postfix/smtp[14008]: warning: open active 6870A8007E8: No such file or directory
Feb  7 14:57:14 www postfix/smtpd[14213]: connect from mail-ie0-f171.google.com[209.85.223.171]
Feb  7 14:57:14 www postfix/smtpd[14216]: connect from unknown[213.179.214.207]
Feb  7 14:57:14 www postfix/smtpd[14213]: 3EBA0800187: client=mail-ie0-f171.google.com[209.85.223.171]
Feb  7 14:57:14 www postfix/cleanup[14218]: 3EBA0800187: message-id=<CAADeyWgtCh21w-_AbKaPrq_kj2A=YjRi7OXHyjjruL01MR6sqw@mail.gmail.com>
Feb  7 14:57:14 www postfix/qmgr[12668]: 3EBA0800187: from=<alexander.farber@gmail.com>, size=1707, nrcpt=1 (queue active)
Feb  7 14:57:14 www spamd[1856]: spamd: connection from localhost [127.0.0.1] at port 34152
Feb  7 14:57:14 www spamd[1856]: spamd: setuid to spam succeeded
Feb  7 14:57:14 www spamd[1856]: spamd: processing message <CAADeyWgtCh21w-_AbKaPrq_kj2A=YjRi7OXHyjjruL01MR6sqw@mail.gmail.com> for spam:502
Feb  7 14:57:14 www spamd[1856]: spamd: clean message (-1.9/5.0) for spam:502 in 0.0 seconds, 1670 bytes.
Feb  7 14:57:14 www spamd[1856]: spamd: result: . -1 - BAYES_00,FREEMAIL_FROM,HTML_MESSAGE,T_DKIM_INVALID scantime=0.0,size=1670,user=spam,uid=502,required_score=5.0,rhost=localhost,raddr=127.0.0.1,rport=34152,mid=<CAADeyWgtCh21w-_AbKaPrq_kj2A=YjRi7OXHyjjruL01MR6sqw@mail.gmail.com>,bayes=0.000000,autolearn=ham
Feb  7 14:57:14 www postfix/smtpd[14216]: 68890800246: client=unknown[213.179.214.207]
Feb  7 14:57:14 www postfix/pipe[14219]: 3EBA0800187: to=<Abram.Farber@gmail.com>, orig_to=<simplex@simplex.ru>, relay=spamassassin, delay=0.18, delays=0.13/0/0/0.05, dsn=2.0.0, status=sent (delivered via spamassassin service)
Feb  7 14:57:14 www postfix/qmgr[12668]: 3EBA0800187: removed
Feb  7 14:57:14 www postfix/pickup[14119]: 69FD7800187: uid=502 from=<alexander.farber@gmail.com>
Feb  7 14:57:14 www postfix/cleanup[14223]: 69FD7800187: message-id=<CAADeyWgtCh21w-_AbKaPrq_kj2A=YjRi7OXHyjjruL01MR6sqw@mail.gmail.com>
Feb  7 14:57:14 www postfix/qmgr[12668]: 69FD7800187: from=<alexander.farber@gmail.com>, size=2042, nrcpt=1 (queue active)
Feb  7 14:57:14 www spamd[1762]: prefork: child states: II
Feb  7 14:57:14 www postfix/smtpd[14213]: disconnect from mail-ie0-f171.google.com[209.85.223.171]
Feb  7 14:57:14 www postfix/cleanup[14218]: 68890800246: message-id=<187523230485881875322129321382@72wdyszvr.meetpeople.gen.in>
Feb  7 14:57:14 www postfix/qmgr[12668]: 68890800246: from=<eHarmonyPartner@meetpeople.gen.in>, size=13993, nrcpt=1 (queue active)
Feb  7 14:57:14 www spamd[1856]: spamd: connection from localhost [127.0.0.1] at port 34153
Feb  7 14:57:14 www spamd[1856]: spamd: setuid to spam succeeded
Feb  7 14:57:14 www spamd[1856]: spamd: processing message <187523230485881875322129321382@72wdyszvr.meetpeople.gen.in> for spam:502
Feb  7 14:57:14 www postfix/smtpd[14216]: disconnect from unknown[213.179.214.207]
Feb  7 14:57:14 www spamd[1856]: spamd: clean message (1.6/5.0) for spam:502 in 0.2 seconds, 13741 bytes.
Feb  7 14:57:14 www spamd[1856]: spamd: result: . 1 - BAYES_50,HTML_MESSAGE,RDNS_NONE,T_REMOTE_IMAGE,UNPARSEABLE_RELAY scantime=0.2,size=13741,user=spam,uid=502,required_score=5.0,rhost=localhost,raddr=127.0.0.1,rport=34153,mid=<187523230485881875322129321382@72wdyszvr.meetpeople.gen.in>,bayes=0.484741,autolearn=no
Feb  7 14:57:15 www postfix/pickup[14119]: 00CD6800247: uid=502 from=<eHarmonyPartner@meetpeople.gen.in>
Feb  7 14:57:15 www postfix/cleanup[14223]: 00CD6800247: message-id=<187523230485881875322129321382@72wdyszvr.meetpeople.gen.in>
Feb  7 14:57:15 www postfix/pipe[14219]: 68890800246: to=<Abram.Farber@gmail.com>, orig_to=<simplex@simplex.ru>, relay=spamassassin, delay=0.68, delays=0.43/0/0/0.25, dsn=2.0.0, status=sent (delivered via spamassassin service)
Feb  7 14:57:15 www postfix/qmgr[12668]: 68890800246: removed
Feb  7 14:57:15 www postfix/qmgr[12668]: 00CD6800247: from=<eHarmonyPartner@meetpeople.gen.in>, size=14341, nrcpt=1 (queue active)
Feb  7 14:57:15 www spamd[1762]: prefork: child states: II
Feb  7 14:57:47 www postfix/smtp[14008]: warning: open active A6F92801560: No such file or directory

不幸的是,在傳遞的測試郵件中仍然可以看到相同的 IP(受 Google 限制)144.76.184.154:

Delivered-To: abram.farber@gmail.com
Received: by 10.170.190.67 with SMTP id h64csp2513657yke;
       Sat, 7 Feb 2015 05:59:08 -0800 (PST)
X-Received: by 10.180.89.210 with SMTP id bq18mr14321108wib.45.1423317548028;
       Sat, 07 Feb 2015 05:59:08 -0800 (PST)
Return-Path: <alexander.farber@gmail.com>
Received: from www.afarber.de ([144.76.184.154])
       by mx.google.com with ESMTP id k10si7979060wif.41.2015.02.07.05.59.07
       for <Abram.Farber@gmail.com>;
       Sat, 07 Feb 2015 05:59:08 -0800 (PST)
Received-SPF: softfail (google.com: domain of transitioning alexander.farber@gmail.com does not designate 144.76.184.154 as permitted sender) client-ip=144.76.184.154;
Authentication-Results: mx.google.com;
      spf=softfail (google.com: domain of transitioning alexander.farber@gmail.com does not designate 144.76.184.154 as permitted sender) smtp.mail=alexander.farber@gmail.com;
      dkim=pass header.i=@gmail.com;
      dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Received: by www.afarber.de (Postfix, from userid 502)
   id 69FD7800187; Sat,  7 Feb 2015 14:57:14 +0100 (CET)
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.afarber.de
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
   HTML_MESSAGE,T_DKIM_INVALID autolearn=ham version=3.3.1
Received: from mail-ie0-f171.google.com (mail-ie0-f171.google.com [209.85.223.171])
   by www.afarber.de (Postfix) with ESMTP id 3EBA0800187
   for <simplex@simplex.ru>; Sat,  7 Feb 2015 14:57:14 +0100 (CET)

這不是我為 smtp-1 或 smtp-2 指定的 IP。

更新 2:

我已將“-v”添加到**/etc/postfix/master.cf**:

smtp      inet  n - n - - smtpd -o content_filter=spamassassin
....
smtp      unix  - - n - - smtp
smtp-1    unix  - - n - - smtp -o smtp_bind_address=144.76.184.155 -v
smtp-2    unix  - - n - - smtp -o smtp_bind_address=144.76.184.156 -v
....
spamassassin unix - n n - - pipe user=spam argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

現在在/var/log/maillog中查看更多 Spamassassin 消息。

這是更新後的“postconf -n”輸出(上面沒有顯示):

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
header_checks = pcre:/etc/postfix/header_checks
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost
myhostname = www.afarber.de
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_destination_concurrency_limit = 2
smtp_destination_rate_delay = 40s
smtp_generic_maps = hash:/etc/postfix/generic
unknown_local_recipient_reject_code = 550
virtual_alias_domains = videoskat.de balkan-preferans.de simplex.ru larissa-farber.de bukvy.de slova.de
virtual_alias_maps = hash:/etc/postfix/virtual

我在這裡看到兩個解決方案。

  1. (我多年前做過這樣的配置)Google使用許多 ip 作為 MX。您可以在傳輸地圖中定義,第一封郵件通過 gmail-smtp-in.l.google.com. 路由,第二封郵件通過 alt1.gmail-smtp-in.l.google.com 路由。然後 - 使用 iptables 和 nat/POSTROUTING - nat 通過第一個 ip 連接到第一個 google MX,並通過第二個 ip 連接到第二個 google MX。
  2. (未經測試,但應該可以)用於傳出郵件的 ip 是通過 smtp_bind_address 定義的。您可以在 master.cf 中定義第二個(和下一個)smtp 傳輸,例如:
smtp-1 unix - - n - - smtp -o smtp_bind_address=firstip
smtp-2 unix - - n - - smtp -o smtp_bind_address=secondip

然後在運輸地圖中定義如下:

person1@gmail.com smtp-1:
person2@gmail.com smtp-2:

您必須在 main.cf 文件中指定使用 transportmap 文件:

transport_maps = hash:/etc/mail/transport

並執行

postmap /etc/mail/transport

創建它的雜湊圖。

引用自:https://serverfault.com/questions/663979