Ошибка ping unknown host

“ping: cannot resolve Unknown host” is an error message that typically appears when the ping command is used to try and reach a hostname that cannot be resolved to an IP address. This can happen for a few reasons:

  • The hostname does not exist: The hostname may have been typed incorrectly or the host may no longer exist on the network.
  • DNS server is not working properly: The DNS server may be down or not configured correctly.
  • The hostname is not registered in the DNS: The hostname may not be registered in the DNS server and therefore cannot be resolved to an IP address.
  • Network connectivity issue: The system may not have internet access or there may be a problem with the router or network connection.

At first, I thought the problem might be with the website I was trying to reach. I started by checking my internet connection to make sure it was working properly.

I noticed that my computer was connected to the network but it did not fix the problem.

In the end, I found that the issue was related to the DNS server.

In this article, let’s dive into this issue and see how to fix it.

understanding ping: cannot resolve Unknown host

The ping command is a tool used to test network connectivity by sending ICMP echo request and measuring the round-trip time and packet loss.

When a computer needs to access another network host, it needs to know the IP address of that host.

The process of converting a hostname (e.g., www.example.com) to an IP address is called “DNS resolution.”

The computer sends a request to a DNS server to resolve the hostname to an IP address.

If the computer is unable to resolve the hostname, you will receive the error message “ping: cannot resolve Unknown host.”

hostname is typed correctly

If the hostname was typed incorrectly or if the host is no longer on the network, the ping command will not be able to resolve the hostname to an IP address, resulting in this error message ping: cannot resolve Unknown host.

So make sure to double-check the spelling of the hostname to ensure that it is correct.

If you can login the remote host, you can use hostname command to verify it. This command will display the current hostname of the system.

DNS server is working properly

You can try one or more of the following methods to make sure that the DNS server is configured correctly and that it is able to resolve hostnames to IP addresses.

Using the dig command: The dig command is used to query DNS servers for information. You can use this command to check the resolution of a specific hostname by running the command “dig google.com” in a terminal.

The command will return the IP address associated with the hostname along with other DNS record information.

% dig google.com

; <<>> DiG 9.10.6 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41563
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;google.com. IN A

;; ANSWER SECTION:
google.com. 0 IN A 74.125.24.139
google.com. 0 IN A 74.125.24.100
google.com. 0 IN A 74.125.24.101
google.com. 0 IN A 74.125.24.102
google.com. 0 IN A 74.125.24.113
google.com. 0 IN A 74.125.24.138

If you get a response, that means your DNS server is working properly.

Checking the /etc/resolv.conf file: The /etc/resolv.conf file contains the IP addresses of the DNS servers that the system is configured to use.

You can check this file to make sure that the DNS server IP addresses are correct and that the file is not corrupted.

# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

hostname is registered in the DNS Server

If the DNS server is working properly, the next step would be to verify that the hostname record for your system is registered and configured correctly on the DNS server.

You can use the dig command to check the hostname record for your system by running the command “dig hostname” in a terminal.

Here is an example of how to use the “dig” command to look up information about a hostname:

dig example.com

This command will perform a DNS lookup for the hostname “example.com” and return information such as the IP address associated with the hostname,

If there is no DNS record for your hostname, you can use the /etc/hosts file.

The /etc/hosts file contains a list of hostnames and their corresponding IP addresses. You can open this file using a text editor and check for the hostname you are trying to verify.

By adding an entry to this file, you can resolve a hostname to an IP address without the need for a DNS server. This can be useful for resolving hostnames when DNS is not available.

To add an entry in the /etc/hosts file, follow these steps:

  • Open a terminal window and gain root access by running the command ‘sudo su -‘
  • Use a text editor such as nano or vi to open the /etc/hosts file. For example, you can run the command ‘nano /etc/hosts’
  • Add a new line at the bottom of the file with the following format: IP_address hostname aliases. For example, “192.168.1.100 myserver”
  • Save the changes to the file by pressing ‘Ctrl + X’ then ‘Y’ and ‘Enter’
  • Verify the changes by running the command ‘cat /etc/hosts’
  • Once you have added the entry in the /etc/hosts file, you can test it by using the ping command to test the hostname resolution

