In plain words
Troubleshooting a network is like finding out why no water comes out of the tap: you check the tap first, then the house meter, then the street, and finally the water plant. The first place where the water stops is where the fault is. The commands in this guide are your measuring tools at each step.
"The internet is down" can hide ten different causes. The method is to work outwards, from the nearest to the farthest: your machine, your network, the gateway, the internet, then the domain name. The first test that fails points to the culprit.
The five-step method
- Does my machine have an IP address? If not: cable, Wi-Fi or DHCP.
- Can I reach my gateway (the internet box, the router)? If not: local network.
- Can I reach an IP address on the internet? (
9.9.9.9,1.1.1.1) If not: the box or the internet provider. - Does name resolution work? If the IP answers but not the name: DNS.
- Does the target service answer on its port? If everything else works: firewall or stopped service.
Tip
An address in 169.254.x.x (Windows, macOS) means the machine got no answer from the DHCP server.
The equivalent commands
| Need | Windows (PowerShell / cmd) | Linux | macOS |
|---|---|---|---|
| Show your IP address | ipconfig /all |
ip -c a |
ifconfig or ipconfig getifaddr en0 |
| Show the gateway | ipconfig (Default Gateway) |
ip route |
route -n get default |
| Test reachability | ping 192.168.1.1 |
ping -c 4 192.168.1.1 |
ping -c 4 192.168.1.1 |
| Trace the path | tracert 9.9.9.9 |
tracepath 9.9.9.9 or traceroute |
traceroute 9.9.9.9 |
| Path + packet loss | pathping 9.9.9.9 |
mtr 9.9.9.9 |
mtr 9.9.9.9 (Homebrew) |
| Query DNS | nslookup example.com or Resolve-DnsName example.com |
dig example.com or resolvectl query example.com |
dig example.com |
| Test a TCP port | Test-NetConnection example.com -Port 443 |
nc -zv example.com 443 |
nc -zv example.com 443 |
| Local listening ports | netstat -ano or Get-NetTCPConnection -State Listen |
ss -tulpn |
lsof -nP -iTCP -sTCP:LISTEN |
| Flush the DNS cache | ipconfig /flushdns |
resolvectl flush-caches |
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder |
| Renew the DHCP lease | ipconfig /release then ipconfig /renew |
sudo nmcli con down <name> && sudo nmcli con up <name> |
sudo ipconfig set en0 DHCP |
Reading the results
ping gets no answer, but the service works
Many servers and firewalls block ping (ICMP). A ping with no answer does not prove a machine is off: test the service port instead.
The name fails, the IP works
The problem is DNS. Compare with another DNS server:
dig @9.9.9.9 example.com # Linux / macOS
nslookup example.com 9.9.9.9 # Windows
If it works with another server, the DNS handed out by your box or network is at fault.
traceroute shows stars
* * * lines in the middle of the path are normal: some routers do not answer these probes. What matters is whether the final destination is reached.
A port is "refused" or "timed out"
- Connection refused: the machine is reachable but nothing listens on that port.
- Timed out: a firewall is probably blocking the traffic somewhere.
Going further
mtrcombines ping and traceroute continuously: ideal for spotting intermittent packet loss.- On Windows,
Test-NetConnection 9.9.9.9 -TraceRoutegives the same path astracert, with output you can use in a PowerShell script. - A
pingto an IPv6 address (ping -6on Windows,ping6orpingon Linux depending on the version) helps spot an IPv6-specific problem.