Linux Firewall Cheat Sheet
Common Linux firewall command cheat sheet, including iptables, firewalld, ufw, etc.
iptables -L -n -vList all rules (verbose mode)
iptables -L -n --line-numbersList rules and display line numbers
iptables -t nat -L -n -vList NAT table rules
iptables-save > /etc/iptables.rulesSave current rules to file
iptables-restore < /etc/iptables.rulesRestore rules from file
iptables -FClear all rules
iptables -t nat -FClear NAT table rules
iptables -XDelete all custom chains
iptables -ZClear all counters
iptables -P INPUT DROPSet default policy of INPUT chain to DROP
iptables -P INPUT ACCEPTSet default policy of INPUT chain to ACCEPT
iptables -A INPUT -s 192.168.1.100 -j ACCEPTAllow access from specified IP
iptables -A INPUT -s 192.168.1.0/24 -j ACCEPTAllow access from specified subnet
iptables -A INPUT -s 192.168.1.100 -p tcp --dport 22 -j ACCEPTAllow specified IP to access specified port
iptables -A INPUT -s 10.0.0.100 -j DROPDeny specified IP access
iptables -A INPUT -s 10.0.0.0/8 -j DROPDeny access from specified subnet
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTAllow established connections
iptables -A INPUT -i lo -j ACCEPTAllow loopback interface
iptables -P INPUT DROP\niptables -A INPUT -s 192.168.1.0/24 -j ACCEPT\niptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTAllow only whitelisted IPs (full configuration)
iptables -A INPUT -p tcp --dport 22 -j ACCEPTAllow SSH connection (port 22)
iptables -A INPUT -p tcp --dport 80 -j ACCEPTAllow HTTP connection (port 80)
iptables -A INPUT -p tcp --dport 443 -j ACCEPTAllow HTTPS connection (port 443)
iptables -A INPUT -p tcp --dport 3306 -j ACCEPTAllow MySQL connection (port 3306)
iptables -A INPUT -p tcp --dport 6379 -j ACCEPTAllow Redis connection (port 6379)
iptables -A INPUT -p tcp --dport 8000:9000 -j ACCEPTAllow port range 8000-9000
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPTAllow Ping requests
iptables -A INPUT -p icmp --icmp-type echo-request -j DROPBlock Ping requests
iptables -D INPUT 3Delete the 3rd rule in INPUT chain
iptables -I INPUT 1 -s 192.168.1.100 -j ACCEPTInsert rule at the 1st line
iptables -A INPUT -j LOG --log-prefix "IPTables-Dropped: "Log dropped packets
iptables -A INPUT -p tcp --dport 22 -m limit --limit 3/min --limit-burst 3 -j ACCEPTLimit SSH connection rate
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080Port forwarding 80 to 8080
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEEnable NAT masquerading (shared internet access)
firewall-cmd --stateCheck firewall status
systemctl start firewalldStart firewall
systemctl stop firewalldStop firewall
systemctl enable firewalldSet to start on boot
systemctl disable firewalldDisable start on boot
firewall-cmd --reloadReload configuration
firewall-cmd --list-allList all configurations in the current zone
firewall-cmd --get-zonesList all available zones
firewall-cmd --get-default-zoneGet the default zone
firewall-cmd --set-default-zone=publicSet the default zone
firewall-cmd --get-servicesList all available services
firewall-cmd --permanent --add-service=httpPermanently add HTTP service
firewall-cmd --permanent --remove-service=httpPermanently remove HTTP service
firewall-cmd --permanent --add-port=8080/tcpPermanently open port 8080
firewall-cmd --permanent --remove-port=8080/tcpPermanently close port 8080
firewall-cmd --permanent --add-port=8000-9000/tcpPermanently open port range
firewall-cmd --permanent --add-source=192.168.1.0/24Add trusted source IP subnet
firewall-cmd --permanent --remove-source=192.168.1.0/24Remove trusted source IP subnet
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.100 accept'Rich rule: Allow specified IP
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.100 drop'Rich rule: Deny specified IP
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.0/24 port port=22 protocol=tcp accept'Rich rule: Allow subnet to access specified port
firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080Port forwarding 80 to 8080
firewall-cmd --permanent --add-masqueradeEnable NAT masquerading
ufw status verboseView firewall status (verbose)
ufw enableEnable firewall
ufw disableDisable firewall
ufw resetReset all rules
ufw default deny incomingDefault deny all incoming
ufw default allow outgoingDefault allow all outgoing
ufw reloadReload rules
ufw status numberedDisplay the list of rules with numbers
ufw allow sshAllow SSH service
ufw allow httpAllow HTTP service
ufw allow httpsAllow HTTPS service
ufw allow 8080/tcpAllow TCP port 8080
ufw allow 8000:9000/tcpAllow port range 8000-9000
ufw allow from 192.168.1.100Allow all access from specified IP
ufw allow from 192.168.1.0/24Allow all access from specified subnet
ufw allow from 192.168.1.100 to any port 22Allow specified IP to access port 22
ufw deny from 10.0.0.100Deny all access from specified IP
ufw deny 3306/tcpDeny TCP port 3306
ufw delete allow 8080/tcpDelete rule allowing 8080
ufw delete 3Delete rule number 3
ufw insert 1 allow from 192.168.1.100Insert rule at line 1
ufw limit sshLimit SSH connection rate (prevent brute force attacks)
nft list rulesetList all rules
nft flush rulesetClear all rules
nft add table inet filterAdd table
nft add chain inet filter input { type filter hook input priority 0 \\; }Add chain
nft add rule inet filter input tcp dport 22 acceptAllow port 22
nft add rule inet filter input ip saddr 192.168.1.100 acceptAllow specified IP
nft add rule inet filter input ip saddr 10.0.0.100 dropDeny specified IP
nft list ruleset > /etc/nftables.confSave rules to file
nft -f /etc/nftables.confRestore rules from file
πTool Introduction
Key Features
βFrequently Asked Questions
πRelated Tools
Cron Expression Parser
Validate cron syntax and preview upcoming schedules.
JSON to CSV
Convert JSON data to CSV format
JSON to YAML
Convert JSON data to YAML format
JSON to XML
Convert JSON data to XML format
YAML to JSON
Convert YAML configuration to JSON data
JSON Formatter
Format, validate and minify JSON data
JSON Visualizer
Display JSON data in tree structure
JSON Data Generator
Generate mock JSON data for testing
i18n JSON Translator
Translate entire JSON locale files in one go. Paste your base content, choose target languages, and the tool will call your OpenRouter-powered API with flattened keys.
JSON Diff Comparison
Compare differences between two JSON data
QR Code Generator
Generate custom QR code images
SVG Placeholder Generator
Generate custom SVG placeholder images
Base64 Image Converter
Convert images to Base64 encoding and vice versa
UUID Generator
Generate UUID unique identifiers in batch
Password Generator
Generate secure and reliable random passwords
Base64 Encoder/Decoder
Base64 string encoding and decoding tool
URL Encoder/Decoder
URL string encoding and decoding tool
MD5 Hash Generator
Generate MD5 hash values from text
SHA256 Hash Generator
Generate SHA256 hash values from text
SHA1 Hash Generator
Generate SHA1 hash values from text
Hex Encoder/Decoder
Hexadecimal string encoding and decoding tool
Binary Encoder/Decoder
Binary string encoding and decoding tool
AES Encrypt/Decrypt
AES symmetric encryption algorithm tool
RSA Encrypt/Decrypt
RSA asymmetric encryption algorithm tool
HMAC Generator
HMAC message authentication code generation tool
IP Address Lookup
Query geographical location and network information of IP addresses
Milliseconds Time Converter
Convert between millisecond timestamps and formatted date strings.