从后缀中删除/隐藏客户端发件人 IP?

Kyl*_*yle 19 email postfix ip

我试图从 postfix 发送的电子邮件中隐藏客户端 IP。

这是我的意思的一个例子:

Received: from mail.[removed].com (adsl-75-37-61-254.dsl.frs2ca.sbcglobal.net [75.37.61.254])
    (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
    (No client certificate requested)
    by mail.[removed].com (Postfix) with ESMTP id D50C7BF185DD
    for <[removed]@gmail.com>; Thu,  2 Aug 2012 16:14:21 +0900 (JST)
Date: Thu, 02 Aug 2012 07:14:08 +0000
Run Code Online (Sandbox Code Playgroud)

注意这一行 (adsl-75-37-61-254.dsl.frs2ca.sbcglobal.net [75.37.61.254])

我想从电子邮件中删除该行。

我试过这样做:

/etc/postfix/main.cf :

smtp_header_checks = regexp:/etc/postfix/smtp_header_checks
Run Code Online (Sandbox Code Playgroud)

smtp_header_checks :

/^((.*) [(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])])/    IGNORE
Run Code Online (Sandbox Code Playgroud)

但是我的 IP 地址仍然在电子邮件的接收部分之内。如果我从本地 smtp 服务器发送电子邮件,则 IP 地址变为localhost.localdomain [127.0.0.1]

如何从标头中删除客户端 IP?

Thi*_*his 15

main.cf

smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
Run Code Online (Sandbox Code Playgroud)

dynamicmaps.cf

# Use your real path to dict_pcre.so, below
pcre    /usr/lib/postfix/dict_pcre.so           dict_pcre_open
Run Code Online (Sandbox Code Playgroud)

你应该把它放在你的/etc/postfix/smtp_header_checks

/^Received: .*/     IGNORE
/^X-Originating-IP:/    IGNORE
Run Code Online (Sandbox Code Playgroud)

然后运行

# /etc/init.d/postfix reload
Run Code Online (Sandbox Code Playgroud)


Lek*_*eyn 7

要从新邮件提交的 Received 标头中删除发件人 IP,请使用header_checks密钥而不是smtp_header_checks选项:

header_checks = regexp:/etc/postfix/header_checks_submission
Run Code Online (Sandbox Code Playgroud)

smtp_header_checks选项仅适用于从 Postfix 发送到外部服务器的邮件,而该header_checks选项适用于从您的客户端发送到 Postfix 的传入邮件。

另请参阅http://www.postfix.org/OVERVIEW.html上的Postfix 如何接收邮件获取组件概述,邮件来自 smtpd -> 清理 -> 传入队列。该smtpd进程接收邮件并注入Received带有发件人 IP 地址的标头。该header_checks(5)选项由cleanup(8)清理电子邮件标头的组件处理。

这是建议设置这样一个header_checks在全球范围内main.cf选择,因为这将修改接收的报头的所有电子邮件,即使是那些从外部服务器接收。相反,您应该将您的客户端配置为通过端口 587 上的专用提交服务发送电子邮件,并将 Postfix 配置为仅重写这些经过身份验证的提交的标头。

在 中/etc/postfix/master.cf,在该-o行之后添加以下几submission行:

submission inet n       -       y       -       -       smtpd
  # Require SASL authentication
  -o smtpd_sasl_auth_enable=yes
  # Require TLS transport security, do not leak your credentials in plaintext.
  -o smtpd_tls_security_level=encrypt`
  # Disallow unauthenticated users from sending mail through this port.
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  # Use a different cleanup service (see below)
  -o cleanup_service_name=ascleanup
Run Code Online (Sandbox Code Playgroud)

时间配置清理服务uthenticated小号ubmissions。我选择名称ascleanup以保持简短和对齐,但任何名称都有效。为此,请在同一文件中复制清理服务行master.cf,但重命名第一个字段并添加一个新选项以选择过滤器文件:

cleanup   unix  n       -       y       -       0       cleanup
ascleanup unix  n       -       y       -       0       cleanup
  -o header_checks=pcre:/etc/postfix/header_checks_submission
Run Code Online (Sandbox Code Playgroud)

(使用该pcre表需要postfix-pcre在 Debian 上安装,它会自动更新 dynamicmaps.cf 文件。对此无需进一步更改。)

最后一部分是 中的实际过滤器配置/etc/postfix/header_checks_submission。您可能会使用以下内容:

/^Received: .*/ IGNORE
Run Code Online (Sandbox Code Playgroud)

这将删除完整的 Received 标题行,但您也可以from helo.host (reverse.host.name [192.0.2.1])在保留其他信息的同时删除该部分:

/^Received: from [^ ]+ \([^ ]+ \[[IPv0-9a-f:.]+\]\)\s+(.* \(Postfix\) with .+)$/ REPLACE Received: $1
Run Code Online (Sandbox Code Playgroud)

如果您确实更改了mail_name选项,请更改Postfix单词以匹配您的配置。(此模式基于 Postfix 源代码smtpd/smtpd.c是准确的。)

我在 Debian buster 上使用 postfix 3.4.7-0+deb10u1 对此进行了测试。有关使用相同方法的另一个很好的描述,请参阅使用 Postfix 发送电子邮件时,如何在 Received 标头中隐藏发件人的 IP 和用户名?

经过上面的修改,下面变成了Received: by ...

Received: from debian (unknown [IPv6:fe80::b036:2ff:fe6e:73f4])
        by mail.example.nl (Postfix) with ESMTPSA id 1571B910B
        for <some@example.com>; Sun, 12 Jan 2020 02:23:15 +0000 (UTC)
Run Code Online (Sandbox Code Playgroud)