4

On my Ubuntu server I've been trying to get the PHP mail() function to work by installing sendmail (I also have postfix installed but I gave up on it). However, when I try to send mail it gets queued with the following error in /var/log/mail.log:

sm-mta[xxx]: gethostbyaddr(x.x.x.x) failed: x

When I performed a nslookup (e.g. nslookup gmail.com) it said it couldn't resolved and the connection timed out. After spending all day on this and trying various things I decided to put the name servers of my domain into my interfaces file, as per: https://askubuntu.com/a/331636

This mitigated the problem I was having with nslookup but I still receive the same error in the logs when trying to send mail, except my public IP address isn't showing up, only the private one. e.g.

sm-mta[xxx]: gethostbyaddr(178.x.x.x) failed: x # public IP error not showing anymore
sm-mta[xxx]: gethostbyaddr(10.x.x.x) failed: x # private IP error still showing

I've looked at a lot of documentation on this and I'm still not sure what I'm doing wrong. I have checked that sendmail is using port 25. Since I am only sending mail out do I need to worry about DNS records concerning MX for my server?


/etc/resolv.conf:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 2001:4860:4860::8844
nameserver 2001:4860:4860::8888
nameserver 8.8.8.8

/etc/dhcp/dhclient.conf:

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

#send host-name "andare.fugue.com";
send host-name = gethostname();
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
#prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
    domain-name, domain-name-servers, domain-search, host-name,
    dhcp6.name-servers, dhcp6.domain-search,
    netbios-name-servers, netbios-scope, interface-mtu,
    rfc3442-classless-static-routes, ntp-servers,
    dhcp6.fqdn, dhcp6.sntp-servers;
#require subnet-mask, domain-name-servers;
#timeout 60;
#retry 60;
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/etc/dhcp3/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;

#alias {
#  interface "eth0";
#  fixed-address 192.5.5.213;
#  option subnet-mask 255.255.255.255;
#}

#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andare.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}

etc/hosts:

# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
127.0.1.1 domain.name
127.0.0.1 localhost.localdomain localhost
178.x.x.x domain.name

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
user103853
  • 43
  • 1
  • 7
  • So your problem is, that you can't resolve DNS-names? What's the content of `/etc/resolv.conf` and `/etc/dhcp/dhclient.conf`? I recommend setting a MX-Record. Raises credibility (spam detection) and you are able to receive messages for the postmaster. – sebix Jan 06 '15 at 19:29
  • @sebix I've added those conf files. Thanks, will do. – user103853 Jan 06 '15 at 19:45

3 Answers3

3

As you write, it had to work.

user1316146 is also right: gethostbyaddr is doing reverse ip lookups, which aren't needed for mail sending. The problem isn't here, on my opinion.

I think, you have simply a noisy network or a not really reliable local dns. You had to configure your sendmail to try to get its target address more agressively, and many times.

Or, maybe you should install a local cachingonly bind to make such problems more clear.

Or, maybe you should try a more robust mta, postfix is imho a good way.

3

As far as I can see you just want to send mails. In this case you must not set an MX record for the server, as your mail server is not responsible for any domain.

If I understand your problem, you really just want an MTA that relays your mails.

Setting up a full fledged mail server for this purpose is overkill; so first here are a few alternatives: https://unix.stackexchange.com/questions/1449/lightweight-outgoing-smtp-server

If you want to have a real mail server anyway, postfix would be preferable: https://askubuntu.com/questions/457003/setting-up-a-send-only-mail-server

However, your DNS problem is probably independent of this.

Of course it is desirable, that all IPs and hostnames used on your server can be resolved. To achieve this you would need a local nameserver for your local addresses (and names) that forwards any other requests to some other nameserver.

But there might be an easier way: The DNS lookups the mail server performs should depend on the mails sender and receiver domains. You should check, if those are correct and just limit yourself to names, that can be resolved. Maybe you have configured the From-address to point to some locally defined domain?

To debug this, you can try to send mails from the command line first and move on to PHP-mailer as soon as this works.

An example mail from the queue would be helpful to check this.

And could you please post the output of netstat -natp ? Just to see what IP addresses sendmail is bound to.

I know this answer is not complete, but this is as much as I can say at this point.

nlu
  • 661
  • 5
  • 9
  • Sendmail entries from `netstat -natp`: `tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN 2729/sendmail: MTA:` and `tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2729/sendmail: MTA:` – user103853 Jan 20 '15 at 18:51
  • This is ok. Can you post the complete log of the mail server for one mail, sent via your mailer? – nlu Jan 20 '15 at 19:00
2

gethostbyaddr is performing reverse DNS, so you need to have PTR records set up for the IP addresses in question. You also needs to have that address range delegated to you for public address.

If you're using 8.8.8.8 as your DNS for the box, you're not going to be able to have PTR records for the 10.0.0.0/8 network.

This lookup usually only occurs for mail being sent IN to the server as the mail server tries to determine the host name of the sender to compare it to the HELO message sent.

By the way, if you're just trying to send mail, the default postfix config works perfectly for that under Ubuntu.