Setting Up a Basic Firewall on Debian Using IPTABLES
Setting up a basic firewall using IPTABLES(Debian)
Evans
Last Update منذ عام واحد
iptables is a powerful command-line tool used to configure Linux kernel firewall rules. It offers packet filtering, network address translation (NAT), and traffic mangling capabilities. This guide walks you through setting up a basic but functional firewall on Debian.
A Debian-based server (Debian 10/11/12)
Root or sudo access
iptables installed (usually included by default)
Optional: iptables-persistent for saving rules across reboots
Check currently active rules:
Create a Basic IPTABLES Rules File
Let’s configure a simple firewall by creating a rules file:
Paste in the following configuration:
Load your rules using:
Verify the rules:
You should now see only the allowed ports (80, 443, 22, etc.) open.
Make IPTABLES Rules Persistent (Survive Reboot)
Since iptables rules are not persistent by default, you must save and reload them at boot:
Save the rules:
Create a pre-up script:
Add:
3. Make it executable:
1. Install the package:
Save current rules:
3. Restart the firewall:
Consider UFW or nftables for simpler management on newer Debian systems.
Regularly audit your firewall using:
Debian 10+ supports nftables, the successor to iptables. For new systems, consider migrating.
If using IPv6, replicate rules using ip6tables.