I recently upgraded from Ubuntu 12.04 to Ubuntu 14.04. After restarting I have WiFi connected and/or LAN connection with no internet access. I’m using Toshiba Satellite C855D.

$ sudo lshw -C network

  *-network               
       description: Wireless interface
       product: RTL8188CE 802.11b/g/n WiFi Adapter
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: wlan0
       version: 01
       serial: c0:d9:62:8d:39:85
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=rtl8192ce driverversion=3.13.0-24-generic firmware=N/A ip=192.168.0.109 latency=0 link=yes multicast=yes wireless=IEEE 802.11bgn
       resources: irq:16 ioport:3000(size=256) memory:f0200000-f0203fff
  *-network
       description: Ethernet interface
       product: RTL8101E/RTL8102E PCI Express Fast Ethernet controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:06:00.0
       logical name: eth0
       version: 05
       serial: 00:8c:fa:49:e0:4d
       size: 10Mbit/s
       capacity: 100Mbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=half firmware=rtl_nic/rtl8105e-1.fw latency=0 link=no multicast=yes port=MII speed=10Mbit/s
       resources: irq:41 ioport:2000(size=256) memory:f0104000-f0104fff memory:f0100000-f0103fff

$ ifconfig -a

eth0      Link encap:Ethernet  HWaddr 00:8c:fa:49:e0:4d   
          UP BROADCAST MULTICAST  MTU:1500  Metric:1 
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000  
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B) 

lo        Link encap:Local Loopback   
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope:Host 
          UP LOOPBACK RUNNING  MTU:65536  Metric:1 
          RX packets:727 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:727 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:0  
          RX bytes:56993 (56.9 KB)  TX bytes:56993 (56.9 KB) 

wlan0     Link encap:Ethernet  HWaddr c0:d9:62:8d:39:85   
          inet addr:192.168.0.109  Bcast:192.168.0.255  Mask:255.255.255.0 
          inet6 addr: fe80::c2d9:62ff:fe8d:3985/64 Scope:Link 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
          RX packets:1934 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000  

$ 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: icmp_seq=1 ttl=47 time=47.2 ms 
64 bytes from 8.8.8.8: icmp_seq=2 ttl=47 time=44.8 ms 
64 bytes from 8.8.8.8: icmp_seq=3 ttl=47 time=43.6 ms 
64 bytes from 8.8.8.8: icmp_seq=4 ttl=47 time=156 ms 

$ ping google.com

ping: unknown host google.com

$ nslookup google.com 8.8.8.8

Server:     8.8.8.8 
Address:    8.8.8.8#53 

Non-authoritative answer: 
Name:   google.com 
Address: 190.167.241.187 
Name:   google.com 
Address: 190.167.241.178 
Name:   google.com 
Address: 190.167.241.163 
Name:   google.com 
Address: 190.167.241.183 
Name:   google.com 
Address: 190.167.241.177 
Name:   google.com 
Address: 190.167.241.172 
Name:   google.com 
Address: 190.167.241.153 
Name:   google.com 
Address: 190.167.241.162 
Name:   google.com 
Address: 190.167.241.167 
Name:   google.com 
Address: 190.167.241.152 
Name:   google.com 
Address: 190.167.241.168 
Name:   google.com 
Address: 190.167.241.182 
Name:   google.com 
Address: 190.167.241.157 
Name:   google.com 
Address: 190.167.241.173 
Name:   google.com 
Address: 190.167.241.148 
Name:   google.com 
Address: 190.167.241.158 

$ cat /etc/resolvconf/resolv.conf.d/head                   

# 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 8.8.8.8 

$ sudo service networking restart

stop: Job failed while stopping 
start: Job is already running: networking 

$ nm-tool

NetworkManager Tool 

State: connected (global) 

- Device: eth0 ----------------------------------------------------------------- 
  Type:              Wired 
  Driver:            r8169 
  State:             unavailable 
  Default:           no 
  HW Address:        00:8C:FA:49:E0:4D 

  Capabilities: 
    Carrier Detect:  yes 
    Speed:           100 Mb/s 

  Wired Properties 
    Carrier:         off 


