CentOS – Server Can Ping IPs but Not Domains

centos

I have 3 servers with DigitalOcean (AMS3). Suddenly, three servers at the same time faced the same issue. It seems the servers cannot connect to the outside world. I tried to ping different IP addresses and domains. Here are the results:

ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmpseq=1 ttl=60 time=2.11 ms
64 bytes from 8.8.8.8: icmpseq=2 ttl=60 time=0.946 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=60 time=0.724 ms

ping google.com
ping: google.com: Name or service not known

I searched for a solution on StackOverflow, ServerFault, and DO Community. There were suggestions that the file /etc/resolv.conf might have issues. Here is my /etc/resolv.conf file:

cat /etc/resolv.conf
; Created by cloud-init on instance boot automatically, do not edit.
nameserver 8.8.8.8
nameserver 8.8.4.4

The contents of other files you may want to see:

cat /etc/nsswitch.conf

passwd:     files sss
shadow:     files sss
group:      files sss
#initgroups: files sss

#hosts:     db files nisplus nis dns
hosts:      files dns myhostname

# Example - obey only what nisplus tells us...
#services:   nisplus [NOTFOUND=return] files
#networks:   nisplus [NOTFOUND=return] files
#protocols:  nisplus [NOTFOUND=return] files
#rpc:        nisplus [NOTFOUND=return] files
#ethers:     nisplus [NOTFOUND=return] files
#netmasks:   nisplus [NOTFOUND=return] files

bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files sss

netgroup:   nisplus sss

publickey:  nisplus

automount:  files nisplus sss
aliases:    files nisplus

cat /etc/sysconfig/network-scripts/ifcfg-eth0

BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=174.138.0.1
HWADDR=16:68:53:c5:4e:5e
IPADDR=174.138.X.Y
IPADDR1=10.18.0.19
IPV6ADDR=2A03:B0C0:0002:00D0:0000:0000:X:Y/64
IPV6INIT=yes
IPV6_DEFAULTGW=2A03:B0C0:0002:00D0:0000:0000:0000:0001
MTU=1500
NETMASK=255.255.240.0
NETMASK1=255.255.0.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=no

dig google.com @8.8.8.8

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> google.com @8.8.8.8
;; global options: +cmd
;; connection timed out; no servers could be reached

dig google.com @2001:4860:4860::8888

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> google.com @2001:4860:4860::8888
;; global options: +cmd
;; connection timed out; no servers could be reached

cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 bizcloud-vds bizcloud-vds
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

::1 bizcloud-vds bizcloud-vds
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

174.138.XXX.YYY           cm105srv.ABC.ir cm105srv

Any help is appreciated.

Best Answer

To configure an interface to use particular DNS servers, add the following lines to the ifcfg file:

 PEERDNS=no
 DNS1=ip-address
 DNS2=ip-address

where ip-address is the address of a DNS server. This will cause the network service to update /etc/resolv.conf with the specified DNS servers specified. Only one DNS server address is necessary, the other is optional.