Skip to content

Instantly share code, notes, and snippets.

@qzydustin
Last active September 1, 2023 05:10
Show Gist options
  • Save qzydustin/49b5d30779240c18af472a9e7399b793 to your computer and use it in GitHub Desktop.
Save qzydustin/49b5d30779240c18af472a9e7399b793 to your computer and use it in GitHub Desktop.
Reset Firewall Rules
#!/bin/bash
# This script resets the firewall rules, installs iptables-persistent, and saves the rules to files.
# Set the default policies to accept all traffic
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Flush all existing rules and chains
iptables -F
# Install iptables-persistent package to save and restore firewall rules on system reboot
apt install iptables-persistent -y
# Save the current IPv4 and IPv6 rules to files
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
# Display the current firewall rules
iptables -nvL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment