postfix – How to Force IPv4 Through SMTP in Postfix?

email-serveripv6postfixsmtpspf

Problem

I have successfully set up a Postfix mailserver with an SMTP interface, set up DKIM, DMARC, SPF, all that stuff.

But I had a problem when testing the delivery of emails to Gmail.

Namely, SPF would pass if I sent it by the sendmail command from the server (some of the ARC-Authentication-Results header content of the delivered message in Gmail):

spf=pass (google.com: domain of [email protected] designates xxx.xxx.xxx.xxx as permitted sender) [email protected];

where xxx.xxx.xxx.xxx is an IPv4 address of the server

but would fail if I connected to the server using SMTP and sent it that way with:

spf=fail (google.com: domain of [email protected] does not designate yyyy:yyyy:yyyy:yyyy:yyyy:yyyy:yyyy:yyyy as permitted sender) [email protected];

where yyyy:yyyy:yyyy:yyyy:yyyy:yyyy:yyyy:yyyy is an IPv6 address of the server.

Fix

I realized that the SPF DNS record is only set up for the IPv4 address so I set it up that it also works with the IPv6 and it started passing as

spf=pass (google.com: domain of [email protected] designates xxx.xxx.xxx.xxx as permitted sender) [email protected];

where xxx.xxx.xxx.xxx is the IPv4 address of the server (weird)

Questions

  1. Is there a way to force IPv4 when sending through the SMTP? Most machines nowadays should handle IPv6 but I would be happier if it didn't touch the IPv6 when I don't want to.
  2. How is it possible that before it failed due to IPv6 not being present in the SPF DNS record but now it passes with IPv4 after I added IPv6?

If there are any settings needed to be known, let me know. There are many lines of config files so it wouldn't be practical to post them all.

Best Answer

it is as simple as postconf -e "inet_protocols = ipv4"

but nothing prevents you from fixing your DNS/SPF over ipv6 as it is said in comment.

Related Topic