Easy Debian Server Firewall

Note: the method below will no longer work with Debian Jessie. The updated method can be found at Easy Debian 8 Server Firewall.

I like to call the method below “The Easy Debian Server Firewall”. You may ask why I call it easy. The answer is simple, it uses standard IPTable’s and has a start and stop script to quickly disable it in the event that debugging is required. Installing the firewall is a simple two stage process. First adjust the file below called firewall.rules to your liking.  This file will be placed at /etc/firewall.rules.

Next we will need to build the init script called firewall to start, stop and restart the firewall. This file will be placed at /etc/init.d/firewall. You will need to make this file executable by running the following command: sudo chmod 0755 /etc/init.d/firewall. Once the file is executable, we will need to employ the update-rc.d tool in order to make the firewall script start on boot with the following command: update-rc.d firewall start 20 2 3 4 5 . stop 99 0 1 6 .

Lastly, we will want to test our new firewall setup. First we must flush any existing IPtables and then list the rules to ensure all are removed with the following command: sudo iptables -F && sudo iptables -L. Your output should look similar to the picture below.iptables-f
Once you have verified that no rules are enabled, you can start your firewall with the following command: sudo service firewall start. Now run: sudo iptables -L and should see the rules that you have enabled in your firewall.rules file.

ubuntu Debian Firewall Download

Did you find this article useful? Why not share it with your friends?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.