How do I set up a Firewall with Iptables on Debian?

Iptables is a powerful firewall utility for Linux systems. It is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. In this tutorial, we will show you how to set up a firewall with Iptables on a Debian system.

Install Iptables

The first step is to install Iptables on your Debian system. To do this, open a terminal window and run the following command:

sudo apt-get install iptables

This will install Iptables on your system. Once the installation is complete, you can move on to the next step.

Configure Iptables

Now that Iptables is installed, you can configure it to set up your firewall. To do this, you will need to edit the Iptables configuration file. This file is located at /etc/iptables/rules.v4. Open this file in a text editor and add the rules you want to use for your firewall. For example, to allow all incoming SSH connections, you would add the following rule:

-A INPUT -p tcp --dport 22 -j ACCEPT

Once you have added the rules you want to use, you can move on to the next step.

Save the Configuration

Once you have configured Iptables, you need to save the configuration. To do this, run the following command:

sudo iptables-save > /etc/iptables/rules.v4

This will save the configuration to the Iptables configuration file.

Activate the Firewall

Now that the configuration is saved, you can activate the firewall. To do this, run the following command:

sudo iptables-restore < /etc/iptables/rules.v4

This will activate the firewall and apply the rules you have configured.

Test the Firewall

Once the firewall is activated, you can test it to make sure it is working properly. To do this, you can use a tool such as Nmap to scan your system and see if the firewall is blocking the ports you have configured it to block. If the firewall is working properly, the ports you have configured it to block should be blocked.

Useful Links