Network diagnostics
IP addresses and routes, DNS lookups, reachability, open ports and traffic capture.
Interfaces and routes
IP addresses of interfaces
ip -br addrRouting table
ip routeWhich route is used for an address
ip route get <ip>
Your public IP
curl -s https://ifconfig.meDNS
Resolve a domain
dig +short <domain>
Specific record type (MX, TXT, CNAME…)
dig +short <domain> MX
Ask a specific DNS server
dig @8.8.8.8 <domain>
Full resolution path from the rootadvanced
dig +trace <domain>
Reverse lookup of an IP
dig -x <ip> +short
Reachability
Ping 4 times
ping -c 4 <host>
Path to a host
traceroute <host>
Path with per-hop packet lossadvanced
mtr -rw <host>
Is a TCP port open?
nc -zv <host> <port>
Check a port without nc (bash only)advanced
timeout 3 bash -c '</dev/tcp/<host>/<port>' && echo open || echo closed
Ports and connections
Listening ports with processes
sudo ss -tulpnEstablished connections
ss -tn state establishedConnections count per remote IPadvanced
ss -tn state established | awk 'NR>1 {split($4,a,":"); print a[1]}' | sort | uniq -c | sort -rn | headScan open ports of your own hostadvanced
nmap -sT <host>
Scan only hosts you own or are allowed to test.
Traffic
Capture traffic on a portadvanced
sudo tcpdump -i any port <port> -nn
Save a capture for Wiresharkadvanced
sudo tcpdump -i any port <port> -w capture.pcap
Bandwidth between two hostsadvanced
iperf3 -c <host>
Start iperf3 -s on the other host first.