Network diagnostic tools help identify connectivity problems, latency, open ports, and packet flow. Master these tools and you can diagnose virtually any network issue from the Linux command line.
| Item | Syntax / Value | Description |
|---|---|---|
| ping | ping -c 4 mywebuniversity.com | Test ICMP reachability and latency |
| ping -i | ping -i 0.2 -c 10 host | Set interval between pings |
| ping6 | ping6 ::1 | Ping IPv6 address |
| traceroute | traceroute mywebuniversity.com | Show hop-by-hop path to destination |
| traceroute -T | traceroute -T -p 443 host | TCP traceroute on port 443 (penetrates firewalls) |
| mtr | mtr mywebuniversity.com | My Traceroute — live latency + packet loss per hop |
| ss -tlnp | ss -tlnp | Show listening TCP ports + PID |
| ss -ulnp | ss -ulnp | Show listening UDP ports |
| ss -s | ss -s | Socket statistics summary |
| ss -an | ss -an | grep :80 | All connections on port 80 |
| netstat | netstat -tulnp | Legacy: show listening ports (use ss instead) |
| ip addr | ip addr show / ip a | Show all network interfaces and IP addresses |
| ip link | ip link show | Show network interface status |
| ip route | ip route show | Show routing table |
| ip route add | sudo ip route add 10.0.0.0/8 via 192.168.1.1 | Add static route |
| ip neigh | ip neigh show | Show ARP table (neighbors) |
| ifconfig | ifconfig eth0 / ifconfig -a | Legacy interface config (use ip instead) |
| hostname | hostname / hostname -I | Show hostname / all IP addresses |
| nmap -sV | nmap -sV -p 1-65535 host | Port scan with service version detection |
| nmap -sn | nmap -sn 192.168.1.0/24 | Ping sweep — discover live hosts |
| nmap -O | nmap -O host | OS fingerprint detection |
| tcpdump | sudo tcpdump -i eth0 -n port 80 | Capture packets on interface |
| tcpdump -w | sudo tcpdump -w capture.pcap | Write packets to file (open with Wireshark) |
| tcpdump host | sudo tcpdump host 8.8.8.8 | Capture only packets to/from host |
| curl -v | curl -v https://mywebuniversity.com/ | HTTP request with full header trace |
| nc | nc -zv host 443 / nc -l -p 8080 | Netcat — test ports, simple server |
| lsof -i | lsof -i :80 | Show processes using port 80 |
| ethtool | sudo ethtool eth0 | Network interface statistics |
| iperf3 | iperf3 -s / iperf3 -c server | Bandwidth testing between hosts |
| dig +stats | dig +stats mywebuniversity.com | DNS query with timing statistics |
# Network Diagnostics — Essential Commands
# ── Connectivity testing ──────────────────────────────────────
ping -c 4 8.8.8.8 # ICMP ping (4 packets)
ping -c 4 mywebuniversity.com # ping by hostname
ping -i 0.5 -c 20 host # ping every 0.5s
# ── Path tracing ──────────────────────────────────────────────
traceroute mywebuniversity.com # UDP traceroute
traceroute -T -p 443 mywebuniversity.com # TCP on port 443 (firewall-friendly)
mtr --report mywebuniversity.com # combined ping + traceroute report
mtr -n mywebuniversity.com # live view (no DNS lookup)
# ── Port and socket info ──────────────────────────────────────
ss -tlnp # TCP listening ports + PID
ss -ulnp # UDP listening ports + PID
ss -anp | grep :443 # connections on port 443
ss -tp # established TCP connections
ss -s # summary statistics
lsof -i :80 # processes on port 80
lsof -i :443 # processes on port 443
lsof -i TCP -s TCP:LISTEN # all listening TCP
# ── Interface and routing ─────────────────────────────────────
ip addr show # all interfaces + IPs
ip addr show eth0 # specific interface
ip link show # interface status (up/down)
ip route show # routing table
ip route get 8.8.8.8 # route to specific destination
ip neigh show # ARP table
# Add static route (temporary)
sudo ip route add 10.0.0.0/8 via 192.168.1.1 dev eth0
# Remove route
sudo ip route del 10.0.0.0/8
# ── Port scanning (nmap) ──────────────────────────────────────
nmap localhost # scan localhost (top 1000 ports)
nmap -p 80,443,22 mywebuniversity.com # specific ports
nmap -sV -p 22,80,443 mywebuniversity.com # detect service versions
nmap -sn 192.168.1.0/24 # ping sweep — find live hosts
sudo nmap -O mywebuniversity.com # OS detection (requires root)
# ── Packet capture (tcpdump) ─────────────────────────────────
sudo tcpdump -i eth0 -n # all traffic, no DNS
sudo tcpdump -i eth0 port 80 # HTTP traffic only
sudo tcpdump -i eth0 host 8.8.8.8 # traffic to/from Google DNS
sudo tcpdump -i eth0 'tcp and port 443' -n # HTTPS only
sudo tcpdump -w /tmp/capture.pcap -i eth0 # save for Wireshark
sudo tcpdump -r /tmp/capture.pcap # read saved capture
# ── HTTP testing ──────────────────────────────────────────────
curl -v https://mywebuniversity.com/ # full verbose HTTP request
curl -I https://mywebuniversity.com/ # HEAD only
curl -s -o /dev/null -w "HTTP:%{http_code} DNS:%{time_namelookup}s TLS:%{time_appconnect}s Total:%{time_total}s\n" https://mywebuniversity.com/
# ── Netcat (nc) utilities ─────────────────────────────────────
nc -zv mywebuniversity.com 443 # TCP connect test
nc -zv mywebuniversity.com 22 # SSH port test
echo "GET / HTTP/1.0\r\n\r\n" | nc mywebuniversity.com 80 # raw HTTP
# ── Bandwidth test (iperf3) ───────────────────────────────────
# On server:
iperf3 -s -p 5201
# On client:
iperf3 -c server.ip -p 5201 -t 10 # 10-second test
iperf3 -c server.ip -u -b 100M # UDP test at 100Mbps
# ── Python network check ──────────────────────────────────────
import socket, time
def check_port(host, port, timeout=3):
try:
start = time.time()
with socket.create_connection((host, port), timeout=timeout):
ms = (time.time() - start) * 1000
return True, ms
except (ConnectionRefusedError, TimeoutError, OSError) as e:
return False, str(e)
for service in [('mywebuniversity.com',80), ('mywebuniversity.com',443), ('8.8.8.8',53)]:
ok, ms = check_port(*service)
if ok: print(f" {service[0]}:{service[1]} OPEN ({ms:.1f}ms)")
else: print(f" {service[0]}:{service[1]} CLOSED ({ms})")
# python3 netcheck.py