Where the command differs, each system gets its own line. Windows commands run in Command Prompt or PowerShell. Commands starting with powershell -c run a PowerShell command from either. In Windows PowerShell 5.1, type curl.exe instead of curl. Some tools, such as mtr, iftop and iperf3, need installing first. Interface names such as eth0 and en0 and all addresses are examples.

Your connection #

  • Show your IP addresses
    Linux
    ip -br addr
    macOS
    ipconfig getifaddr en0
    Windows
    ipconfig
  • Show full details for every network interface
    Linux
    ip addr show
    macOS
    ifconfig
    Windows
    ipconfig /all
  • Show MAC addresses
    Linux
    ip link show
    macOS
    ifconfig en0 ether
    Windows
    getmac /v
  • Show the default gateway
    Linux
    ip route show default
    macOS
    route -n get default
    Windows
    ipconfig | findstr /i "Gateway"
  • Show the DNS servers in use
    Linux
    resolvectl status
    macOS
    scutil --dns | grep nameserver
    Windows
    ipconfig /all | findstr /i /c:"DNS Servers"
  • Show your public IP addressLinux, macOS, Windows
    curl ifconfig.me
  • Get a new IP address from DHCP
    macOS
    sudo ipconfig set en0 DHCP
    Windows
    ipconfig /release && ipconfig /renew
  • Show traffic and error counts for each interface
    Linux
    ip -s link
    macOS
    netstat -i
    Windows
    netstat -e
  • Show the link speed of each adapter
    Linux
    ethtool eth0
    Windows
    powershell -c "Get-NetAdapter | Select-Object Name, LinkSpeed"

Ping and traceroute #

  • Check you can reach a host
    Linux, macOS
    ping -c 4 8.8.8.8
    Windows
    ping 8.8.8.8
  • Ping a host until you press Ctrl+C
    Linux, macOS
    ping 8.8.8.8
    Windows
    ping -t 8.8.8.8
  • Ping over IPv6
    Linux
    ping -6 -c 4 google.com
    macOS
    ping6 -c 4 google.com
    Windows
    ping -6 google.com
  • Ping with larger packets
    Linux, macOS
    ping -c 4 -s 1400 8.8.8.8
    Windows
    ping -l 1400 8.8.8.8
  • Find the largest packet that gets through without splitting (MTU)
    Linux
    ping -M do -s 1472 -c 4 8.8.8.8
    macOS
    ping -D -s 1472 -c 4 8.8.8.8
    Windows
    ping -f -l 1472 8.8.8.8
  • Trace the route to a host
    Linux, macOS
    traceroute 8.8.8.8
    Windows
    tracert 8.8.8.8
  • Trace the route without looking up names
    Linux, macOS
    traceroute -n 8.8.8.8
    Windows
    tracert -d 8.8.8.8
  • Trace the route over TCP to get past firewalls that block pingLinux
    sudo traceroute -T -p 443 example.com
  • Find where packets are being lost along the route
    Linux, macOS
    mtr 8.8.8.8
    Windows
    pathping 8.8.8.8

Ports and connections #

  • Test whether a TCP port is open
    Linux, macOS
    nc -zv example.com 443
    Windows
    powershell -c "Test-NetConnection example.com -Port 443"
  • List listening ports and the programs using them
    Linux
    sudo ss -tulpn
    macOS
    sudo lsof -iTCP -sTCP:LISTEN -n -P
    Windows
    netstat -ano | findstr LISTENING
  • Find what's using a port
    Linux, macOS
    sudo lsof -i :8080
    Windows
    netstat -ano | findstr :8080
  • List all connections
    Linux
    ss -tuna
    macOS, Windows
    netstat -an
  • Show connection statistics
    Linux
    ss -s
    macOS, Windows
    netstat -s
  • Watch live network use
    Linux
    sudo iftop -i eth0
    macOS
    nettop
    Windows
    resmon
  • Start a bandwidth test serverLinux, macOS, Windows
    iperf3 -s
  • Test bandwidth to an iperf3 serverLinux, macOS, Windows
    iperf3 -c 192.168.1.10

DNS #

  • Look up a domain's IP address
    Linux, macOS
    dig example.com +short
    Windows
    nslookup example.com
  • Show the full DNS answer
    Linux, macOS
    dig example.com
    Windows
    powershell -c "Resolve-DnsName example.com"
  • Look up a domain's mail (MX) records
    Linux, macOS
    dig example.com MX +short
    Windows
    nslookup -type=mx example.com
  • Look up a domain's TXT records, such as SPF
    Linux, macOS
    dig example.com TXT +short
    Windows
    nslookup -type=txt example.com
  • Look up a domain's name servers
    Linux, macOS
    dig example.com NS +short
    Windows
    nslookup -type=ns example.com
  • Look up a domain's IPv6 (AAAA) address
    Linux, macOS
    dig example.com AAAA +short
    Windows
    nslookup -type=aaaa example.com
  • Look up where a name points (CNAME)
    Linux, macOS
    dig www.example.com CNAME +short
    Windows
    nslookup -type=cname www.example.com
  • Look up a domain using a specific DNS server
    Linux, macOS
    dig @1.1.1.1 example.com +short
    Windows
    nslookup example.com 1.1.1.1
  • Look up the name for an IP address
    Linux, macOS
    dig -x 8.8.8.8 +short
    Windows
    nslookup 8.8.8.8
  • Follow a lookup from the root servers downLinux, macOS
    dig example.com +trace
  • Clear the DNS cache
    Linux
    sudo resolvectl flush-caches
    macOS
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    Windows
    ipconfig /flushdns
  • Show the DNS cacheWindows
    ipconfig /displaydns
  • Edit the hosts file
    Linux, macOS
    sudo nano /etc/hosts
    Windows
    notepad C:\Windows\System32\drivers\etc\hosts

Routes and ARP #

  • Show the routing table
    Linux
    ip route
    macOS
    netstat -rn
    Windows
    route print
  • Show which route an address uses
    Linux
    ip route get 8.8.8.8
    macOS
    route -n get 8.8.8.8
    Windows
    powershell -c "Find-NetRoute -RemoteIPAddress 8.8.8.8"
  • Add a route
    Linux
    sudo ip route add 10.20.0.0/16 via 192.168.1.254
    macOS
    sudo route -n add -net 10.20.0.0/16 192.168.1.254
    Windows
    route add 10.20.0.0 mask 255.255.0.0 192.168.1.254
  • Add a route that stays after a restartWindows
    route -p add 10.20.0.0 mask 255.255.0.0 192.168.1.254
  • Delete a route
    Linux
    sudo ip route del 10.20.0.0/16
    macOS
    sudo route -n delete -net 10.20.0.0/16
    Windows
    route delete 10.20.0.0
  • Show the ARP table
    Linux
    ip neigh
    macOS, Windows
    arp -a
  • Clear the ARP cache
    Linux
    sudo ip neigh flush all
    macOS
    sudo arp -a -d
    Windows
    netsh interface ip delete arpcache

Wi-Fi #

  • Show your current Wi-Fi connection
    Linux
    nmcli device wifi show
    macOS
    system_profiler SPAirPortDataType
    Windows
    netsh wlan show interfaces
  • List Wi-Fi networks in range
    Linux
    nmcli device wifi list
    Windows
    netsh wlan show networks mode=bssid

Web requests with curl #

  • Check a website responds and show its headersLinux, macOS, Windows
    curl -I https://example.com
  • Follow redirectsLinux, macOS, Windows
    curl -L https://example.com
  • Download a fileLinux, macOS, Windows
    curl -LO https://example.com/file.zip
  • Download a file under a different nameLinux, macOS, Windows
    curl -L -o setup.zip https://example.com/file.zip
  • Time how long a request takes
    Linux, macOS
    curl -o /dev/null -s -w "%{time_total}\n" https://example.com
    Windows
    curl -o NUL -s -w "%{time_total}\n" https://example.com
  • Test your download speed
    Linux, macOS
    curl -o /dev/null https://speed.cloudflare.com/__down?bytes=100000000
    Windows
    curl -o NUL https://speed.cloudflare.com/__down?bytes=100000000
  • Send JSON to an API
    Linux, macOS
    curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' https://api.example.com/items
    Windows
    curl -X POST -H "Content-Type: application/json" -d "{\"name\":\"test\"}" https://api.example.com/items
  • Call an API with a token
    Linux, macOS
    curl -H "Authorization: Bearer $TOKEN" https://api.example.com/me
    Windows
    curl -H "Authorization: Bearer %TOKEN%" https://api.example.com/me
  • Test a site on a new IP address before changing DNSLinux, macOS, Windows
    curl --resolve example.com:443:203.0.113.10 https://example.com
  • Show the TLS handshake and certificateLinux, macOS, Windows
    curl -vI https://example.com
  • Show when a site's certificate expiresLinux, macOS
    echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -enddate

Packet capture #

  • Capture packets on an interface
    Linux
    sudo tcpdump -i eth0
    macOS
    sudo tcpdump -i en0
    Windows
    pktmon start --capture
  • Capture packets to one host and port
    Linux
    sudo tcpdump -i any host 192.168.1.20 and port 443
    macOS
    sudo tcpdump -i en0 host 192.168.1.20 and port 443
  • Save a capture to open in Wireshark
    Linux
    sudo tcpdump -i eth0 -w capture.pcap
    macOS
    sudo tcpdump -i en0 -w capture.pcap
    Windows
    pktmon stop && pktmon etl2pcap PktMon.etl --out capture.pcapng

SSH tunnels #

  • Reach a remote service through SSH on a local portLinux, macOS, Windows
    ssh -L 8080:localhost:80 user@server01
  • Share a local service on a port of the remote serverLinux, macOS, Windows
    ssh -R 9000:localhost:3000 user@server01
  • Use a server as a SOCKS proxyLinux, macOS, Windows
    ssh -D 1080 user@server01
  • Connect through a jump hostLinux, macOS, Windows
    ssh -J [email protected] user@server01