Sub topic 4
Network diagnostics: tracert, pathping, nslookup, and netstat
This chapter assumes you can already run ipconfig and ping from an elevated Command Prompt and that you know what an IP address, a DNS server, and a default gateway are. Here you will move from "is the host reachable?" to "where does the path break?", "is DNS answering?", and "which process owns this connection?".
Tracing the route with tracert and pathping
tracert sends packets with a rising Time to Live (TTL) value. Each router along the path lowers the TTL by one. When it reaches zero, that router replies with an error, so every hop reveals itself in order.
ping -n 4 127.0.0.1
ping -n 4 example.com
tracert -d example.com
nslookup example.comThe sequence tests the local TCP/IP stack first, then name resolution and reachability, then the route, then DNS directly. The -d switch skips reverse DNS lookups, which makes the trace faster.
Read the output like this:
- A row of
*and "Request timed out" at one hop may only mean that router ignores these probes. If later hops answer, the path is fine. - If every hop after a certain point times out, the fault is at or just past the last responding hop.
- If the first hop fails, check the local network and the default gateway.
pathping combines tracert with repeated pings. It first lists the route, then spends a few minutes measuring packet loss at each hop. Use it when a connection is intermittent or slow and you need to find which hop drops packets.
Checking DNS with nslookup
nslookup queries a DNS server directly. This separates a DNS problem from a network problem.
nslookup example.comasks your configured DNS server for the address.nslookup example.com 8.8.8.8asks a specific server instead. If this works but the default server fails, the configured DNS server is the problem.
If ping 8.8.8.8 works but ping example.com fails, name resolution is broken. After you fix the DNS settings, ipconfig /flushdns clears stale cached answers.
Viewing connections with netstat
netstat lists network connections and listening ports on the local machine.
netstat -ano
tasklist | findstr /i "chrome"
taskkill /PID 1234 /FThe switches mean:
| Switch | Effect |
|---|---|
| `-a` | Shows all connections and listening ports |
| `-n` | Shows addresses and ports as numbers, with no name lookups |
| `-o` | Adds the process ID (PID) that owns each connection |
netstat -ano gives you a PID. tasklist maps that PID to a program name, and taskkill /PID 1234 /F ends it. Here 1234 is a placeholder, so use the PID you found. Only end a process you have identified, because /F forces it to stop without saving work.
Common errors
- Treating one timed-out hop as a failure when later hops respond.
- Running
pathpingand leaving too early. It needs several minutes to finish its statistics. - Testing only with names. Always test with an IP address too, to separate DNS faults from routing faults.
- Killing a process from a PID you did not verify with
tasklist.
Exercise
Users report that a web application is slow at certain times. ping always succeeds. Which command shows where along the route packets are being lost, and why is it better than tracert here?
Show answer
pathping. It lists the route like tracert, then sends many probes to each hop and reports the packet loss percentage per hop. This exposes an intermittent loss that a single tracert pass or a few pings can miss.
Exercise
You run netstat -ano and see an unknown program listening on port 8080 with PID 4321. What do you run next to find the program's name?
Show answer
tasklist | findstr 4321. It matches the PID to an image name. You can then decide whether to end it with taskkill /PID 4321 /F.