When a network misbehaves, a few commands answer most first questions. Is the host reachable? What address does this machine have? Which IP address does a name resolve to? Which programs are listening? The ten commands below cover those questions on Linux, and the table at the end gives Windows equivalents. Some come installed by default, others need to be added, and some need root for full output.
1. ping
ping sends ICMP echo requests and reports whether replies come back and how long they take. Use it to check reachability:
ping -c 4 example.com
The -c 4 option stops after four replies. Without it, Linux ping keeps running until you press Ctrl+C. Some hosts block ping, so a failure does not always mean the host is down.
2. traceroute
traceroute shows each router a packet passes through on the way to a destination, along with the response time at each hop:
traceroute example.com
On many systems traceroute must be installed separately. tracepath does a similar job and usually works without root.
3. ip
ip, from the iproute2 package, is the modern tool for addresses, routes, and interfaces. It replaces ifconfig and route on current systems:
ip addr show
ip route show
ip link show
ip addr show lists the addresses on each interface, ip route show shows the default gateway and other routes, and ip link show shows whether an interface is up.
4. ss
ss lists sockets, which are the endpoints of network connections. It replaces netstat on current systems:
sudo ss -tulpn
This shows listening TCP and UDP ports and the program using each one. Without sudo, you may not see process names for services owned by other users.
5. dig
dig queries DNS servers and shows the full answer, including the time to live (TTL) and which server replied:
dig example.com A
dig +short example.com
The first command asks for IPv4 address records. +short prints only the answer, which is handy in scripts. To query a specific resolver, add its address, such as dig @1.1.1.1 example.com.
6. nslookup
nslookup does simpler DNS lookups and works on both Linux and Windows. On Linux it usually comes from a DNS utilities package such as bind-utils or dnsutils:
nslookup example.com
Use it for quick checks. For detailed output or scripting, dig is usually the better choice.
7. curl
curl transfers data to or from a URL. For connectivity tests, it shows whether a web service answers and what status it returns:
curl -I https://example.com
The -I option requests only the headers, so you see the status line, such as HTTP/2 200, without downloading the page.
8. mtr
mtr combines ping and traceroute and keeps updating loss and latency for each hop. It helps you find where packet loss starts:
mtr -r -c 10 example.com
The -r option prints a one-time report, and -c 10 sends ten probes per hop. Some routers slow down or drop replies to probes while still forwarding traffic, so loss at one middle hop may not matter. Loss that continues all the way to the final destination is the more meaningful sign.
9. tcpdump
tcpdump captures packets on an interface so you can see the actual traffic. It usually needs root:
sudo tcpdump -i any -c 10
This captures ten packets from any interface. Capture only on networks you own or are authorized to monitor, and remember that captured packets can contain sensitive data.
10. nmcli
nmcli controls NetworkManager from the command line. It works only on systems that use NetworkManager, which is common on desktops:
nmcli device status
nmcli connection show
nmcli device status shows each interface and its state, and nmcli connection show lists the saved connection profiles.
Windows equivalents
| Task | Linux | Windows |
|---|---|---|
| Show IP configuration | ip addr show |
ipconfig /all |
| Trace the route | traceroute or tracepath |
tracert |
| Query DNS | dig or nslookup |
nslookup or Resolve-DnsName in PowerShell |
| List listening ports | sudo ss -tulpn |
netstat -ano |
| Test a TCP port | nc -zv example.com 443 (needs netcat) |
Test-NetConnection -ComputerName example.com -Port 443 |
| Continuous ping | ping example.com |
ping -t example.com |
Where to start
If you are new, learn ping, ip, ss, and dig first. Together they answer most questions about reachability, addresses, ports, and DNS. For tools beyond these, see what are the best networking tools for linux.