TLDRBins TLDRBins / Firewall (Linux)


Usage Tips:

  • Click on a keyword to enable inline editing.
  • Click inside a code block to copy (excludes comments).
  • Use the button to view examples.
  • Click outside to collapse all examples.

Check Firewall Rules

# Show all rules sudo iptables -L -v -n --line-numbers
Sample Output: TO-DO
# Show target chain sudo iptables -L <CHAIN> -v -n --line-numbers
Sample Output: sudo iptables -L INPUT -v -n --line-numbers

Set Firewall Rules

# Default policy sudo iptables -P <CHAIN> <RULE>
Sample Output: sudo iptables -P INPUT DROP
sudo iptables -A <CHAIN> -p <PROTOCOL> -s <SOURCE> --dport <PORT> -j <RULE>
Sample Output: # Allow SSH from a specific subnet sudo iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 22 -j ACCEPT

Delete a Firewall Rule

sudo iptables -D <CHAIN> <LINE_NUMBER>
Sample Output: TO-DO
sudo iptables -D INPUT 1
Sample Output: TO-DO