- Device: wlan0  [Honey Nut Cheerios] ------------------------------------------ 
  Type:              802.11 WiFi 
  Driver:            rtl8192ce 
  State:             connected 
  Default:           yes 
  HW Address:        C0:D9:62:8D:39:85 

  Capabilities: 
    Speed:           18 Mb/s 

  Wireless Properties 
    WEP Encryption:  yes 
    WPA Encryption:  yes 
    WPA2 Encryption: yes 

  Wireless Access Points (* = current AP) 
    *Honey Nut Cheerios: Infra, 00:21:29:EF:11:2D, Freq 2437 MHz, Rate 54 Mb/s, Strength 78 WPA2 
    Claro8AD:        Infra, 00:1A:2B:B0:69:CD, Freq 2462 MHz, Rate 54 Mb/s, Strength 27 WPA2 
    CLAROB5F570:     Infra, 88:25:2C:B5:F5:70, Freq 2412 MHz, Rate 54 Mb/s, Strength 20 WEP 
    WIND30:          Infra, 00:1F:FB:68:E3:6C, Freq 2427 MHz, Rate 54 Mb/s, Strength 37 WPA 
    dd-wrt_vap:      Infra, 02:1C:10:34:41:15, Freq 2437 MHz, Rate 54 Mb/s, Strength 24 WPA 

  IPv4 Settings: 
    Address:         192.168.0.109 
    Prefix:          24 (255.255.255.0) 
    Gateway:         192.168.0.1 

    DNS:             8.8.8.8 
    DNS:             8.8.4.4 

Добрый день возникла проблема, что не работает

fsockopen('ssl://smtp.mail.ru', 465 , $errno, $errstr, 30)

php_network_getaddresses: getaddrinfo failed: Name or service not known

Дошел до того что сделал ping mail.ru
ping: unknown host mail.ru

Что с этим делать подскажите пожалуйста?
Как я понимаю, это настройка сервера.
centos7 стоит

cat /etc/resolv.conf
nameserver 141.8.192.2

ping tells me that it can’t resolve some hostname («ping: unknown host domain.company.local») in a URL but when I use host or nslookup on the same computer on the command line, the resolutions works fine (i.e. it’s fast and reliable).

What could be causing this?

More testing: Firefox, wget and ping have the same problem. Pinging the IP address works.

OS: Linux (Ubuntu 13.04)

EDIT My /etc/resolv.conf reads:

nameserver 127.0.1.1
search domain.company.local

netstat reports:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -               

so something is running on this port (nslookup also reports it uses 127.0.1.1 as DNS server).

