The Technical Search Engine - Search Everything related to Technology all around the world emphasizing on selected sites. If you have a blog/site related to Technology then contact us to add it to the search and get more hits!


Freedom from labor itself is not new; it once belonged among the most firmly established privileges of the few. In this instance, it seems as though scientific progress and technical developments had been only taken advantage of to achieve something about which all former ages dreamed but which none had been able to realize.
Hannah Arendt

Secure your Linux Box using IPTables Firewall!


Nilesh - Posted on 04 May 2008

Most of the Linux distributions have an inbuilt firewall called iptables. Well, many a times its not configured properly. 

Below is a shell script, just copy and paste it into a file....further steps below the script.

#!/bin/bash

iptables -v -F;
iptables -v -A INPUT -i lo -j ACCEPT;
iptables -v -A INPUT -i eth0 -j ACCEPT;
iptables -v -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT;
iptables -v -A INPUT -m state -m tcp --proto tcp --dport 80 --state NEW -j ACCEPT;
iptables -v -A INPUT -m state -m udp --proto udp --dport 53 --state NEW -j ACCEPT;
iptables -v -A INPUT -m state -m tcp --proto tcp --dport 53 --state NEW -j ACCEPT;
iptables -v -A INPUT -j REJECT;

iptables -v -A OUTPUT -o lo -j ACCEPT;
iptables -v -A OUTPUT -o eth0 -j ACCEPT;
iptables -v -A OUTPUT -m tcp --proto tcp --dport 80 -j ACCEPT;
iptables -v -A OUTPUT -m tcp --proto tcp --dport 443 -j ACCEPT;
iptables -v -A OUTPUT -m tcp --proto tcp --dport 445 -j ACCEPT;
iptables -v -A OUTPUT -m tcp --proto tcp --dport 53 -j ACCEPT;
iptables -v -A OUTPUT -m udp --proto udp --dport 53 -j ACCEPT;
iptables -v -A OUTPUT -m tcp --proto tcp --dport 5222 -j ACCEPT; #Google Talk or Jabber
iptables -v -A OUTPUT -m tcp --proto tcp --dport 5050 -j ACCEPT; #Yahoo
iptables -v -A OUTPUT -m tcp --proto tcp --dport 6667 -j ACCEPT; #IRC
iptables -v -A OUTPUT -m tcp --proto tcp --dport 7777 -j ACCEPT; #Jabber file Transfers
iptables -v -A OUTPUT -j REJECT;

iptables -v -A FORWARD -j REJECT;

iptables-save > /tmp/iptables;

iptables-restore < /tmp/iptables;

/etc/init.d/iptables save

This shell script has been tested in Fedora (built on which) and Ubuntu (Friend's PC).

After pasting into a file, you need to chmod the file with executable permissions. chmod means changing permissions for a file on a Linux/Unix system.

for assistance on chmod log on to  http://www.december.com/unix/ref/chmod.html

as in this instance it will be chmod 777 <file path>

Then execute the file as root. (to become root in debian or debian based gnu's, "sudo or su" is the command)

You may modify it further as needed.

NOTE: iTech7.com will not be responsible for any damages/losses occurred due to this script.

If you need more help, go to the #iptables channel on irc.freenode.net

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

puneeth@puneeth-desktop:~$ iptables -v -F;
iptables v1.3.8: can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.

Execute the application as root. DO NOT USE SUDO. Use su - (su dash).

Nilesh Govindrajan

Site & Server Administrator
iTech7

Nilesh Govindrajan

Site & Server Administrator
iTech7

what is Chmod the file mean?? give example!!

updated article

Nilesh Govindrajan

Site & Server Administrator
iTech7

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <address><blockquote><h1><h2><h3><h4><h5><h6><hr><p><ol><ul><li><table><caption><tr><th><td><a><cite><em><strong><b><i><u><big><small><img><br><sub><sup><img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

CAPTCHA
This is to verify that you are human visitor
7 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.