Score:0

postfix: how to force IPv4 through SMTP?

co flag

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.

cn flag
Bob
You can prefer IPv4 https://serverfault.com/q/1049845/546643 over IPv6
in flag
You should probably fix your IPv6 instead, ensure your PTR, SPF and DKIM is correct and you should mostly be good.
VaNa avatar
co flag
This is probably why it came through IPv6: *"With Postfix 2.8 the default is "ipv6"; earlier implementations are hard-coded to prefer IPv6 over IPv4."* source: http://www.postfix.org/postconf.5.html#smtp_address_preference
Score:1
gf flag

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

but nothing prevent you from fixing your dns/SPF over ipv6 as it is said in comment. regards.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.