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.
Official links: Linux man pages, Windows commands.
Your connection #
-
Show your IP addressesLinux
ip -br addrmacOSipconfig getifaddr en0Windowsipconfig -
Show full details for every network interfaceLinux
ip addr showmacOSifconfigWindowsipconfig /all -
Show MAC addressesLinux
ip link showmacOSifconfig en0 etherWindowsgetmac /v -
Show the default gatewayLinux
ip route show defaultmacOSroute -n get defaultWindowsipconfig | findstr /i "Gateway" -
Show the DNS servers in useLinux
resolvectl statusmacOSscutil --dns | grep nameserverWindowsipconfig /all | findstr /i /c:"DNS Servers" -
Show your public IP addressLinux, macOS, Windows
curl ifconfig.me -
Get a new IP address from DHCPmacOS
sudo ipconfig set en0 DHCPWindowsipconfig /release && ipconfig /renew -
Show traffic and error counts for each interfaceLinux
ip -s linkmacOSnetstat -iWindowsnetstat -e -
Show the link speed of each adapterLinux
ethtool eth0Windowspowershell -c "Get-NetAdapter | Select-Object Name, LinkSpeed"
Ping and traceroute #
-
Check you can reach a hostLinux, macOS
ping -c 4 8.8.8.8Windowsping 8.8.8.8 -
Ping a host until you press Ctrl+CLinux, macOS
ping 8.8.8.8Windowsping -t 8.8.8.8 -
Ping over IPv6Linux
ping -6 -c 4 google.commacOSping6 -c 4 google.comWindowsping -6 google.com -
Ping with larger packetsLinux, macOS
ping -c 4 -s 1400 8.8.8.8Windowsping -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.8macOSping -D -s 1472 -c 4 8.8.8.8Windowsping -f -l 1472 8.8.8.8 -
Trace the route to a hostLinux, macOS
traceroute 8.8.8.8Windowstracert 8.8.8.8 -
Trace the route without looking up namesLinux, macOS
traceroute -n 8.8.8.8Windowstracert -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 routeLinux, macOS
mtr 8.8.8.8Windowspathping 8.8.8.8
Ports and connections #
-
Test whether a TCP port is openLinux, macOS
nc -zv example.com 443Windowspowershell -c "Test-NetConnection example.com -Port 443" -
List listening ports and the programs using themLinux
sudo ss -tulpnmacOSsudo lsof -iTCP -sTCP:LISTEN -n -PWindowsnetstat -ano | findstr LISTENING -
Find what's using a portLinux, macOS
sudo lsof -i :8080Windowsnetstat -ano | findstr :8080 -
List all connectionsLinux
ss -tunamacOS, Windowsnetstat -an -
Show connection statisticsLinux
ss -smacOS, Windowsnetstat -s -
Watch live network useLinux
sudo iftop -i eth0macOSnettopWindowsresmon -
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 addressLinux, macOS
dig example.com +shortWindowsnslookup example.com -
Show the full DNS answerLinux, macOS
dig example.comWindowspowershell -c "Resolve-DnsName example.com" -
Look up a domain's mail (MX) recordsLinux, macOS
dig example.com MX +shortWindowsnslookup -type=mx example.com -
Look up a domain's TXT records, such as SPFLinux, macOS
dig example.com TXT +shortWindowsnslookup -type=txt example.com -
Look up a domain's name serversLinux, macOS
dig example.com NS +shortWindowsnslookup -type=ns example.com -
Look up a domain's IPv6 (AAAA) addressLinux, macOS
dig example.com AAAA +shortWindowsnslookup -type=aaaa example.com -
Look up where a name points (CNAME)Linux, macOS
dig www.example.com CNAME +shortWindowsnslookup -type=cname www.example.com -
Look up a domain using a specific DNS serverLinux, macOS
dig @1.1.1.1 example.com +shortWindowsnslookup example.com 1.1.1.1 -
Look up the name for an IP addressLinux, macOS
dig -x 8.8.8.8 +shortWindowsnslookup 8.8.8.8 -
Follow a lookup from the root servers downLinux, macOS
dig example.com +trace -
Clear the DNS cacheLinux
sudo resolvectl flush-cachesmacOSsudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderWindowsipconfig /flushdns -
Show the DNS cacheWindows
ipconfig /displaydns -
Edit the hosts fileLinux, macOS
sudo nano /etc/hostsWindowsnotepad C:\Windows\System32\drivers\etc\hosts
Routes and ARP #
-
Show the routing tableLinux
ip routemacOSnetstat -rnWindowsroute print -
Show which route an address usesLinux
ip route get 8.8.8.8macOSroute -n get 8.8.8.8Windowspowershell -c "Find-NetRoute -RemoteIPAddress 8.8.8.8" -
Add a routeLinux
sudo ip route add 10.20.0.0/16 via 192.168.1.254macOSsudo route -n add -net 10.20.0.0/16 192.168.1.254Windowsroute 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 routeLinux
sudo ip route del 10.20.0.0/16macOSsudo route -n delete -net 10.20.0.0/16Windowsroute delete 10.20.0.0 -
Show the ARP tableLinux
ip neighmacOS, Windowsarp -a -
Clear the ARP cacheLinux
sudo ip neigh flush allmacOSsudo arp -a -dWindowsnetsh interface ip delete arpcache
Wi-Fi #
-
Show your current Wi-Fi connectionLinux
nmcli device wifi showmacOSsystem_profiler SPAirPortDataTypeWindowsnetsh wlan show interfaces -
List Wi-Fi networks in rangeLinux
nmcli device wifi listWindowsnetsh 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 takesLinux, macOS
curl -o /dev/null -s -w "%{time_total}\n" https://example.comWindowscurl -o NUL -s -w "%{time_total}\n" https://example.com -
Test your download speedLinux, macOS
curl -o /dev/null https://speed.cloudflare.com/__down?bytes=100000000Windowscurl -o NUL https://speed.cloudflare.com/__down?bytes=100000000 -
Send JSON to an APILinux, macOS
curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' https://api.example.com/itemsWindowscurl -X POST -H "Content-Type: application/json" -d "{\"name\":\"test\"}" https://api.example.com/items -
Call an API with a tokenLinux, macOS
curl -H "Authorization: Bearer $TOKEN" https://api.example.com/meWindowscurl -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 interfaceLinux
sudo tcpdump -i eth0macOSsudo tcpdump -i en0Windowspktmon start --capture -
Capture packets to one host and portLinux
sudo tcpdump -i any host 192.168.1.20 and port 443macOSsudo tcpdump -i en0 host 192.168.1.20 and port 443 -
Save a capture to open in WiresharkLinux
sudo tcpdump -i eth0 -w capture.pcapmacOSsudo tcpdump -i en0 -w capture.pcapWindowspktmon 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