Sub topic 17
Troubleshooting with Command-Line Tools
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. You will learn a repeatable order for testing a connection with ipconfig, ping, nslookup, tracert and netstat, and how to read the results.
The Troubleshooting Idea: Work Outward
A connection depends on several layers. Your adapter needs a valid address. The local network must reach the router. The router must reach the internet. DNS must turn names into addresses. Test in that order, from your own computer outward. The first test that fails shows where to look.
Reading the Configuration with ipconfig
Start by looking at what the computer believes about its own network settings.
ipconfig /allCheck these fields for each adapter:
- IPv4 Address should fit the local network, for example 192.168.1.x.
- Subnet Mask should match the other devices, commonly 255.255.255.0.
- Default Gateway is the router's address. If it is blank, the computer cannot leave the local network.
- DHCP Server shows which device gave out the lease. DHCP Enabled: Yes means the address was assigned automatically.
- DNS Servers lists the servers used for name lookups.
An address starting with 169.254 is an APIPA address. Windows assigns it when no DHCP server answers. The computer can talk only to other APIPA devices on the same link. It cannot reach the internet.
Renewing an Address and Clearing DNS
If the address is wrong or APIPA, ask DHCP for a new lease. Then clear the DNS cache, which is the list of recent name lookups the computer remembers.
ipconfig /release
ipconfig /renew
ipconfig /flushdnsIf /renew fails, DHCP is not answering. Check the cable or Wi-Fi connection, then check whether the router's DHCP service is running. The command ipconfig /displaydns shows the cache contents.
Testing Reachability with ping
ping sends ICMP echo requests, which are small test messages, to a target and reports whether replies come back and how long they take. Run three pings in a fixed order.
ping 127.0.0.1
ping 192.168.1.1
ping example.comEach one tests something different:
| Test | What it proves | If it fails |
|---|---|---|
| `ping 127.0.0.1` | The local TCP/IP stack works. The loopback address never leaves the computer. | Reinstall or reset the network stack, or fix the driver. |
| `ping` the default gateway | The computer can reach the router across the local link. | Check the cable, switch port, Wi-Fi signal, or whether the gateway setting is correct. |
| `ping` a remote IP, then a name | The router can reach the internet, and DNS works. | See the table below. |
Replace 192.168.1.1 with your own gateway address from ipconfig /all.
The remote tests give the most information when you compare them:
| Ping by IP address | Ping by name | Likely cause |
|---|---|---|
| Works | Works | Network is fine |
| Works | Fails | DNS problem |
| Fails | Fails | Router, ISP, or firewall problem |
Common results are "Request timed out" (no reply arrived) and "Destination host unreachable" (a device along the path reported that it has no route). Some devices block ICMP on purpose, so a failed ping does not always mean the device is down.
Two useful options are ping -t example.com, which pings until you press Ctrl+C, and ping -n 10 example.com, which sends ten requests. A continuous ping is handy while you wiggle a cable or reboot a router.
Checking Names with nslookup
nslookup asks a DNS server to resolve a name and shows which server answered.
nslookup example.comIf the output shows an IP address for the name, DNS is working. If you get a timeout or "server failed" message, the configured DNS server is not responding or is wrong. Compare this with a successful ping to a raw IP address. That pair of results points to DNS, not to the connection itself.
Following the Path with tracert
tracert lists each router hop between your computer and a destination. It shows where delay grows or where replies stop.
tracert example.comEach line is one hop with three round-trip times. Read the output like this:
- Hop 1 is normally your own router. If the trace stops there, the problem is between your router and the internet.
- A sudden jump in time at one hop suggests congestion or a long link at that point.
- Lines of
* * *mean no reply. One such line in the middle is often just a router that ignores these probes. If every hop after some point is* * *, traffic is being lost or blocked there.
On Linux and macOS, the equivalent command is traceroute.
Seeing Connections with netstat
netstat lists network connections and listening ports on the local computer.
netstat -anThe -a option shows all connections and listening ports. The -n option shows numbers instead of names, so ports appear as 443 and not "https". Look at the state column:
| State | Meaning |
|---|---|
| LISTENING | A service is waiting for incoming connections on that port. |
| ESTABLISHED | A connection is active. |
| TIME_WAIT | A connection recently closed and is being cleaned up. |
Use netstat to confirm that a service is listening on the port you expect, for example 3389 for Remote Desktop. It also helps spot unexpected connections to unknown addresses. Adding -b (administrator rights needed) shows which program owns each connection.
Putting It Together: Worked Scenarios
Scenario 1: No internet, address 169.254.14.7. The computer did not get a lease. Check the cable or Wi-Fi, then run ipconfig /release and ipconfig /renew. If the lease still fails, check whether the router's DHCP service is enabled.
Scenario 2: Websites fail by name, but ping 8.8.8.8 works. The connection is fine and DNS is not. Run nslookup example.com. Check the DNS server entries in ipconfig /all, then run ipconfig /flushdns. A wrong DNS server or a stale cache is the usual cause.
Scenario 3: Gateway ping fails, address looks normal. Check that the default gateway matches the router's real address and that the mask is correct. If both are right, inspect the cable, switch port or wireless link. A wrong subnet mask can make the gateway look like a remote network.
Scenario 4: Only one distant site is slow. Run tracert to that site. A delay that begins at one hop and continues on every later hop points to a problem at that point on the path, outside your network.
Exam Tips
- Know the standard order:
ipconfig, then ping loopback, gateway and remote host. - 169.254.x.x means APIPA and a failed DHCP lease.
- Ping by IP works but ping by name fails: think DNS.
tracertfinds the hop where a path breaks.nslookuptests DNS.netstatshows ports and connections.
Exercise
A user cannot open websites. ipconfig /all shows an address of 169.254.88.12 and no default gateway. Which two commands should you run next, and what does each do?
Show answer
Run ipconfig /release and then ipconfig /renew. The first drops the APIPA configuration, and the second asks the DHCP server for a new lease. If it still fails, check the cable or Wi-Fi link and the router's DHCP service.
Exercise
ping 8.8.8.8 replies, but ping example.com shows that the name cannot be found. What is the likely problem, and which command tests it directly?
Show answer
DNS resolution is failing, while the network connection works. Run nslookup example.com to test the DNS server, and check the DNS entries in ipconfig /all. Running ipconfig /flushdns can clear a bad cached entry.
Exercise
You run tracert to a remote site. Hop 1 and hop 2 respond, and every line from hop 3 onward is * * *. What does this suggest?
Show answer
Traffic is being lost or blocked at or after hop 3. Hop 1 is likely your own router, so the fault is beyond your local network. The cause could be an ISP issue or a device that blocks the probes.