external smtp ip appears as local

  • I have a mail server behind a pfsense firewall and set it to verify the spf record of the sending server but when I send a test from gmail, the email gets rejected because it appears as if gmail's ip address is which it obviously is not.

    Not sure where to start looking for a solution. here's the rejection message I get:

    host mail.be-o.com[] said: 550 5.7.1
    dusanlazarevic@be-o.com: Recipient address rejected: Message rejected due
    to: domain owner discourages use of this host. Please see
    (in reply to RCPT TO command

  • Hi,

    From your mail server, when you resolve gmail.com using ping, host and dig, do you really receive as a host ?

    The SPF of the MX of be-o.com is :

    root@ns311465:~# dig be-o.com TXT +short
    "v=spf1 ip4:"

    This :

    @vladanpopovic said in [external smtp ip appears as local](/post/862949):
    > host mail.be-o.com[] said: 550 5.7.1
    > dusanlazarevic@be-o.com: Recipient address rejected: Message rejected due
    > to: domain owner discourages use of this host. Please see
    > http://www.openspf.net/Why?s=mfrom;id=vladanpopoxxxxxx@gmail.com;ip=;r=dusanlazarevic@be-o.com
    > (in reply to RCPT TO command

    is what your server (log) said to you ?

    Btw : woooow, openspf.net and org are down for me ...

  • yes that's the correct spf for our server - what I don't get is why the email from gmail is rejected and why does the ip appear in http://www.openspf.net/Why?s=mfrom;id=vladanpopoxxxxxx@gmail.com;ip=;r=dusanxxxxxxx@be-o.com

    yes it seems that openspf is down

  • When a mail arrives at your mail server (postfix ?) you instructed to have the mail parsed by a SPF 'plugin'.
    The SPF checks if the domain of the sender - declared sender mail or "from:" mail has a SPF record, which is acyually a TXT record these days, with a special format.

    This what it does when a mail from gmail comes in - your dusanxxxxxxx@be-o.com :

    dig gmail.com TXT +short
    "v=spf1 redirect=_spf.google.com"

    There is a redirect, so :

    dig _spf.google.com  TXT +short
    "v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"

    These "netblocks" list all the IP addresses gmail is using, example :

    dig _netblocks.google.com TXT +short
    "v=spf1 ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ip4: ~all"

    Now, the actual check is easy :
    The IP4 or IPv6 address gmail was using when it send your mail must be in one of these blocks.

    Or, your SPF check comes back with : did you email come from ? Who is ?
    Can the system where your mail server and SPF check is running, do a good DNS resolution (ie : do the dig's) ?

    What is in the headers of the mails ?

    Btw : this is not an pfSense issue, more a "mail issue". But, don't worry, I'm using postfix with SPF, DKIM, DMARC (they are all needed if you want to send mail to gmail / hotmail / yahoo / etc ....) so we'll figure it out.

    Normally, your SPF addon or plugin comes with a manual and is using config files. So it most probable you can activate the SPF debug facilities to see what is happening.
    When setting up a mail server that actually works, you'll be looking at log files for the rest of your live, testing all the debug methods - using mail accounts from pretty any mail supplier on the planet.

    Is this a home setup ? Else where ? My mail server runs on a Debian on a dedicated server on the net. There isn't even a firewall on this server - just fail2ban to block bots.

    edit :
    A mail from my gmail to a mail I host myself( gertjan@my-domaine.tld ) :

    Sep  5 10:40:34 ns311465 postfix/smtpd[31732]: connect from mail-io1-xd30.google.com[2607:f8b0:4864:20::d30]
    Sep  5 10:40:34 ns311465 postfix/smtpd[31732]: Trusted TLS connection established from mail-io1-xd30.google.com[2607:f8b0:4864:20::d30]: TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)
    Sep  5 10:40:35 ns311465 postfix/policy-spf[31734]: Policy action=PREPEND Received-SPF: pass (gmail.com ... _spf.google.com: Sender is authorized to use 'my-mail@gmail.com' in 'mfrom' identity (mechanism 'include:_netblocks2.google.com' matched)) receiver=ns311465.ip-188-165-201.eu; identity=mailfrom; envelope-from="my-mail@gmail.com"; helo=mail-io1-xd30.google.com; client-ip="2607:f8b0:4864:20::d30"
    Sep  5 10:40:35 ns311465 postfix/smtpd[31732]: A4F7563E0373: client=mail-io1-xd30.google.com[2607:f8b0:4864:20::d30]
    Sep  5 10:40:35 ns311465 postfix/cleanup[31737]: A4F7563E0373: message-id=<CAD_ygHUFAgSs4wv_zut_9zR0vTmeNxKssh+uE-eH_VU1sEaZFg@mail.gmail.com>
    Sep  5 10:40:35 ns311465 opendmarc[1243]: A4F7563E0373: gmail.com pass
    Sep  5 10:40:35 ns311465 opendkim[1229]: A4F7563E0373: DKIM verification successful
    Sep  5 10:40:36 ns311465 postfix/qmgr[24576]: A4F7563E0373: from=<my-mail@gmail.com>, size=2855, nrcpt=1 (queue active)
    Sep  5 10:40:36 ns311465 postfix/smtpd[31732]: disconnect from mail-io1-xd30.google.com[2607:f8b0:4864:20::d30]
    Sep  5 10:40:36 ns311465 return-from-amavis/smtpd[31742]: B334963E1599: client=localhost.localdomain[]
    Sep  5 10:40:36 ns311465 postfix/cleanup[31737]: B334963E1599: message-id=<CAD_ygHUFAgSs4wv_zut_9zR0vTmeNxKssh+uE-eH_VU1sEaZFg@mail.gmail.com>
    Sep  5 10:40:36 ns311465 postfix/qmgr[24576]: B334963E1599: from=<my-mail@gmail.com>, size=3940, nrcpt=1 (queue active)
    Sep  5 10:40:36 ns311465 postfix/smtp[31738]: A4F7563E0373: to=<gertjan@my-domaine.tld>, relay=localhost[]:10024, delay=1.9, delays=1.1/0.02/0/0.77, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[]:10025): 250 2.0.0 Ok: queued as B334963E1599)
    Sep  5 10:40:36 ns311465 postfix/qmgr[24576]: A4F7563E0373: removed
    Sep  5 10:40:36 ns311465 postfix/virtual[31743]: B334963E1599: to=<gertjan@my-domaine.tld>, relay=virtual, delay=0.14, delays=0.05/0.01/0/0.08, dsn=2.0.0, status=sent (delivered to maildir)
    Sep  5 10:40:36 ns311465 postfix/qmgr[24576]: B334963E1599: removed

    As you can see, the third line validates that the source is actually 'gmail'.
    And opendkim and opendmarc are fine also.

  • LAYER 8

    @Gertjan the problem here is that the external ip of gmail is rewritten to and presented to the mail server that reject it obviusly

    so the point here is what option/package do that?
    i have some postfix servers myself behind pfsense but never encountered such behavior
    some misconfigured proxy maybe or you have something wrong in advanced outbound NAT
    rule that NAT's from the WAN to your LAN could rewrite the source

  • is the gateway ip on the pfsense for the dmz.
    the gateway ip for the lan is
    the email server is indeed postfix and I can send and receive emails (when no spf checking) so I don't think there is any dns problem.

    here are the headers of a successful delivery without spf checking:
    X-Synology-Spam-Flag: ⁨no⁩
    X-Received: ⁨by 2002:a17:90a:c70e:: with SMTP id o14mr2999852pjt.56.1567677993037; Thu, 05 Sep 2019 03:06:33 -0700 (PDT)⁩
    X-Gm-Message-State: ⁨APjAAAV5doh0JoEKLeIEuMZNN0RjSmvwLRRn/L02wV8xBydPAw/gr7q8 WpZ63Of3mYsfRpuXVd39jB+UzvwR7os=⁩
    Return-Path: ⁨vladanpopovic389@gmail.com
    Return-Path: ⁨vladanpopovic389@gmail.com
    X-Google-Smtp-Source: ⁨APXvYqx3TZvG0tZRPS4u+hd6pZ+impJrOF9B+w6B8jVZqnFzvIvOxS3NU/99hyF05Vb9UlXQ17H/hQ==⁩
    Mime-Version: ⁨1.0 (Mac OS X Mail 12.4 (3445.104.11))⁩
    Authentication-Results: ⁨decani.be-o.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CiHo8k/p⁩
    X-Synology-Virus-Status: ⁨no⁩
    X-Mailer: ⁨Apple Mail (2.3445.104.11)⁩
    Dkim-Signature: ⁨v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=CiHo8k/pEHnK8ioeo+ekDBbl82nMU/KaWfI5Su+28dGGlNVq7F1LosV0d0Z86dJBgQ hcbO/tdBgVeuepa4xyuZri40FVbaTrktehRcgvObhPDdiZjrUs2deG/MN+LhMfpUAdlE YnOf27mZK3mLRXN5OaRjXJ8lxedQcfjXgKV/8NjodUop7hwY74qgYczf9X0CKIHZVL1a lEplkdRNfvwCt7nWxej8CjzXPzFs/imCGl82Z+1hNedeY4m7DpfahV+vUPDJrEtL1SvS IdpJyJL6gEMhqr79/WKpvQ8HF8XBkoGPF/7U/y4Nl1r5Zt92gJiYPE+5z1RZgVlr/ogl sQaA==⁩
    Content-Transfer-Encoding: ⁨7bit⁩
    X-Google-Dkim-Signature: ⁨v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id📅to; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=ZeYoS3/G7hllKXaYc5ba09XCaMB6+b/gz/cYt/ORYOan6JM7w4zW5euzmCL+2HLwFZ tLKUGT3LCmhjt+48qbO3K7tziXv58h8yOveVKwwViF/qUFbkEhIx0ClceE4Zq7XHTc37 Oqv0FLm6FkYbC8tBIL8ZwWSVee5q/9wTZDDVwFvoFfMm3BNzg5wUg3I6ADPNTxvf8K8w DC3P4ekGaXW7ueUKVs+d+FUb0FkejCxYmeLXAwibapxU7wPfnInmqL4q3aTJKfbaX6ey z57Pck65CT3Wq5zLd5rfrXDp5oXLxQnFSS25D+ihEm2/BgwsCob/uWj3n/HtLFoxlxjV plsg==⁩
    Content-Type: ⁨text/plain; charset=us-ascii⁩
    Delivered-To: ⁨vladanpopovic@be-o.com⁩
    X-Original-To: ⁨vladanpopovic@be-o.com⁩
    Received: ⁨from mail-pf1-f175.google.com (mail-pf1-f175.google.com []) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by decani.be-o.com (Postfix) with ESMTPS id 95CC22BBC3B for vladanpopovic@be-o.com; Thu, 5 Sep 2019 18:06:35 +0800 (CST)⁩
    Received: ⁨by mail-pf1-f175.google.com with SMTP id q10so1438406pfl.0 for vladanpopovic@be-o.com; Thu, 05 Sep 2019 03:06:35 -0700 (PDT)⁩
    Received: ⁨from [] (061238132018.ctinets.com. []) by smtp.gmail.com with ESMTPSA id q20sm4587299pfg.85.2019. for vladanpopovic@be-o.com (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Sep 2019 03:06:32 -0700 (PDT)⁩

  • LAYER 8

    ok so it's not a pfsense problem, maybe there is some problem with the order in wich you pass the email through the milters
    can you post a log with spf enabled?

  • actually I can't - it seems to be delivering now with spf check being on ... not sure what changed - I need to clarify before posting more.

    thank you very much for your help @Gertjan & @kiokoman

    I will post again if I can reliably replicate the problem

  • @vladanpopovic said in external smtp ip appears as local:

    actually I can't

    Oh, yes you can.
    The filter, or better, as @kiokoman stated, a milter, can be made verbose to see what happens.

    I have this in my master.cf file :

    policyd-spf-perl  unix  -       n       n       -       -       spawn
    	user=nobody argv=/usr/local/bin/perl /usr/lib/postfix/policyd-spf-perl -v

    "policyd-spf-perl " is a Debian package, and known as a postfix milter.

    You see the -v option ?

    I added it.

    You can also changing

    my $VERBOSE = 0;


    my $VERBOSE = 1;

    in /usr/lib/postfix/policyd-spf-perl

    Instead of one line that details SPF operations like DUNNO, fail or pass, I get the whole boat load.

    Here are the details https://pastebin.com/qxdg9QKX

    Just an idea : you have to open this file : /usr/lib/postfix/policyd-spf-perl and add a gateway like this :

    use constant relay_addresses => map(
    			2001:xxxxx:52:cff::1286/128 )
    ); # add addresses to qw (  ) above separated by spaces using CIDR notation.
    # mail2.aaa-bbbb-fumel.fr
    # 92.xxxx.20.243/32 2001:xxxx:52:cff::1286/128

    If I didn't do this, mails received by mail MX backup (when the main MX is down) would be marked bad by this SPF filter - sorry : milter.

    You use probably another milter for SPF. Just check the doc of the source - or even better : check the source - it's perl or bash or something like that. Making it verbose is always - not difficult -.

Log in to reply