A lightweight and interactive script to manage firewall rules using iptables.
This tool allows you to block, unblock, and list rules for incoming traffic with ease. Designed for simplicity and extensibility, this script is perfect for beginners and professionals looking to automate their firewall management.
- Add Firewall Rules: Block incoming traffic from specific IP addresses.
- Remove Firewall Rules: Unblock previously blocked IP addresses.
- View Current Rules: List all active rules with detailed information.
- Search Rules: Check if an IP is already blocked in the firewall.
- Apply Scheduled Rules: Automatically apply firewall rules from a file (e.g., scheduled rules).
- Interactive Menu: Simple and intuitive menu-driven interface.
- Logging: Tracks actions (e.g., rule additions/removals) with timestamps in a log file.
Before using this script, ensure the following:
-
System Requirements:
- Linux-based operating system.
iptablesinstalled and configured.
-
Permissions:
- The script must be executed with root or
sudoprivileges to modify firewall rules.
- The script must be executed with root or
-
Dependencies:
bash: The script is written in Bash and requires a compatible shell.
-
Clone the repository:
git clone [https://github.com/LeaDoublet/MiniFirewallAutomation.git](https://github.com/LeaDoublet/MiniFirewall.git) cd MiniFirewallAutomation -
Make the script executable:
chmod +x MiniFirewallAutomation.sh
-
Run the script with
sudo:sudo ./MiniFirewallAutomation.sh
-
Follow the interactive menu to manage your firewall:
- Option 1: Add a rule to block an IP address.
- Option 2: Remove a rule to unblock an IP address.
- Option 3: View all active rules.
- Option 4: Search for an IP to check if it is blocked.
- Option 5: Apply scheduled rules from a file.
- Option 6: Exit the script.
-
Blocking an IP:
Enter the IP to block: 192.168.1.100 Rule added: Blocked IP 192.168.1.100.
-
Listing Rules:
Chain INPUT (policy ACCEPT) num target prot opt source destination 1 DROP all -- 192.168.1.100 0.0.0.0/0 -
Unblocking an IP:
Enter the IP to unblock: 192.168.1.100 Rule removed: Unblocked IP 192.168.1.100.
-
Searching for a Blocked IP:
Enter the IP to search: 192.168.1.100 IP 192.168.1.100 is currently blocked.
-
Applying Scheduled Rules:
Applying scheduled rules from /etc/iptables/scheduled_rules.txt Rule added: Blocked IP 192.168.1.101.
The script maintains a log file firewall.log in the same directory. It records:
- Timestamp of actions.
- Details of blocked/unblocked IPs.
Example log entry:
2025-01-05 10:30:45: Blocked IP 192.168.1.100
2025-01-05 10:45:12: Unblocked IP 192.168.1.100
Scheduled Rules : To apply scheduled rules, create a file like /etc/iptables/scheduled_rules.txt with the following format:
ADD,192.168.1.101
REMOVE,192.168.1.100
The script will process these rules and apply them accordingly.