Batch 5: Protocols & Security Networking Apache & NGINX Cloud ← Full TOC

← Networking Index

🔧 Network Diagnostics — ping, traceroute, netstat, ss, ip, tcpdump, nmap

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.

📋 Reference

ItemSyntax / ValueDescription
pingping -c 4 mywebuniversity.comTest ICMP reachability and latency
ping -iping -i 0.2 -c 10 hostSet interval between pings
ping6ping6 ::1Ping IPv6 address
traceroutetraceroute mywebuniversity.comShow hop-by-hop path to destination
traceroute -Ttraceroute -T -p 443 hostTCP traceroute on port 443 (penetrates firewalls)
mtrmtr mywebuniversity.comMy Traceroute — live latency + packet loss per hop
ss -tlnpss -tlnpShow listening TCP ports + PID
ss -ulnpss -ulnpShow listening UDP ports
ss -sss -sSocket statistics summary
ss -anss -an | grep :80All connections on port 80
netstatnetstat -tulnpLegacy: show listening ports (use ss instead)
ip addrip addr show / ip aShow all network interfaces and IP addresses
ip linkip link showShow network interface status
ip routeip route showShow routing table
ip route addsudo ip route add 10.0.0.0/8 via 192.168.1.1Add static route
ip neighip neigh showShow ARP table (neighbors)
ifconfigifconfig eth0 / ifconfig -aLegacy interface config (use ip instead)
hostnamehostname / hostname -IShow hostname / all IP addresses
nmap -sVnmap -sV -p 1-65535 hostPort scan with service version detection
nmap -snnmap -sn 192.168.1.0/24Ping sweep — discover live hosts
nmap -Onmap -O hostOS fingerprint detection
tcpdumpsudo tcpdump -i eth0 -n port 80Capture packets on interface
tcpdump -wsudo tcpdump -w capture.pcapWrite packets to file (open with Wireshark)
tcpdump hostsudo tcpdump host 8.8.8.8Capture only packets to/from host
curl -vcurl -v https://mywebuniversity.com/HTTP request with full header trace
ncnc -zv host 443 / nc -l -p 8080Netcat — test ports, simple server
lsof -ilsof -i :80Show processes using port 80
ethtoolsudo ethtool eth0Network interface statistics
iperf3iperf3 -s / iperf3 -c serverBandwidth testing between hosts
dig +statsdig +stats mywebuniversity.comDNS query with timing statistics

💡 Example

# 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

← DNS & Name Resolution  |  🏠 Index  |  Firewalls & iptables →