Network Cheat Sheet

Cheet says: Know thy network!

IP & Interface Info


ip addr                    # Show all interfaces
ip -4 addr                 # IPv4 only
ip link                    # Link layer info
ip route                   # Routing table
ip neigh                   # ARP table

hostname -I                # All IPs
curl ifconfig.me           # Public IP

Port Scanning & Listening


What's listening?

ss -tlnp # TCP listeners with process ss -ulnp # UDP listeners lsof -i :80 # Who's using port 80? netstat -tulpn # Classic way

Scan ports

nmap -sT localhost # TCP connect scan nmap -sV 192.168.1.1 # Service detection nmap -A 192.168.1.0/24 # Aggressive scan

DNS Queries


dig example.com            # Full query
dig +short example.com     # Just the answer
dig @8.8.8.8 example.com   # Use specific DNS
dig -x 8.8.8.8             # Reverse lookup
dig example.com ANY        # All records

nslookup example.com       # Simple lookup
host example.com           # Another way

Network Testing


ping -c 4 google.com       # ICMP ping
mtr google.com             # Traceroute + ping
traceroute google.com      # Route tracing

curl -v https://site.com   # Verbose HTTP
curl -I https://site.com   # Headers only
wget --spider url          # Check if exists

Packet Capture


tcpdump basics

tcpdump -i eth0 # Capture on interface tcpdump port 80 # Filter by port tcpdump host 1.2.3.4 # Filter by host tcpdump -w capture.pcap # Write to file tcpdump -r capture.pcap # Read from file

Common filters

tcpdump 'tcp port 443' tcpdump 'not port 22' tcpdump 'src host 10.0.0.1'

Firewall (UFW)


ufw status                 # Show rules
ufw enable                 # Enable firewall
ufw allow 22/tcp           # Allow SSH
ufw deny 23                # Block telnet
ufw allow from 10.0.0.0/8  # Allow subnet
ufw delete allow 80        # Remove rule
ufw reset                  # Reset all

Firewall (iptables)


iptables -L -n -v          # List all rules
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -j DROP  # Default deny

Save/restore

iptables-save > rules.v4 iptables-restore < rules.v4

Connections & Sessions


ss -s                      # Summary stats
ss -t state established    # Active connections
ss -o                      # Show timers
watch ss -tp               # Live view

Who's connected?

who # Logged in users w # Users + activity last # Login history

Bandwidth Testing


iperf3 -s                  # Server mode
iperf3 -c server_ip        # Client test
speedtest-cli              # Internet speed

Useful One-Liners


Find open ports on network

nmap -sn 192.168.1.0/24 # Ping sweep

Monitor connections live

watch -n1 'ss -t'

Check if port is open

nc -zv host 443

Quick HTTP server

python3 -m http.server 8000