Getting SMTP to use a specific IP address

Hi, I'm still in my first month as Linoder, and loving it so far, but I have one issue that I haven't been able to figure out.

I have several domains running on my single Linode, and I bought an extra IP address to run one specific domain on. Everything is set up fine using the Linode DNS server, including the reverse DNS. So I have:

Domain A on xx.xx.xx.xx

Domain B on yy.yy.yy.yy

Domain C on yy.yy.yy.yy

and

xx.xx.xx.xx maps back to Domain A

yy.yy.yy.yy maps back to Domain B

I am running Wordpress blogs on all three domains (yy.yy.yy.yy) and have configured them to email me via SMTP and Google Apps whenever a new comment is added.

The problem is that the Google see the emails as all coming from the same IP address (xx.xx.xx.xx) even if they are being sent from domains B and C.

What's even more puzzling is that the "Received-SPF" line in the emails contains the "members.linode.com" domain name for the other IP address (yy.yy.yy.yy)!

Like this:

Received-SPF: pass (google.com: domain of www-data@liyyy-yy.members.linode.com designates xx.xx.xx.xx as permitted sender) client-ip=xx.xx.xx.xx;

I just checked emails from all three domains, and this line in all of them (on both IP addresses) is exactly the same.

So what's happening here? I believe WordPress uses PHP's mail() API under the covers, so is there a way to configure it to use the correct IP address when sending mail, or is this something on the Linode end?

What I really want is complete separation of the blogs on the different IP addresses. It all seems to be working fine when using ping and tracert, so why is Google getting cross-linked information when I send emails to my Google apps mail server?

3 Replies

liyyy-yy is the hostname of your Linode. If you want something else you need to change it.

hostname NEW_HOST_NAME

This can be used to temporarily change it to NEWHOSTNAME.

You need to change hostname based on IP address. More about this: http://www.linuxmail.info/postfix-multi … -greeting/">http://www.linuxmail.info/postfix-multiple-ip-address-smtp-greeting/

Thanks for the reply. The members.linode.com names are no longer showing up. I had already changed the reverse DNS names for my ip addresses the day before, but I guess it just took longer to propagate the changes than I expected.

However, the emails are all still being sent via one of the two ip addresses, no matter which ip address the source domain is assigned to.

After some more digging, WordPress is using a PHP application called PHPMailer which uses something else called PHPSmtp to connect directly with (in this case) Gmail's SMTP server, so postfix doesn't enter into the equation.

The 'hostname' is set to "aaa.com" and appears in the "Received:" line of the email header but I'm still getting this:

Received: from aaa.com (bbb.com [69.164.bbb.bbb])

Note also that 69.164.bbb.bbb is set to "eth0:1" and 69.164.aaa.aaa is set to "eth0" so I would have thought that by default, all emails should come from the aaa address. Very strange.

In other words, the SMTP code seems to be supplying the correct domain but either the underlying code or Gmail is still identifying the email as coming from the wrong IP address and (I assume) reverse DNS'ed domain name.

I guess I could start using postfix on my own machine to handle the outgoing emails, but it seems to be overkill for what I want, which is just the occasional email sent to a commenter on my blog.

So if anyone has any idea how to get WordPress or PHP to behave itself – or even tell if it's possible or not, then I would be very grateful.

I'll keep digging.

Update: Success!!

Figured it out once I had the magic Google formula and found the right web page:

http://blog.nachtarbeiter.net/2008/08/2 … p-address/">http://blog.nachtarbeiter.net/2008/08/21/binding-phps-fsockopen-to-a-specific-ip-address/

The problem is that the older PHP fsocketopen API doesn't allow you to bind to a specific IP address, and just uses whatever is the default IP address for PHP (not sure how that is calculated, but whatever).

The trick is to substitute the newer socket APIs from PHP5 when opening the port to the SMTP server, since they do allow you to bind to a specific IP address (which you can get for any domain name using the gethostbyname PHP API.)

The good news is that I can now send emails from WordPress blogs on both IP addresses without worrying that they will be cross-contaminated.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct