Postfix: Name service error for name=domain.com type=MX: Host not found, try again

Solution 1:

Well, this is embarrassing. As I predicted my problem was caused by the most obvious and trivial reason: lack of read access to /etc/resolv.conf for the postfix user o_0

As you probably know the postfix subproceses (smtp, smtpd, qmgr, etc) runs with the postfix user. All the comments and suggestion I've received has been related with problems accessing to DNS resolving data and the usual suspects has been SELinux or a chrooted postfix. You all were right in the final reason. Following an advice and tried:

# sudo -u postfix -H cat /etc/resolv.conf
cat: /etc/resolv.conf: Permission denied

So... What??

# ls -l /etc/resolv.conf
-rw-r-----. 1 root named 118 mar 28 20:34 /etc/resolv.conf

OMG!... then after a chmod o+r and restarting Postfix all the email on hold can be processed and sent and new mail is processed as expected.

I doubt I've changed the resolv.conf reading permissions but I can't be 100% sure. So finally the problem is fixed and I'm very sorry for stole the attention of all of you for this ridiculous reason. Thanks you all.

Solution 2:

step 1. i check gmail.com for access to mx record on my server. first i installed the bind server using yum install bind-utils and check rhe gmail.com by following command:

root@host# host -t mx gmail.com
;; connection timed out; no servers could be reached

so, i change my dns server to 8.8.8.8 using nmtui command and reboot my server...

after reboot I execute the host -t mx gmail.com and my timed out was fixed by thsi houtput:

root#host# host -t mx gmail.com
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.

But the main problem not solved yet for me... so, I did step 2...

step 2. Om my server not exist etc folder on /var/spool/postfix/.So, I created etc folder manually...Then, copy three file on it. /etc/host.conf , /etc/resolv.conf and /etc/servoces

root@host# mkdir /var/spool/postfix/etc
root@host# cp /etc/host.conf /var/spool/postfix/etc/
root@host# cp /etc/resolv.conf /var/spool/postfix/etc/
root@host# cp /etc/services /var/spool/postfix/etc/

The main problem of MX not solved yet...

step 3. I change mode of /etc/resolv.conf and /var/pool/postfix/etc/* to 1777 and fixed my problem

root@host# chmod 1777 /etc/resolve.conf
root@host# chmod 1777 -R /var/spool/postfix/etc

finally I restart the postfix service using systemctl restart postfix.service and my smtp worked fine!