Ads 468x60px

Pages

2011年3月9日 星期三

sendmail 本地送信 masquerade 設定-解決 From, Reply-To的問題


環境:
- Linux kernel: 2.6.18-164.11.1.el5.centos.plus
- Distribution: CentOS release 5.4 (Final)
- 主機名稱:w1.xfs.tw.mydomain.com

需求:將本機(例如以 shell: /usr/sbin/sendmail -t ...) 送出的信件,From, Reply-To 重寫為 noreply@mydomain.com,讓收件人無法回覆這一封系統發出的信件。

預設:sendmail 的基本設定會將 From: noreply@mydomain.com 的 mydomain.com 改為主機名稱,如 w1.xfs.tw.mydomain.com. 這樣會暴露我們的主機名稱,並且也不是我們想要達到的目的。

修改:sendmail 的設定檔,預設是存在 /etc/mail/sendmail.cf(給神人看的), 我們要看及修改的是 /etc/mail/sendmail.mc, 修改完畢之後,再做以下動作,以更新 sendmail.cf 檔,最後再重啟 sendmail 的 service.

/#
/# cd /etc/mail
/etc/mail# m4 ./sendmail.mc > sendmail.cf
/etc/mail# /sbin/service sendmail restart

sendmail.mc 稱作 m4 的參數檔,通常檔名均取為 filename.mc 這樣的附檔名格式,你可以在 /usr/share/sendmail-cf/cf 裡面找到相當多的範例檔案喔!例如 Red Hat 的設定範例檔為 /usr/share/sendmail-cf/cf/redhat.mc (如果是 Red Hat 7.3 以後版本,含 Red Hat 9 ,這個檔案則放置在 /etc/mail/sendmail.mc 喔!)。這個環境參數設定檔的設定項目很多,其格式為:

設定元件(`設定項目', `參數一', `參數二')

仔細看到上面的例子當中,在設定的元件後面接上小括號,而小括號內則為該設定元件的項目內容,以及該項目內容的參數!而將設定項目與各參數包起來的『並不是單引號』,要注意的是,在『設定項目』左右兩邊的:

1. 左邊的是 quod ,也就是鍵盤上面數字鍵 1 的左邊那個按鍵『`』;
2. 右邊的才是單引號『'』。

以下為 sendmail.mc 的修改之處(行號各版本可能不同)

81 dnl FEATURE(always_add_domain)dnl
160 MASQUERADE_AS(`mydomain.com')dnl
164 FEATURE(masquerade_envelope)dnl
168 FEATURE(masquerade_entire_domain)dnl
174 MASQUERADE_DOMAIN(`mydomain.com')dnl
175 MAILER(local)dnl
176 MAILER(smtp)dnl
177 dnl MAILER(procmail)dnl

說明:
1. 把 always_add_domain 註解掉,讓它不要加入 local domain
2. 開啟 masquerade_envelope 及 設定 MASQUERADE_AS()
3. 開啟 masquerade_entire_domain 及 設定 MASQUERADE_AS(), MASQUERADE_DOMAIN()

其他說明:
local
The local and prog mailers. You will almost always need these; the only exception is if you relay ALL your mail to another site. This mailer is included automatically.

masquerade_entire_domain
If masquerading is enabled (using MASQUERADE_AS) and MASQUERADE_DOMAIN is set, this feature will cause addresses to be rewritten such that the masquerading domains are actually entire domains to be hidden. All hosts within the masquerading domains will be rewritten to the masquerade name (used in MASQUERADE_AS). For example,if you have: MASQUERADE_AS(`masq.com') MASQUERADE_DOMAIN(`foo.org') MASQUERADE_DOMAIN(`bar.com') then *foo.org and *bar.com are converted to masq.com. Without this feature, only foo.org and bar.com are masqueraded.

masquerade_envelope
If masquerading is enabled (using MASQUERADE_AS) or the genericstable is in use, this feature will cause envelope addresses to also masquerade as being from the masquerade host. Normally only the header addresses are masqueraded.

0 意見:

張貼留言