Sub topic 19
Using ping, ipconfig, nslookup, and tracert
This chapter assumes you know what an IPv4 address, subnet mask, default gateway, DHCP, and DNS are, and that you can open a Windows command prompt or PowerShell. The four tools here let you find which layer of a connection is failing. You will also learn the order in which to use them.
The troubleshooting approach
A working connection depends on a chain of parts. The network adapter needs a valid address. The router must be reachable. DNS must turn names into addresses. The path to the destination must be open. Test the chain from the inside out, and stop at the first link that fails. That link is where you start fixing.
ipconfig: read the address configuration
Run ipconfig /all first. It lists every adapter with its settings.
ipconfig /allLook for these fields:
- IPv4 Address and Subnet Mask. These show whether the adapter has a usable address for your network.
- Default Gateway. This is the router's address. If it is blank, the computer cannot reach anything outside its own subnet.
- DHCP Server and lease times. These show whether the address came from DHCP and when the lease expires.
- DNS Servers. These are the servers used to resolve names.
An address in 169.254.0.0/16 is an APIPA address. Windows assigns it to itself when no DHCP server answers. The computer can talk to other APIPA devices on the same segment, but it has no gateway, so it cannot reach the internet. Common causes are a router that is down, a bad cable, a wireless client that is not really associated, or a DHCP scope that has run out of addresses.
To request a new lease, release the old one and renew it:
ipconfig /release
ipconfig /renewTwo related switches are useful. ipconfig /flushdns clears the local DNS cache, and ipconfig /displaydns shows it. Without /all, plain ipconfig shows only the address, mask, and gateway.
ping: test reachability
ping sends ICMP echo request packets and waits for echo replies. It reports whether a reply came back and how long it took. Test in three steps:
ping 127.0.0.1
ping 192.168.1.1
ping example.comReplace 192.168.1.1 with your own gateway address from ipconfig.
| Test | If it fails, suspect |
|---|---|
| `ping 127.0.0.1` (loopback) | A damaged or misconfigured TCP/IP stack on this computer |
| `ping` the default gateway | The adapter, cable, Wi-Fi association, wrong IP settings, or the router |
| `ping` a remote IP such as `8.8.8.8` | The router's internet link, the ISP, or a modem problem |
| `ping` a name such as `example.com` | DNS, if the same test by IP address works |
The last row is a key step. If ping 8.8.8.8 works but ping example.com fails, the internet link is fine and name resolution is broken.
Useful options on Windows:
-tpings until you press Ctrl+C. This helps with intermittent drops, because you can wiggle a cable or move a device and watch the replies.-n 10sends 10 requests instead of the default 4.-4forces IPv4 and-6forces IPv6.
Read the results as well as the pass or fail. "Request timed out" means no reply arrived. "Destination host unreachable" usually comes from a router or from your own computer when there is no route. High or erratic times point to congestion or a weak wireless signal. Packet loss on Wi-Fi often points to interference or low signal.
nslookup: test DNS directly
nslookup asks a DNS server to resolve a name. It does not use the cache that the browser and ping use in the same way, so it isolates the DNS server itself.
nslookup example.comThe output first names the server that answered, then gives the address or addresses for the name. Interpret it like this:
- An address comes back. DNS works. If the site still fails, look at routing, firewalls, or the remote server.
- "Non-existent domain" (NXDOMAIN). The server answered, but the name does not exist. Check the spelling.
- "DNS request timed out." The configured server is not responding. Check the DNS entry in
ipconfig /all.
You can name a different server as a second argument to compare answers:
nslookup example.com 8.8.8.8If the public server answers and your configured server does not, the problem is your DNS server, often the router or the ISP's resolver. Changing the DNS setting on the adapter or the router is the fix.
tracert: find where packets stop
tracert lists each router hop between your computer and a destination. It works by sending packets with increasing Time To Live (TTL) values. Each router decrements the TTL, and the router that drops it to zero reports back. That reveals the path one hop at a time.
tracert example.comEach line shows the hop number, three round-trip times, and the router's name or address. Read it as follows:
- Hop 1 is normally your default gateway. If the trace fails here, the problem is on the local network.
- A sudden jump in time that stays high for all later hops marks where latency is added, such as a slow link.
- Asterisks (
* * *) and "Request timed out" at one hop only are often harmless, because some routers do not answer trace packets but still forward them. Asterisks on every hop from some point to the end mean traffic stops there.
On Linux and macOS the equivalent command is traceroute. The related pathping on Windows combines tracing with per-hop loss statistics, but it runs for a few minutes.
Putting it together
Suppose a laptop on Wi-Fi cannot open websites.
ipconfig /allshows169.254.17.40. The laptop did not get a DHCP lease, so you check the Wi-Fi connection and the router's DHCP service, then runipconfig /renew.- If the address is normal,
pingthe gateway. A failure means the local link is bad. - If the gateway answers,
ping 8.8.8.8. A failure means the router or ISP link is down. - If that works but
ping example.comfails, runnslookup example.com. A timeout confirms a DNS problem. - If everything responds but one site is slow or unreachable, run
tracertto see where it breaks.
Exercise
A user's PC shows the address 169.254.88.12 and cannot browse. Which command do you run first to confirm the problem, and which two commands then try to fix it?
Show answer
Run ipconfig /all to confirm the 169.254.x.x APIPA address and check for a blank default gateway and DHCP server. Then run ipconfig /release and ipconfig /renew to request a new lease. If it still fails, check the cable or Wi-Fi connection and the router's DHCP service.
Exercise
ping 8.8.8.8 succeeds, but ping example.com fails with a name resolution error. Which tool do you use next, and what is the likely cause?
Show answer
Use nslookup example.com, optionally with nslookup example.com 8.8.8.8 to compare servers. The likely cause is a failed or misconfigured DNS server, because the internet connection itself works.