Why Do I Get the Error "Name or service not known" When I Ping a Public Domain Name Configured for a Linux ECS?
Symptom
A public domain name configured for an ECS fails to be pinged, and the error message "Name or service not known" is displayed. However, the EIP of the ECS can be pinged.
Possible Causes
Generally, there are three possible causes:
- No or incorrect DNS server addresses are configured in /etc/resolv.conf.
- The DNS records are deleted from /etc/nsswitch.conf.
- The /lib64/libnss_dns.so.2 library file is missing.
Run the following command to view all files used for resolving the domain name:
# strace -e trace=open ping www.baidu.com -c 1
All files in the output affect domain name resolution.
Scenarios
The following procedure applies to ECSs running CentOS or EulerOS.
Solution
- No or incorrect DNS server IP addresses are configured in /etc/resolv.conf.
nameserver is the most important item in /etc/resolv.conf. A nameserver entry defines the IP address of the DNS server used for domain name resolution.
If there are no nameserver entries in /etc/resolv.conf, no DNS servers have been configured for domain name resolution. If there are multiple nameserver entries, the DNS servers are queried in the order listed in the file. The next DNS server is queried only when the previous one does not respond.
Check the IP addresses of DNS servers configured in /etc/resolv.conf.
- The DNS records are deleted from /etc/nsswitch.conf.
- Check whether /etc/nsswitch.conf contains the DNS records.
# grep hosts /etc/nsswitch.conf
If the output is as follows, the DNS option is not configured on the hosts line. As a result, the system does not read /etc/resolv.conf when resolving the domain name.
#hosts: db files nisplus nis dns hosts: files myhostname
- Open /etc/nsswitch.conf, locate the hosts line, and add the DNS option.
#hosts: db files nisplus nis dns hosts: files dns myhostname
hosts lists the tools by priority that are used to search for IP addresses paired with domain names.
file indicates the /etc/hosts file, and dns indicates DNS. By default, file is placed before dns. This means that the system first attempts to search for a domain name in /etc/hosts and then search for the domain name through DNS. If dns is not configured, DNS is not used.
- Check whether /etc/nsswitch.conf contains the DNS records.
- The /lib64/libnss_dns.so.2 library file is lost.
- /lib64/libnss_dns.so.2 is generated by the glibc package. Run the following command to check whether the package is modified.
# rpm -V glibc
Generally, in Linux, running the rpm -qf /lib64/libnss_dns.so.2 command can generate the library file.
If the output is as follows, /lib64/libnss_dns.so.2 is missing.
missing /lib64/libnss_dns.so.2
- Run the following command to create a soft link again:
Run the ls -l /lib64/libnss_dns.so.2 command on a normal ECS. The command output will show that the source file of /lib64/libnss_dns.so.2 is /usr/lib64/libnss_dns-2.17.so.
# ln -s /usr/lib64/libnss_dns-2.17.so /usr/lib64/libnss_dns.so.2
- /lib64/libnss_dns.so.2 is generated by the glibc package. Run the following command to check whether the package is modified.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.