Skip to content
Tutorials Center
My learning

Topics

Lesson 67 of 79 ยท Tools and Troubleshooting

Essential Network Tools

Learn the everyday network command-line tools: ping, traceroute, dig, curl, ss, ip, nmap and whois. See how to read sample output and parse it with Python.

When something on the network misbehaves, a handful of small commands answer most questions: Is the host alive? Where do packets stop? What address does this name resolve to? What is listening on this machine? These tools exist on almost every system, and each is a window onto a protocol you have already studied.

A note about this lesson: the tools talk to the real network, which a web page cannot do, so the command output shown here is sample output written to illustrate the format. Your addresses and numbers will differ. The Python examples parse that sample text, which is a skill in its own right, because scripts often turn tool output into reports. Command names are given for Linux and macOS first, with Windows equivalents noted.

ping: is it reachable, and how fast?

ping sends ICMP echo requests and waits for echo replies. It tells you whether a host answers, how long the round trip takes and whether packets are lost.

TEXT
$ ping -c 4 example.org
PING example.org (203.0.113.25) 56(84) bytes of data.
64 bytes from 203.0.113.25: icmp_seq=1 ttl=57 time=18.4 ms
64 bytes from 203.0.113.25: icmp_seq=2 ttl=57 time=17.9 ms
Request timeout for icmp_seq 3
64 bytes from 203.0.113.25: icmp_seq=4 ttl=57 time=21.2 ms

--- example.org ping statistics ---
4 packets transmitted, 3 received, 25% packet loss
rtt min/avg/max/mdev = 17.9/19.2/21.2/1.5 ms

How to read it: the address in parentheses shows that the name resolved (DNS worked). ttl=57 is the remaining hop budget of the reply; guessing that the sender started at 64, the path was about 7 hops. time is the round-trip time (RTT). The summary gives loss and the spread of times. On Windows use ping -n 4 example.org; Linux and macOS use -c.

Caveat: many firewalls drop ICMP, so a silent ping does not prove a host is down. Test the real service as well (for example with curl below).

Python Compute ping statistics from sample output

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

traceroute: where does the path go?

traceroute (tracert on Windows) maps the route by sending packets with TTL 1, 2, 3, and so on. Each router that drops a packet because its TTL expired returns an ICMP "time exceeded" message, which reveals its address. Three probes are sent per hop.

TEXT
$ traceroute example.org
traceroute to example.org (203.0.113.25), 30 hops max, 60 byte packets
 1  192.168.1.1 (192.168.1.1)       1.2 ms   1.1 ms   1.0 ms
 2  10.20.0.1 (10.20.0.1)           8.5 ms   8.1 ms   8.9 ms
 3  * * *
 4  198.51.100.9 (198.51.100.9)    14.0 ms  13.7 ms  14.4 ms
 5  203.0.113.1 (203.0.113.1)      18.1 ms  18.3 ms  17.8 ms
 6  203.0.113.25 (203.0.113.25)    18.5 ms  18.2 ms  18.9 ms

Reading it: hop 1 is your home router, hop 2 your ISP. A line of * * * means that router did not answer; it may simply ignore or rate-limit probes, so a single star row followed by working hops is normal. Look for the hop where latency jumps and stays high, or where every following hop is silent. Paths can differ per probe because of load balancing, and the forward and return paths may differ. mtr combines ping and traceroute in a live display with per-hop loss.

nslookup and dig: ask DNS directly

When a name will not resolve, ask a DNS server yourself. nslookup exists everywhere; dig gives more detail.

TEXT
$ dig example.org A +noall +answer +stats
example.org.        3600  IN  A   203.0.113.25

$ dig example.org MX +short
10 mail.example.org.

$ dig @1.1.1.1 example.org AAAA +short
2001:db8:10::25

$ dig +trace example.org      # follow root -> TLD -> authoritative servers

The number after the name is the remaining TTL (cache lifetime). @server chooses which resolver to ask, which is how you tell whether the problem is your resolver or the authoritative servers. dig -x 203.0.113.25 does a reverse lookup. nslookup example.org 8.8.8.8 is the same idea.

curl: speak the application protocol

curl makes requests over HTTP and many other protocols. For troubleshooting, the most useful options show the conversation.

TEXT
$ curl -I https://example.org
HTTP/2 200
content-type: text/html; charset=UTF-8
cache-control: max-age=604800
server: ExampleServer

$ curl -v https://example.org 2>&1 | head -n 12
*   Trying 203.0.113.25:443...
* Connected to example.org (203.0.113.25) port 443
* ALPN: server accepted h2
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* SSL certificate verify ok.
> GET / HTTP/2
> Host: example.org
< HTTP/2 200

$ curl -s -o /dev/null -w "dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} total=%{time_total}\n" https://example.org
dns=0.012 connect=0.031 tls=0.067 total=0.112

The -w timing output is gold: it splits a slow request into name lookup, TCP connect, TLS handshake and total time, so you can see which stage is slow. Other helpers: --resolve host:443:IP tests a specific server address without touching DNS, -L follows redirects and --max-time stops hung requests. Because curl tests the real service, it is a better "is the website up" test than ping.

Python Break down a curl timing line

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

ss and netstat: what is listening and connected?

