Sendmail and nslookup resolution problems

domain-name-systememailemail-serverresolv.confsendmail

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

Best Answer

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.