理想未来ってなんやねん

娘可愛い。お父さん頑張る。

Received: from localhost (xxx [127.0.0.1])を消す

postfixの小ネタ


amavisdをインストールすると内部で中継されて以下のようなReceivedヘッダーが追加されます。

Received: from localhost (xxxxxx [127.0.0.1])
	by mail.xxxxxx.co.jp (Postfix) with ESMTP id E5399210066;
	Thu, 18 Feb 2010 12:18:50 +0900 (JST)
Received: from mail.xxxxxx.co.jp ([127.0.0.1])
 by localhost (mail.xxxxxx.co.jp [127.0.0.1]) (amavisd-maia, port 10024)
 with ESMTP id 04418-14; Thu, 18 Feb 2010 12:18:48 +0900 (JST)

localhostの情報まで見えてしまうのはカッコ良いものではないので、できれば削除したいものです。


postfixでReceivedヘッダーを消すには、header_checksで

/^Received:.*127\.0\.0\.1/ IGNORE

と記載すれば消えるはずですが、amavisdを入れていると何故か上手くいきません。


調べた結果、解決できたのでメモに残しておきます。

amavisd.confの設定

まず下記のヘッダーを除去します。

Received: from mail.xxxxxx.co.jp ([127.0.0.1])
 by localhost (mail.xxxxxx.co.jp [127.0.0.1]) (amavisd-maia, port 10024)
 with ESMTP id 04418-14; Thu, 18 Feb 2010 12:18:48 +0900 (JST)


これは非常に簡単でamavisd.confに1行追加するだけで変更できます。

$insert_received_line = 0;


変更後amavisdを再起動してください。

master.cfの設定

次に本題の下記のヘッダーが取り除きます。

Received: from localhost (xxxxxx [127.0.0.1])
	by mail.xxxxxx.co.jp (Postfix) with ESMTP id E5399210066;
	Thu, 18 Feb 2010 12:18:50 +0900 (JST)


header_checksが機能しない原因はno_header_body_checksで、amavisdをインストールするとmaster.cfは下記のように設定されているかと思います。

127.0.0.1:10025 inet n  -       n       -       -       smtpd
    -o content_filter=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o smtpd_restriction_classes=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_data_restrictions=reject_unauth_pipelining
    -o smtpd_end_of_data_restrictions=
    -o mynetworks=127.0.0.0/8
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_milters=
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
    -o receive_override_options=no_address_mappings,no_header_body_checks,no_unknown_recipient_checks


127.0.0.1:10025の最後の部分に、

    -o receive_override_options=no_address_mappings,no_header_body_checks,no_unknown_recipient_checks

とあり、no_header_body_checksと記載されています。


no_header_body_checksが付いていると、body_checksおよびheader_checksが機能しなくなります。
前段でbody_checksおよびheader_checksがされていることから、no_header_body_checksを付けて簡略化しているのようですが、このままだと自分でつけたReceivedヘッダーを除去できません。


no_header_body_checksを外すことでheader_checksが機能するようになりますが、そのまま取ってしまうと、header_checksが2重で実行されることになります。


そこで、127.0.0.1:10025の場合はlocalhostのみを除去するheader_checksに変更します。
まず、header_checksはcleanupの機能ですので、新たにcleanup2を作成しlocalhostのみを除去するlocal_header_checksというファイルを用意し使用するようにします。
そして127.0.0.1:10025の場合のみcleanup_service_nameをcleanup2に上書きすることで、2重で実行を防げるようになります。


変更後の内容は下記の通りです。

127.0.0.1:10025 inet n  -       n       -       -       smtpd
    -o content_filter=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o smtpd_restriction_classes=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_data_restrictions=reject_unauth_pipelining
    -o smtpd_end_of_data_restrictions=
    -o mynetworks=127.0.0.0/8
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_milters=
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
    -o cleanup_service_name=cleanup2
    -o receive_override_options=no_address_mappings,no_unknown_recipient_checks
cleanup2  unix  n       -       n       -       0       cleanup
    -o header_checks=regexp:/etc/postfix/local_header_checks


local_header_checksは下記のように記載します。
実際にヘッダーに記載される内容に応じて適当に置き換えて下さい。

/^Received: from localhost \(xxxxxx \[127\.0\.0\.1\]\)/ IGNORE


/Received:.*127\.0\.0\.1/ IGNOREでも除去することが可能ですが、先頭から指定しています。
(smtpd_bannerに127.0.0.1とか入れているスパマーがいた場合にそのヘッダーも除去されてしまうので…)


変更が終わったらpostfix reloadで設定を反映します。



以上、そんな感じで。