ss (Linux) and netstat (everywhere, with different flags) list sockets: who is listening on which port and which connections exist, with their TCP states.

TEXT
$ ss -tlnp            # TCP, listening, numeric, show process
State   Recv-Q Send-Q  Local Address:Port   Peer Address:Port  Process
LISTEN  0      4096          0.0.0.0:22          0.0.0.0:*     users:(("sshd",pid=812))
LISTEN  0      511         127.0.0.1:5432        0.0.0.0:*     users:(("postgres",pid=1044))
LISTEN  0      511                 *:443               *:*     users:(("nginx",pid=990))

$ ss -tn state established
Recv-Q Send-Q  Local Address:Port    Peer Address:Port
0      0        192.168.1.20:51044  203.0.113.25:443

Flags: -t TCP, -u UDP, -l listening, -n numbers instead of names, -p process. The address matters: 127.0.0.1:5432 is reachable only from the machine itself, while 0.0.0.0:22 accepts connections on all interfaces. Many sockets stuck in CLOSE_WAIT suggest an application that never closes connections, and a large SYN-RECV count can indicate a SYN flood. The Windows equivalent is netstat -ano. lsof -i :8080 shows what holds a given port.

ip and ifconfig: this machine's network configuration

TEXT
$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP
    link/ether 3c:22:fb:12:9a:07 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.20/24 brd 192.168.1.255 scope global dynamic eth0
    inet6 fe80::3e22:fbff:fe12:9a07/64 scope link

$ ip route
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.20

$ ip neigh
192.168.1.1 dev eth0 lladdr aa:bb:cc:00:00:01 REACHABLE

You can read the MAC address, the IPv4 address with its prefix length (subnetting), the MTU, the default gateway from the routing table and the ARP neighbor table. ip replaces the older ifconfig, route and arp on Linux. On macOS use ifconfig and netstat -rn; on Windows use ipconfig /all, route print and arp -a.

A good first check: an address starting 169.254. means DHCP failed (DHCP); a missing default route means no Internet.

nmap: what is open?

nmap discovers hosts and open ports. Use it only on networks you own or have permission to scan.

TEXT
$ nmap -sV 192.168.1.10
Nmap scan report for 192.168.1.10
Host is up (0.0010s latency).
Not shown: 997 closed tcp ports
PORT    STATE SERVICE VERSION
22/tcp  open  ssh     OpenSSH 9.6
80/tcp  open  http    nginx 1.24
443/tcp open  https   nginx 1.24

Useful forms: nmap -sn 192.168.1.0/24 (which hosts are up), -p 1-1024 or -p- (port range), -sV (identify service versions) and -sU (UDP, slow). A port reported filtered means a firewall is dropping probes. Scanning your own server from the outside is a quick audit of what the firewall really exposes.

whois: who owns this?

whois queries registries for ownership information about a domain or an IP block. Domain records show the registrar, creation and expiry dates and name servers (personal details are often redacted for privacy); IP queries show which organization holds the block and the autonomous system, handy for reporting abuse or understanding whose network a strange address belongs to.

TEXT
$ whois 203.0.113.25
NetRange:   203.0.113.0 - 203.0.113.255
CIDR:       203.0.113.0/24
OrgName:    Example Hosting Ltd

Choosing the right tool

Question Tool
Is the host reachable, and how fast? ping
Where along the path does it break? traceroute, mtr
Does the name resolve, and to what? dig, nslookup
Does the service answer, and which stage is slow? curl -v, curl -w
What is my machine listening on or connected to? ss, netstat
What is my address, route and ARP table? ip, ifconfig, ipconfig
Which ports does a host expose? nmap
Who owns this domain or IP? whois

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How does traceroute discover the routers along a path?

    A packet whose TTL reaches zero is dropped by a router, which sends back ICMP time exceeded. Starting at TTL 1 and increasing reveals each hop.
  2. 2. ping gets no reply from a web server, yet the website works in a browser. What is the most likely explanation?

    ICMP is often filtered. Testing the real service with curl is a better check of availability.
  3. 3. What does curl's time_connect minus time_namelookup measure?

    time_connect is cumulative up to the finished TCP handshake, so subtracting the DNS time leaves the TCP connect stage.
  4. 4. In ss output, what is the difference between 127.0.0.1:5432 and 0.0.0.0:5432 as a listening address?

    Binding to the loopback address keeps a service private to the host, whereas the wildcard address exposes it on every network interface.
  5. 5. An nmap scan reports a port as filtered. What does this suggest?

    Filtered means nmap cannot tell whether the port is open or closed because no reply arrives, typically due to a firewall.

Summary

  • ping tests reachability, round-trip time and loss with ICMP; traceroute and mtr map the path using expiring TTLs.
  • dig and nslookup query DNS directly; @server isolates resolver problems from authoritative ones.
  • curl -v and curl -w test the real application and split latency into DNS, TCP, TLS and transfer time.
  • ss/netstat show listening ports and connection states; ip (or ifconfig/ipconfig) shows addresses, routes and the neighbor table.
  • nmap audits exposed ports on systems you are authorized to test; whois shows ownership.

Next, learn to look at the actual packets in packet capture with tcpdump and Wireshark.