Some useful commands you can run in the terminal/shell/command prompt to diagnose and solve networking problems
If you've just read our 'What is the terminal' page, here are some commands that might be useful in diagnosing connection issues.
Purpose: checking if a network device or host is alive/running/connected.
Usage:
Windows
ping -t <ip address or hostname>
Mac /
Linux
ping <ip address or hostname>
Notes: A lack of response doesn't mean the target isn't alive, it may just be programmed not to respond, or busy.
The '-t' option on Windows is to make it run until you press Ctrl-C, omit this if you just want 4 pings and no more. Conversely, if you want 4 pings only on Mac/Linux, use ping -c 4
Find out more: watch our ping video or visit our ping page.
Purpose: Checking the route taken to a specific host on a network or the Internet.
Usage:
Windows
tracert <ip address or hostname>
Mac /
Linux
traceroute <ip address or hostname>
Notes: Traceroute shows the path your packets took at the moment you ran it — a one-time snapshot. Networks constantly adjust routes due to load balancing, congestion, or failures, so running it again later (or even seconds apart) may show a different path.
Find out more: watch our traceroute video or visit our traceroute page.
Purpose: Combines ping and traceroute, by continuously testing the route to a host, showing packet loss and latency at every hop.
Usage:
Windows
Download GUI version from WinMTR.net
Mac
sudo mtr <ip address or hostname>
Linux
mtr <ip address or hostname>
Notes: Unlike traceroute's one-time snapshot, MTR keeps probing, so intermittent problems show up over time. The Mac version will need you to authorise with your password.
Purpose: To check DNS by looking up what a hostname resolves to
Usage:
Windows /
Mac /
Linux
nslookup <hostname>
Notes: To test a specific DNS server rather than your default one, add it after the hostname, eg: nslookup
Purpose: To clear your operating system's DNS cache, to force downloading the latest entries from the upstream DNS resolver (sometimes your router, sometimes your ISP, sometimes a third party resolver).
Usage:
Windows
ipconfig /flushdns (Windows)
Mac
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Notes: The Mac command above is actually two commands in one, because the method has changed over time, and this dual command should work no matter which version of MacOS you're on.
Also, note that the commands above don't necessarily clear your browsers DNS cache as well (which is different from it's page cache). To do that, simply restart your browser.