There is no /etc/*inetd.conf, so I’m not sure which application serves this port.

It seems that dnsmasq is used:

/usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces
   --pid-file=/var/run/NetworkManager/dnsmasq.pid --listen-address=127.0.1.1
   --conf-file=/var/run/NetworkManager/dnsmasq.conf --cache-size=0 --proxy-dnssec
   --enable-dbus=org.freedesktop.NetworkManager.dnsmasq
   --conf-dir=/etc/NetworkManager/dnsmasq.d

All the config files and folders are empty. Since nslookup says it uses 127.0.1.1#53 my guess is that dnsmasq works even without a configuration. But how does it know which parent DNS to query?

EDIT2 Disabling dnsmasq as suggested by harrymc didn’t help. So I ran strace ping which gave me this odd output (just the interesting parts):

open("/etc/host.conf", O_RDONLY|O_CLOEXEC) = 4
read(4, "127.0.0.1tlocalhostn#127.0.1.1ta"..., 4096) = 613
...
open("/lib/libnss_mdns4_minimal.so.2", O_RDONLY|O_CLOEXEC) = 4
read(4, "177ELF2113>1f"..., 832) = 832
...
mmap(NULL, 2105560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) = 0x7f7829b00000
...
socket(PF_FILE, SOCK_STREAM, 0)         = 4
fcntl(4, F_GETFD)                       = 0
fcntl(4, F_SETFD, FD_CLOEXEC)           = 0
connect(4, {sa_family=AF_FILE, path="/var/run/avahi-daemon/socket"}, 110) = 0
fcntl(4, F_GETFL)                       = 0x2 (flags O_RDWR)
fstat(4, {st_mode=S_IFSOCK|0777, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f782a4f8000
lseek(4, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
write(4, "RESOLVE-HOSTNAME-IPV4 domain.com"..., 44) = 44
read(4, "-15 Timeout reachedn", 4096)  = 20

So ping looks in /etc/hosts which makes sense. Then it loads and mmap()s /lib/libnss_mdns4_minimal.so.2 which makes sense as well.

But then it talks to avahi!?

Which led me to this forum post: ping doesn’t make a dns request.

My /etc/nsswitch.conf also contains this line:

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

If I ping a working address, I see that the process also loads /lib/libnss_mdns4_minimal.so.2 but then, it does a DNS query via port 53.

So my guess is now that /lib/libnss_mdns4_minimal.so.2 is somehow noticing that the IP address ends with .local and not with .com and then the [NOTFOUND=return] is triggered.

How do I fix this?

I’ve configured the DNS settings for a host (admin.example-preprod.foobar.it with IP 100.100.100.100) but it does not resolve from every server I try (it does for some).

For example, I’m on a server which uses the following 3 DNS servers:

foobar@server:~$ cat /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 200.200.200.1
nameserver 200.200.200.2
nameserver 200.200.200.3

dig works for all of them.

first:

foobar@server:~$ dig admin.example-preprod.foobar.it @200.200.200.1

; <<>> DiG 9.9.5-3ubuntu0.7-Ubuntu <<>> admin.example-preprod.foobar.it @200.200.200.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6540
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 2
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;admin.example-preprod.foobar.it.        IN      A

;; ANSWER SECTION:
admin.example-preprod.foobar.it. 86400 IN A      100.100.100.100

;; AUTHORITY SECTION:
foobar.it.               86400   IN      NS      qwert.foobar.it.
foobar.it.               86400   IN      NS      ns0.xname.org.
foobar.it.               86400   IN      NS      ns1.xname.org.

;; ADDITIONAL SECTION:
qwert.foobar.it.         86400   IN      A       200.200.200.1

;; Query time: 46 msec
;; SERVER: 200.200.200.1#53(200.200.200.1)
;; WHEN: Fri Nov 04 10:35:46 EET 2016
;; MSG SIZE  rcvd: 156

second:

foobar@server:~$ dig admin.example-preprod.foobar.it @200.200.200.2

; <<>> DiG 9.9.5-3ubuntu0.7-Ubuntu <<>> admin.example-preprod.foobar.it @200.200.200.2
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 40127
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;admin.example-preprod.foobar.it.        IN      A

;; AUTHORITY SECTION:
foobar.it.               85817   IN      SOA     qwert.foobar.it. webmaster.foobar.it. 2016092901 10800 900 1814400 10800

;; Query time: 3 msec
;; SERVER: 200.200.200.2#53(200.200.200.2)
;; WHEN: Fri Nov 04 10:36:05 EET 2016
;; MSG SIZE  rcvd: 111

third:

foobar@server:~$ dig admin.example-preprod.foobar.it @200.200.200.3

; <<>> DiG 9.9.5-3ubuntu0.7-Ubuntu <<>> admin.example-preprod.foobar.it @200.200.200.3
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2392
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;admin.example-preprod.foobar.it.        IN      A

;; ANSWER SECTION:
admin.example-preprod.foobar.it. 86400 IN A      100.100.100.100

;; AUTHORITY SECTION:
foobar.it.               86400   IN      NS      qwert.foobar.it.
foobar.it.               86400   IN      NS      ns1.xname.org.
foobar.it.               86400   IN      NS      ns0.xname.org.

;; ADDITIONAL SECTION:
qwert.foobar.it.         81845   IN      A       200.200.200.1

;; Query time: 2309 msec
;; SERVER: 200.200.200.3#53(200.200.200.3)
;; WHEN: Fri Nov 04 10:35:56 EET 2016
;; MSG SIZE  rcvd: 156

but then, when I try to ping it gives me unknown host:

foobar@server:~$ ping admin.example-preprod.foobar.it
ping: unknown host admin.example-preprod.foobar.it

How is that possible and where should I look at to solve the problem?

Понравилась статья? Поделить с друзьями:
  • Ошибка ping timeout
  • Ошибка p2192 kia ceed
  • Ошибка pin inapp unknown 9 при активации office
  • Ошибка p2191 форд фокус
  • Ошибка pin inapp invalid pin 8 office