Sub topic 6
Ping by IP address versus ping by name
This chapter assumes you can open a command prompt or terminal, know what an IP address is, and know that traffic crosses routers to leave your network. It also assumes you have read the earlier chapters on ipconfig and on reading ping output. Here the goal is narrower: using the difference between pinging an address and pinging a name to decide whether a fault is in connectivity or in name resolution.
Two different questions
A ping to an IP address asks one question: can my computer exchange ICMP echo messages with that host?
A ping to a name asks two questions in order:
- Can my computer turn this name into an IP address?
- Can it then reach that address?
The second question is the same as the first test. That makes the pair useful. If the address works and the name fails, the problem is almost certainly in the first step, name resolution. If both fail, the fault is probably in connectivity, or the target is filtering ICMP.
Name resolution is the job of DNS, the Domain Name System. Your computer asks a DNS server, usually the one listed in ipconfig /all, for the IP address that belongs to a name such as example.com. The answer is cached locally for a time.
What happens when you ping a name
When you run ping example.com, the tool does not send anything to example.com directly. The sequence is:
- The resolver checks the local DNS cache and the hosts file for an entry.
- If nothing is found, it sends a query to the configured DNS server.
- The DNS server replies with an address, or with an error.
- Ping sends ICMP echo requests to that address.
Ping prints the resolved address on its first line, so you can see which step succeeded.
The two failure signatures
The error text tells you which stage failed. Learn to recognize these.
| Symptom | Typical message | Stage that failed |
|---|---|---|
| Name cannot be resolved | Windows: `Ping request could not find host example.com. Please check the name and try again.` Linux: `ping: example.com: Name or service not known` or `Temporary failure in name resolution`. macOS: `ping: cannot resolve example.com: Unknown host` | Resolution (step 1) |
| Name resolves, no replies | `Request timed out.` (Windows) or no output lines and `100% packet loss` (Linux and macOS) | Reachability (step 2) |
| Name resolves, replies arrive | `Reply from 93.184.215.14: bytes=32 time=21ms TTL=56` | Both worked |
The important point is that the first row never reaches the network path at all. No echo request was sent. A name that fails to resolve tells you nothing about whether the destination is reachable.
A worked example
Suppose a web page will not load. You run the layered sequence from the earlier chapters and reach the last two steps:
ping 8.8.8.8
ping example.comThree outcomes are common.
Outcome A: the address replies, the name fails.
C:\> ping 8.8.8.8
Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=14ms TTL=117
Reply from 8.8.8.8: bytes=32 time=13ms TTL=117
Reply from 8.8.8.8: bytes=32 time=14ms TTL=117
Reply from 8.8.8.8: bytes=32 time=13ms TTL=117
C:\> ping example.com
Ping request could not find host example.com. Please check the name and try again.Your connection to the internet works. The fault is in name resolution. Check the DNS servers listed by ipconfig /all. They may be wrong, unreachable, or blank.
Outcome B: both succeed. Connectivity and DNS are fine. If the web page still fails, look higher up: the browser, a proxy, a firewall rule on TCP port 443, or the web server itself. Ping only proves that ICMP works.
Outcome C: both fail with timeouts. The name may resolve, but nothing returns. Go back down the sequence. Ping the default gateway, then the local address, to find where the path first breaks.
Using the output to see resolution
The address that ping prints for a name is useful evidence.
ping -n 2 example.comThe first line looks like Pinging example.com [93.184.215.14] with 32 bytes of data:. The address in brackets is what DNS returned. Check three things.
- Is it an address at all? If the line shows no brackets, resolution failed.
- Is it the address you expect? A stale cache, a hosts file entry, or a wrong DNS server can return an old or unrelated address.
- Is it IPv4 or IPv6? Many systems prefer IPv6 when a name has both kinds of record. A name can then reply over IPv6 while your IPv4 path is broken, or the reverse. You can force a family with
-4or-6on Windows, andping -4orping -6on current Linux and macOS (on older macOS, useping6for IPv6).
ping -4 example.com
ping -6 example.comCauses of resolution failures
When the address works and the name does not, look at these causes in turn.
- No DNS server configured.
ipconfig /allshows an empty DNS Servers line. This can follow a failed DHCP lease. - Wrong DNS server. A manual setting points to a server that no longer exists or is not reachable from this network. Ping the DNS server's address to test that it is reachable.
- DNS server reachable by ping but not answering queries. Ping uses ICMP, while DNS uses UDP or TCP port 53. A server can answer one and not the other.
- Stale cache. The local cache holds a bad or outdated answer. Clear it:
``bat ipconfig /flushdns ``
- VPN or split DNS. A VPN may send some names to an internal DNS server and others to a public one. A name that works on one network may fail on another.
- Hosts file override. An entry in the hosts file wins over DNS. On Windows it is
C:\Windows\System32\drivers\etc\hosts. On Linux and macOS it is/etc/hosts. - Typo or nonexistent name. The most common cause. Check the spelling before changing anything else.
Reverse lookups can add delay
Some tools also turn addresses back into names, which is called a reverse lookup. ping -a on Windows does this. tracert does it by default, which is why -d makes it faster. If the DNS server is slow or broken, these lookups stall. A command that pauses before printing, then prints normal timings, is waiting on DNS rather than on the network.
When the name resolves but ping still fails
A successful lookup followed by timeouts does not prove a network fault. Several things can cause it.
- The host blocks ICMP echo. Many servers and firewalls drop it. The site may still serve web pages fine. Test with an application that uses the real service, such as a browser or
curl. - The name returns an address that is not meant to answer. Some names point to a load balancer or content delivery network. Some point to an address that is not reachable for ICMP from outside.
- The name returned a different address on each run. DNS can rotate among several addresses. Two pings may hit two different servers. Compare the bracketed address between runs.
A short decision table
| Ping by IP | Ping by name | Most likely conclusion |
|---|---|---|
| Replies | Replies | Connectivity and DNS work. Look at higher layers. |
| Replies | Cannot find host | DNS configuration or DNS server problem. |
| Timeout | Cannot find host | Check connectivity first. DNS may be unreachable too. |
| Timeout | Resolves, then timeout | Path problem, or the destination filters ICMP. Test a different known target. |
| Replies for some IPs only | Varies | Partial path problem, routing, or filtering. Use `tracert` next. |
Always test the IP of a target you know responds to ping, such as a well-known public DNS server, so that your result is not caused by the target's own filtering.
Exercises
Exercise
ping 8.8.8.8 returns replies, but ping example.com prints "Ping request could not find host". Which part of the path is working, and which part do you check next?
Show answer
The path to the internet works, because the IP address replies. The fault is in name resolution. Check the DNS servers listed by ipconfig /all, confirm they are set and reachable, and try ipconfig /flushdns.
Exercise
ping example.com shows "Pinging example.com [93.184.215.14]" followed by four "Request timed out." lines. A coworker says this proves DNS is broken. Is that correct?
Show answer
No. The brackets show that DNS returned an address, so resolution worked. The timeouts mean the echo requests received no replies. The cause is a path fault or ICMP filtering at the target or along the route.
Exercise
Why can a DNS server answer ping while name lookups still fail?
Show answer
Ping uses ICMP, and DNS queries use UDP or TCP port 53. A host can reply to ICMP echo while its DNS service is stopped, overloaded, or blocked by a firewall.