Cheatsheets / Networking Cheatsheet

Networking Cheatsheet

curl, DNS lookups, checking open ports, and ping/traceroute - with the command differences between Linux, macOS, and Windows called out.

Last verified

curl and ping behave almost identically across Linux, macOS, and Windows (PowerShell 7+ ships a real curl.exe, not just an alias). Port-inspection and DNS tools differ more, so those sections are split by OS.

curl

curl https://example.com

Fetches a URL and prints the response body.

curl -I https://example.com

Fetches only the response headers (a HEAD request).

curl -i https://example.com

Fetches the response including its headers, followed by the body.

curl -X POST -H "Content-Type: application/json" -d '{"a":1}' https://api.example.com

Sends a JSON POST request with a custom header and body.

curl -o file.zip https://example.com/file.zip

Downloads a file, saving it under a name you choose.

curl -O https://example.com/file.zip

Downloads a file, keeping the remote filename.

curl -L https://example.com

Follows HTTP redirects instead of stopping at the first 3xx response.

curl -v https://example.com

Shows the full request/response exchange, including TLS handshake details - the first thing to add when debugging a failing request.

curl -u user:pass https://api.example.com

Sends HTTP Basic Auth credentials with the request.

curl -w "%{http_code} %{time_total}s\n" -o /dev/null -s https://example.com

Prints just the status code and total time, discarding the body - handy for quick health checks.

DNS lookups

dig example.com

Full DNS query and answer (Linux/macOS; not installed by default on Windows).

dig example.com +short

Prints just the resolved IP address(es), no extra output.

dig example.com MX

Looks up a specific record type - here, mail exchange records.

dig -x 8.8.8.8

Performs a reverse DNS lookup (IP to hostname).

nslookup example.com

Cross-platform DNS lookup tool, available by default on Linux, macOS, and Windows.

Resolve-DnsName example.com

Windows PowerShell’s native DNS lookup cmdlet, with structured object output.

Finding what’s using a port

ss -tulpn

Linux: lists listening TCP/UDP sockets with owning process IDs (sudo needed to see the process name for all sockets).

sudo lsof -i :3000

Linux/macOS: shows which process is bound to a specific port.

lsof -i -P | grep LISTEN

macOS/Linux: lists all listening sockets across every port.

Get-NetTCPConnection -State Listen

Windows: lists all listening TCP ports and their owning process IDs.

Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess

Windows: resolves the process name that owns whatever is listening on port 3000.

netstat -an | grep LISTEN

Older, still-common way to list listening sockets on macOS (and Linux systems where net-tools is installed).

Checking your own IP and connectivity

curl -4 ifconfig.me

Prints your public IPv4 address, as seen from the internet.

ip addr show

Linux: lists local network interfaces and their assigned IPs.

ifconfig

macOS (and legacy Linux): lists local network interfaces and their assigned IPs.

Get-NetIPAddress

Windows: lists IP addresses assigned to all network adapters.

ping -c 4 example.com

Linux/macOS: sends 4 ICMP echo requests and stops.

Test-Connection example.com -Count 4

Windows: PowerShell’s equivalent of ping -c 4.

traceroute example.com

Linux/macOS: shows the network hops a packet takes to reach a host.

tracert example.com

Windows: same idea as traceroute, different binary name.

Cross-OS notes

  • Ports: ss is Linux-only (part of iproute2); macOS relies on lsof -i or netstat; Windows uses Get-NetTCPConnection.
  • DNS: dig isn’t installed on Windows by default - use Resolve-DnsName in PowerShell or nslookup everywhere.
  • curl on Windows: PowerShell historically aliased curl to Invoke-WebRequest, which takes different flags. PowerShell 7+ ships the real curl.exe, but if curl -I behaves oddly, run curl.exe explicitly to bypass any alias.
  • IPv6: add -6 to curl/ping (Linux/macOS) to force IPv6, or -4 to force IPv4 when a host resolves to both.
  • See ssh.md for remote-access-specific networking (tunnels, jump hosts).