Why these tools matter
When a network misbehaves — a site won't load, a service is unreachable, traffic is going somewhere it shouldn't — these commands are how you find out what is actually happening. They are the stethoscope of the security analyst: cheap, built into almost every operating system, and precise. Each one answers a different question. ping asks *is that host alive?* ip addr and ipconfig ask *what is my own address?* ss and netstat ask *what is connected and what ports are open?* dig and nslookup ask *what IP does this name resolve to?* traceroute asks *what path does my traffic take?* And arp asks *who are my neighbors on this local network?*
Learning to read their output is a defensive skill: the same tools that help you troubleshoot also let you spot a rogue listening port, an unexpected DNS answer, or a suspicious device on your subnet.
Windows vs Linux
Many of these tools come in pairs — the same idea with a different name per operating system. Windows ships ipconfig, tracert, and nslookup. Linux ships ifconfig (legacy) and the modern ip, plus traceroute and dig; macOS ships ifconfig, traceroute, and dig (but not ip). Flags differ too (Windows -n count vs Linux -c count on ping), so always check which OS you are on.
ping — is the host reachable?
ping sends an ICMP echo request and waits for an echo reply. A reply means the host is up and reachable, and the round-trip time (RTT) tells you how fast the link is. No reply can mean the host is down, unreachable, or simply configured to ignore ICMP — many firewalls silently drop pings, so "no reply" is not proof a host is offline. On Linux ping runs forever until you press Ctrl+C; on Windows it sends 4 packets and stops.
Common ping options (note the count flag differs by OS):
| Command | What it does | Example |
|---|---|---|
| ping <host> | ping - named after the sound sonar makes (not an acronym): send ICMP echo requests to test whether a host is reachable | ping google.com |
| ping -c 4 <host> | count - Linux/macOS: send exactly 4 packets, then stop | ping -c 4 8.8.8.8 |
| ping -n 4 <host> | number - Windows: send exactly 4 packets, then stop (Linux uses -c for count) | ping -n 4 8.8.8.8 |
| ping -t <host> | until stopped - Windows: ping continuously until you press Ctrl+C | ping -t 192.168.1.1 |
| ping -i 2 <host> | interval - Linux: wait 2 seconds between each packet | ping -i 2 google.com |
| ping -s 1000 <host> | size - Linux: set the ICMP payload size to 1000 bytes | ping -s 1000 192.168.1.1 |
| ping -W 3 <host> | timeout (Wait) - Linux: wait up to 3 seconds for each reply before giving up on it | ping -W 3 192.168.1.1 |
Your own address: ipconfig, ifconfig, ip addr
Before you can diagnose anything you need to know your own network identity: your IP address, subnet mask, default gateway, and DNS servers. On Windows that is ipconfig. On Linux the old tool is ifconfig (deprecated but still common), and the modern replacement is the ip command — ip addr for addresses, ip route for the routing table, ip link for interfaces.
| Command | What it does | Example |
|---|---|---|
| ipconfig | ipconfig = IP CONFIGuration - Windows: show IPv4/IPv6, subnet mask, and gateway per adapter | ipconfig |
| ipconfig /all | /all = every detail - Windows: add MAC address, DHCP, DNS servers, and lease times | ipconfig /all |
| ipconfig /flushdns | /flushdns = flush the DNS cache - Windows: clear the local DNS resolver cache | ipconfig /flushdns |
| ipconfig /renew | /renew = renew the DHCP lease - Windows: pull fresh IP settings from the DHCP server | ipconfig /renew |
| ifconfig | ifconfig = InterFace CONFIGuration - Linux/macOS (legacy): show interface addresses and traffic stats | ifconfig |
| ip addr | ip = the modern Linux networking tool, addr = its address object - show addresses on every interface (ip a for short) | ip addr show eth0 |
| ip route | route = the ip routing-table object - Linux: show the routing table and default gateway | ip route |
| ip link | link = the ip network-interface object - show each interface with its MAC address and up/down state | ip link |
Connections and open ports: netstat and ss
Every listening port is a door into the machine, so knowing which ports are open — and which programs own them — is core to defense. netstat is the classic tool; ss ("socket statistics") is the modern Linux replacement, faster because it reads socket data straight from the kernel. The most useful view is listening sockets: services sitting open, waiting for a connection. An unexpected listener is a red flag worth investigating.
Listing sockets and the routing table:
| Command | What it does | Example |
|---|---|---|
| ss -tuln | ss = Socket Statistics - list listening TCP + UDP sockets, numeric (the everyday view) | ss -tuln |
| ss -tp | ss = Socket Statistics - show TCP connections with the owning process (run with sudo) | sudo ss -tp |
| netstat -tuln | netstat = NETwork STATistics - Linux (legacy): same listing as ss -tuln | netstat -tuln |
| netstat -ano | netstat = NETwork STATistics - Windows: all connections plus the owning PID, numeric | netstat -ano |
| netstat -rn | netstat = NETwork STATistics - show the kernel routing table via the -r flag (works on both OSes) | netstat -rn |
The flags stack together — on Linux the same letters work on both ss and netstat:
| Command | What it does |
|---|---|
| -t | TCP - restrict the listing to TCP sockets only |
| -u | UDP - restrict the listing to UDP sockets only |
| -l | listening - show only listening sockets (servers waiting for a connection) |
| -n | numeric - show ports and IPs as numbers, skip DNS lookups |
| -p | process - show the process / PID that owns each socket (needs sudo) |
| -a | all - show all sockets, both listening and already established |
0.0.0.0 vs 127.0.0.1
A listener on 0.0.0.0 (or ::) accepts connections from any network interface — reachable from the outside. A listener on 127.0.0.1 (loopback) accepts connections only from the same machine. Binding a service to loopback is a common way to keep it private.
DNS lookups: nslookup and dig
The Domain Name System turns names like google.com into IP addresses. DNS runs on port 53. nslookup is available on every OS and is fine for quick checks. dig ("domain information groper") is the analyst's favorite on Linux/macOS: it shows the full query, the answer section, which server replied, and record types like MX (mail), NS (name servers), TXT, and PTR (reverse). Comparing what DNS *returns* against what you *expect* is how you catch DNS tampering or misconfiguration.
| Command | What it does | Example |
|---|---|---|
| nslookup <host> | nslookup = Name Server LOOKUP - look up the A record (IPv4 address) for a name | nslookup google.com |
| nslookup -type=MX <domain> | -type = the record type to query - ask for MX, NS, TXT, ... instead of the default A record | nslookup -type=MX google.com |
| dig <host> | dig = Domain Information Groper - full DNS query with answer and authority sections | dig google.com |
| dig +short <host> | +short = terse output - print just the answer, one value per line | dig +short google.com |
| dig <domain> MX | MX = the Mail eXchange record type - query which mail servers accept a domain's email | dig google.com MX |
| dig @8.8.8.8 <host> | @server = query this specific DNS server - ask 8.8.8.8 instead of your default resolver | dig @8.8.8.8 example.com |
| dig -x <ip> | -x = reverse lookup - turn an IP back into a name (PTR record) | dig -x 8.8.8.8 |
Mapping the path: tracert and traceroute
traceroute (Linux/macOS) and tracert (Windows) reveal every router hop between you and a destination. They work by sending packets with a deliberately small TTL (time-to-live) that increases by one each round: the first hop replies when TTL hits zero, then the second, and so on, until the packets reach the target. The result is a map of the route your traffic takes and where latency or loss appears. A row of * * * means a hop did not reply within the timeout — often a router configured to stay silent, not necessarily a failure.
Windows tracert uses ICMP by default; Linux traceroute uses UDP by default:
| Command | What it does | Example |
|---|---|---|
| tracert <host> | tracert = TRACE RouTe (the Windows spelling) - trace the router hops to a host using ICMP | tracert google.com |
| traceroute <host> | traceroute = trace the route - Linux/macOS: map every router hop, using UDP probes by default | traceroute google.com |
| traceroute -I <host> | -I (capital i) = use ICMP Echo - Linux: probe with ICMP like Windows tracert | traceroute -I google.com |
| traceroute -T -p 443 <host> | -T = use TCP SYN, -p = destination port - Linux: probe TCP 443 to pass some firewalls | sudo traceroute -T -p 443 google.com |
| traceroute -n <host> | -n = numeric - skip reverse DNS on each hop, show numeric IPs (faster) | traceroute -n google.com |
| traceroute -m 20 <host> | -m = max hops (max TTL) - stop tracing after 20 hops | traceroute -m 20 google.com |
| traceroute -w 2 <host> | -w = wait - seconds to wait for each hop's reply before printing a * timeout | traceroute -w 2 google.com |
Layer 2 neighbors: arp
Inside a single local network, machines actually deliver frames using MAC addresses (Layer 2), not IP addresses (Layer 3). The Address Resolution Protocol bridges the two: it maps an IP address to the MAC address that currently holds it, and caches the result in the ARP table. arp -a shows that table — a quick inventory of the devices your machine has recently talked to on the local segment. On modern Linux the successor command is ip neigh.
| Command | What it does | Example |
|---|---|---|
| arp -a | arp = Address Resolution Protocol - show the ARP cache of IP-to-MAC mappings on the local segment (Windows & Linux) | arp -a |
| arp -n | numeric - Linux: show the cache as numbers, skip name resolution | arp -n |
| ip neigh | ip neigh = the modern Linux neighbour table - show the ARP/neighbour cache (successor to arp) | ip neigh show |
| arp -d <ip> | delete - remove a single entry from the ARP cache (needs sudo) | sudo arp -d 192.168.1.55 |
| arp -s <ip> <mac> | static - add a permanent IP-to-MAC entry, a manual defence against ARP spoofing (needs sudo) | sudo arp -s 192.168.1.1 3c:37:86:1a:2b:cc |
Why ARP matters for security
ARP has no authentication — a host simply trusts the replies it receives. That design weakness is what makes ARP spoofing possible, where an attacker convinces machines to send traffic to the wrong MAC. Defensively, this is why you inspect the ARP table: two different IPs mapped to the same MAC, or your gateway's MAC suddenly changing, are classic warning signs of a man-in-the-middle on the local network.
Who can see these commands on the network?
Every command on this page either stays entirely inside your own computer, or sends real packets out onto the network — and those are two very different situations for anyone watching. The table below rates each command's visibility to a network admin, a firewall or IDS, the destination host, a DNS resolver, or anyone else on the path your traffic takes.
The visibility scale
Rate every command using this fixed scale:
None (local only) — the command only reads information your computer already has (a cached address, a routing table, a list of open sockets). No packet leaves the machine, so there is nothing on the network for anyone to observe.
Low — the command creates a small amount of traffic that blends into ordinary background noise, or the connection's contents are hidden by encryption (TLS/HTTPS, SSH) even though the connection itself is still visible.
Moderate — the command creates everyday traffic that is clearly visible to the destination host, to devices and firewalls on the path, and to DNS resolvers — loggable and identifiable, but not by itself alarming.
High — the command creates traffic that stands out: a broadcast every device on the local segment can see, unencrypted content anyone on the path can read in full, or a pattern (like a port scan) that intrusion-detection systems are specifically built to catch.
Encryption is a common source of confusion: TLS/HTTPS and SSH hide *what* you send, never *that* you sent it. The destination IP address and port, the timing and amount of data, and — thanks to the DNS lookup that happens first and the TLS SNI field that names the site inside the "encrypted" handshake — usually the hostname you're connecting to, are all still visible to anyone watching the network. On a school or managed network, assume every command below that isn't None (local only) is logged somewhere.
ping — ICMP echo traffic reaches the destination, every router on the path, and any IDS watching for ICMP:
| Command | What a network monitor can see | Visibility |
|---|---|---|
| ping <host> | ICMP echo/reply packets travel to the target and back; visible to the destination, every router on the path, and any firewall or IDS watching for ICMP. | Moderate |
| ping -c 4 <host> | Same ICMP traffic as ping, just a fixed count — one exchange per packet, still visible end to end. | Moderate |
| ping -n 4 <host> | Windows count flag; identical ICMP visibility to ping. | Moderate |
| ping -t <host> | Pings continuously until stopped — the same visible ICMP traffic, just sustained longer, which can look more like a probe to a watchful IDS. | Moderate |
| ping -i 2 <host> | Same ICMP traffic, spaced out — visibility is unchanged, only the packet rate differs. | Moderate |
| ping -s 1000 <host> | Same ICMP exchange with a bigger payload — the extra size is visible to anyone inspecting the packet, and some IDS rules flag oversized ICMP. | Moderate |
| ping -W 3 <host> | Same ICMP exchange; the timeout only affects how long your machine waits for a reply, not what's visible on the wire. | Moderate |
Your own address — these only read settings the OS already has:
| Command | What a network monitor can see | Visibility |
|---|---|---|
| ipconfig | Reads settings the OS already has from the last DHCP lease; no packet leaves the machine. | None (local only) |
| ipconfig /all | Same local read, just more fields (MAC, DHCP, DNS servers); still no traffic. | None (local only) |
| ipconfig /flushdns | Clears the local resolver cache in memory; nothing is sent to the network. | None (local only) |
| ipconfig /renew | Broadcasts a DHCP request on the local network to get a fresh lease — every device on that LAN segment, and the DHCP server's logs, can see it, though it never leaves the local network. | Moderate |
| ifconfig | Reads local interface configuration; no packet leaves the machine. | None (local only) |
| ip addr | Reads local interface addresses from the kernel; no packet leaves the machine. | None (local only) |
| ip route | Reads the local routing table from the kernel; no packet leaves the machine. | None (local only) |
| ip link | Reads local interface state from the kernel; no packet leaves the machine. | None (local only) |
Connections and open ports — ss and netstat only read the kernel's own socket table, regardless of which flags you combine:
| Command | What a network monitor can see | Visibility |
|---|---|---|
| ss -tuln | Reads the kernel's own socket table and lists what's listening; sends nothing. | None (local only) |
| ss -tp | Also reads the local socket table, plus the owning process; still nothing on the wire. | None (local only) |
| netstat -tuln | Same local kernel read as ss -tuln. | None (local only) |
| netstat -ano | Windows equivalent — reads local connection state and PIDs; nothing sent. | None (local only) |
| netstat -rn | Reads the local kernel routing table; nothing sent. | None (local only) |
| -t | A flag on ss/netstat, which stay local-only no matter which flags are combined. | None (local only) |
| -u | A flag on ss/netstat, which stay local-only no matter which flags are combined. | None (local only) |
| -l | A flag on ss/netstat, which stay local-only no matter which flags are combined. | None (local only) |
| -n | A flag on ss/netstat, which stay local-only no matter which flags are combined. | None (local only) |
| -p | A flag on ss/netstat, which stay local-only no matter which flags are combined. | None (local only) |
| -a | A flag on ss/netstat, which stay local-only no matter which flags are combined. | None (local only) |
DNS lookups — every query is visible to your resolver and to anyone on the path to it:
| Command | What a network monitor can see | Visibility |
|---|---|---|
| nslookup <host> | Sends a DNS query to your configured resolver; the resolver logs it, and anyone on the path to that resolver can see the name you looked up. | Moderate |
| nslookup -type=MX <domain> | Same DNS query mechanics, just a different record type — same visibility. | Moderate |
| dig <host> | Same DNS query as nslookup, visible to your resolver and the path to it. | Moderate |
| dig +short <host> | Same underlying query; the flag only changes how the answer is printed, not what's visible on the wire. | Moderate |
| dig <domain> MX | Same DNS visibility, asking for a different record type. | Moderate |
| dig @8.8.8.8 <host> | Sends the query directly to a named server instead of your default resolver — still a visible DNS query, now logged by that specific server. | Moderate |
| dig -x <ip> | A reverse DNS (PTR) query — same visibility as any other DNS lookup. | Moderate |
Mapping the path — every hop the probes pass through sees one, whether it's ICMP, UDP, or TCP:
| Command | What a network monitor can see | Visibility |
|---|---|---|
| tracert <host> | Sends ICMP probes with increasing TTL; every router hop along the way, plus the destination, sees a packet aimed to expire at their doorstep. | Moderate |
| traceroute <host> | Sends UDP probes by default on Linux/macOS; same hop-by-hop visibility as tracert, just a different protocol. | Moderate |
| traceroute -I <host> | Switches to ICMP probes like Windows tracert — same per-hop visibility. | Moderate |
| traceroute -T -p 443 <host> | Uses TCP SYN packets to a specific port to slip past firewalls that block ICMP/UDP — still visible to every hop and to the destination on port 443. | Moderate |
| traceroute -n <host> | Same probes as traceroute, just skips the reverse-DNS lookup on each hop when printing results — visibility on the wire is unchanged. | Moderate |
| traceroute -m 20 <host> | Same probes, just caps how many hops it will try — visibility per hop is unchanged. | Moderate |
| traceroute -w 2 <host> | Same probes; the wait time only affects your own timeout, not what's visible to others. | Moderate |
Layer 2 neighbors — arp and ip neigh only read (or edit) the local cache the kernel already built:
| Command | What a network monitor can see | Visibility |
|---|---|---|
| arp -a | Reads the local ARP cache the kernel already built from past traffic; no new packet is sent to look it up. | None (local only) |
| arp -n | Same local cache read, printed numerically. | None (local only) |
| ip neigh | The modern equivalent of arp -a — reads the local neighbor cache; no packet sent. | None (local only) |
| arp -d <ip> | Deletes one entry from the local cache; a purely local table edit. | None (local only) |
| arp -s <ip> <mac> | Adds a static entry to the local cache; a purely local table edit, even though its purpose is defensive. | None (local only) |
Network monitoring commands
These are the tools on the other side of the conversation — what a network administrator or defender runs to see what's happening on devices and networks they are authorized to monitor. Where the commands above answer *is this one host reachable?*, these answer *what is happening on my network right now?*
Reading local state — no different in kind from ss, netstat, and arp earlier on this page:
| Command | What it does | Example |
|---|---|---|
| ss -tunap | Every TCP/UDP socket, established or listening, with the owning process and PID — the fuller sibling of ss -tuln. | sudo ss -tunap |
| netstat -tunap | The legacy equivalent of ss -tunap; slower because it walks more of the kernel, but the same information. | sudo netstat -tunap |
| lsof -i | Lists every open file that is actually a network socket, one line per connection, grouped by the process that owns it. | sudo lsof -i |
| ip -s link | Per-interface packet, byte, and error counters — a quick health check for a NIC. | ip -s link |
| watch -n 1 'ss -tun' | Re-runs ss every second so you can watch connections appear and disappear live. | watch -n 1 'ss -tun' |
| iftop | A live, top-style view of bandwidth used by each connection. | sudo iftop -i eth0 |
| nethogs | A live, top-style view of bandwidth used by each process. | sudo nethogs eth0 |
Capturing live packets — these read traffic already arriving at the network card, in far more detail than a socket list:
| Command | What it does | Example |
|---|---|---|
| sudo tcpdump -i <interface> | Captures every packet crossing an interface and prints a one-line summary of each. | sudo tcpdump -i eth0 |
| sudo tcpdump -n port 53 | Captures only DNS traffic (port 53); -n skips reverse-DNS on the output so it prints fast. | sudo tcpdump -n port 53 |
| tshark | The command-line version of Wireshark — captures and can decode traffic in far more detail than tcpdump's default summary. | sudo tshark -i eth0 -Y dns |
| pktmon | Windows' built-in packet monitor and capture tool. | pktmon start --etw -p 0 |
Windows equivalents:
| Command | What it does | Example |
|---|---|---|
| netstat -ano | All connections plus the owning PID, numeric — look up the PID in Task Manager to find the program. | netstat -ano |
| Get-NetTCPConnection | PowerShell cmdlet listing every TCP connection as structured objects you can filter and sort. | Get-NetTCPConnection -State Listen |
| Get-NetUDPEndpoint | PowerShell cmdlet listing every UDP endpoint the same way. | Get-NetUDPEndpoint |
None of this puts your own machine on the network in a new way. ss, netstat, lsof, ip -s link, and the PowerShell cmdlets all read state the kernel already has — no different from the commands earlier on this page. tcpdump, tshark, iftop, nethogs, and pktmon are passive listeners: they read packets already arriving at your network card, so watching does not itself create outbound traffic another host or IDS could see. What they DO need is administrator or root privileges, because reading raw packets is treated as a privileged operation by the OS. On a switched network you generally only receive traffic addressed to your own machine plus broadcasts — capturing someone else's unicast traffic takes additional access, like a mirrored switch port, that a legitimate administrator sets up on purpose, not something you can casually add yourself.
Get permission before you monitor or capture
Only run these commands on networks and devices you own, or where you have explicit written permission to monitor — your own lab VM, your own home network, or a school network where a teacher or IT department has specifically authorized it. Capturing someone else's traffic without permission can violate your school's acceptable-use policy and laws such as the federal Wiretap Act (18 U.S.C. § 2511), even if you never do anything with what you capture. Practice on a lab virtual machine or a home network you control.
Try it yourself
network-diagnostics.txtDownload network-diagnostics.txt: https://restedteacher.com/practice-files/cybersecurity/network-diagnostics.txt
A saved terminal session from a fictional school lab computer running ip route, ping, dig, traceroute, and arp -a. Every address, domain, and MAC address in it is reserved for documentation or private networks, so nothing in the file points at a real computer.
Get to the file first
Your browser saves the file to your Downloads folder. Move it into a labs folder and go there:
mkdir -p ~/labs && mv ~/Downloads/network-diagnostics.txt ~/labs/ && cd ~/labs
Then run cat network-diagnostics.txt to read the session. On WSL, your Windows Downloads folder is /mnt/c/Users/<your-name>/Downloads instead of ~/Downloads.
Using network-diagnostics.txt, answer each question by reading the output of the command it names. grep with the right word pulls each answer out fast.
1. From the ip route output: what IPv4 address does this lab computer have (the src address), and what is its default gateway?
2. From the ping -c 5 to portal.kestrelvalley.test: what percentage of packets were lost, and which icmp_seq number never got a reply?
3. From the dig ... MX output: a mail server with a lower MX preference number is tried first. Which mail server is tried first for kestrelvalley.test?
4. From the traceroute output: how many numbered hop lines are listed, counting the destination itself, and which hop number did not answer?
5. From the arp -a output: one IP address other than the gateway shows the same MAC address as the gateway. Which IP address is it? ( grep ' at ', awk '{print $4}', sort, uniq -d, then grep the MAC )
Bonus: run the same read-only commands on your own machine, on a network you are allowed to use, and compare.