Firewall & Networking Cheat Sheet
· 4 min read
Network Diagnostics
Basic Connectivity
ping [host]- Test connectivity to a hostping -c 4 [host]- Send 4 packets (Linux/Mac)traceroute [host]- Show route packets take to destination (Linux/Mac)tracert [host]- Show route packets take to destination (Windows)mtr [host]- Combined ping and traceroute (Linux)
Network Information
ifconfig- Display network interfaces (Linux/Mac, deprecated)ip addr show- Display IP addresses and interfaces (Linux, modern)ip link show- Display network interfaces statusipconfig- Display network configuration (Windows)ipconfig /all- Detailed network configuration (Windows)hostname -I- Show all IP addresses of the host
DNS
nslookup [domain]- Query DNS for domain informationdig [domain]- Detailed DNS lookup (Linux/Mac)host [domain]- Simple DNS lookupdig +short [domain]- Brief DNS responsenslookup -type=mx [domain]- Query MX records
Port Scanning & Connections
netstat -tuln- Show listening ports (Linux)netstat -ano- Show all connections with process IDs (Windows)ss -tuln- Modern alternative to netstat (Linux)lsof -i :[port]- Show process using specific port (Linux/Mac)nc -zv [host] [port]- Test if port is open (netcat)telnet [host] [port]- Test port connectivitynmap [host]- Scan ports on target hostnmap -p- [host]- Scan all ports
Network Statistics
netstat -s- Display network statisticsiftop- Real-time bandwidth monitoring (Linux)nethogs- Monitor bandwidth per process (Linux)tcpdump -i [interface]- Capture network packetstcpdump -i eth0 port 80- Capture HTTP traffic
Linux Firewalls
iptables
iptables -L- List all rulesiptables -L -v -n- List rules with verbose outputiptables -A INPUT -p tcp --dport 22 -j ACCEPT- Allow SSHiptables -A INPUT -s 192.168.1.0/24 -j ACCEPT- Allow subnetiptables -A INPUT -p tcp --dport 80 -j DROP- Block port 80iptables -D INPUT [rule_number]- Delete rule by numberiptables -F- Flush all rules (caution!)iptables -P INPUT DROP- Set default policy to DROPiptables-save > /etc/iptables/rules.v4- Save rulesiptables-restore < /etc/iptables/rules.v4- Restore rules
firewalld (RHEL/CentOS/Fedora)
firewall-cmd --state- Check firewall statusfirewall-cmd --list-all- List all settingsfirewall-cmd --get-zones- List all zonesfirewall-cmd --get-active-zones- Show active zonesfirewall-cmd --zone=public --add-port=8080/tcp- Open port temporarilyfirewall-cmd --zone=public --add-port=8080/tcp --permanent- Open port permanentlyfirewall-cmd --reload- Reload firewall rulesfirewall-cmd --zone=public --add-service=http- Allow servicefirewall-cmd --zone=public --remove-port=8080/tcp --permanent- Remove portfirewall-cmd --list-ports- List open ports
ufw (Ubuntu/Debian)
ufw status- Check firewall statusufw enable- Enable firewallufw disable- Disable firewallufw allow 22- Allow port 22ufw allow ssh- Allow SSH serviceufw allow from 192.168.1.0/24- Allow subnetufw deny 80- Deny port 80ufw delete allow 80- Remove allow ruleufw status numbered- List rules with numbersufw delete [number]- Delete rule by numberufw reset- Reset to default settings
Windows Firewall
netsh (Command Line)
netsh advfirewall show allprofiles- Show all firewall profilesnetsh advfirewall set allprofiles state on- Enable firewallnetsh advfirewall set allprofiles state off- Disable firewallnetsh advfirewall firewall show rule name=all- List all rulesnetsh advfirewall firewall add rule name="Allow Port 80" dir=in action=allow protocol=TCP localport=80- Add inbound rulenetsh advfirewall firewall delete rule name="Allow Port 80"- Delete rulenetsh advfirewall reset- Reset firewall to defaults
PowerShell
Get-NetFirewallRule- List all firewall rulesGet-NetFirewallProfile- Show firewall profilesSet-NetFirewallProfile -Profile Domain,Public,Private -Enabled True- Enable firewallNew-NetFirewallRule -DisplayName "Allow Port 8080" -Direction Inbound -LocalPort 8080 -Protocol TCP -Action Allow- Create ruleRemove-NetFirewallRule -DisplayName "Allow Port 8080"- Remove ruleGet-NetFirewallRule | Where-Object {$_.Enabled -eq 'True'}- Show enabled rules
Routing
Linux
ip route show- Display routing tableroute -n- Display routing table (deprecated)ip route add 10.0.0.0/24 via 192.168.1.1- Add static routeip route del 10.0.0.0/24- Delete routeip route get [IP]- Show route to specific IP
Windows
route print- Display routing tableroute add 10.0.0.0 mask 255.255.255.0 192.168.1.1- Add static routeroute delete 10.0.0.0- Delete routeroute -p add [destination] mask [netmask] [gateway]- Add persistent route
Network Configuration
Linux
ip addr add 192.168.1.10/24 dev eth0- Add IP to interfaceip link set eth0 up- Bring interface upip link set eth0 down- Bring interface downdhclient eth0- Request DHCP addresssystemctl restart networking- Restart networking (Debian/Ubuntu)systemctl restart NetworkManager- Restart NetworkManager (RHEL/Fedora)
Windows
ipconfig /release- Release DHCP leaseipconfig /renew- Renew DHCP leaseipconfig /flushdns- Clear DNS cachenetsh interface ip set address "Ethernet" static 192.168.1.10 255.255.255.0 192.168.1.1- Set static IP
Troubleshooting Tips
- Always test firewall rules before applying permanently
- Use
--permanentflag with firewalld to make changes persistent - Check logs:
/var/log/firewalld(firewalld),/var/log/syslogor/var/log/messages(iptables) - Remember that some tools require root/administrator privileges
- Document all firewall changes for future reference