How to remove client sender IP from postfix

There may have different methods to implement this feature. But I use the way from answer from serverfault.

First, I have to install postfix-pcre in my debian/ubuntu system,

sudo apt install postfix-pcre

Then, I defined a cleanup service in master.cf,

ascleanup   unix  n       -       y       -       0       cleanup
  -o header_checks=pcre:/etc/postfix/header_checks_submission

Let’s update submission and smtps in master.cf to use this cleanup service,

submission inet n       -       y       -       -       smtpd
  -o smtpd_sasl_auth_enable=yes
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_tls_auth_only=yes
  -o smtpd_reject_unlisted_recipient=no
  -o smtpd_recipient_restrictions=
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
  -o cleanup_service_name=ascleanup

smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_reject_unlisted_recipient=no
  -o smtpd_recipient_restrictions=
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
  -o cleanup_service_name=ascleanup

pickup    unix  n       -       y       60      1       pickup
cleanup   unix  n       -       y       -       0       cleanup
ascleanup   unix  n       -       y       -       0       cleanup
  -o header_checks=pcre:/etc/postfix/header_checks_submission

As you see above, ‘-o cleanup_service_name=ascleanup’ option was added into submission and smtps services.

The last, here is the content in /etc/postfix/header_checks_submission,

/^Received: .*/ IGNORE

Now, restart postfix and new configuration should be working. When you send a message from client via smtps/submission, you will see that client’s IP is removed from the headers.

Comment