0 Replies - 1234 Views - Last Post: 19 August 2008 - 03:59 PM

#1 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Simple firewall script

Posted 19 August 2008 - 03:59 PM

Description: The only requirements are Bash and iptables.

To enable the firewall, do 'sh firewall.sh --enable'.

To disable it, do 'sh firewall.sh --disable'.This is a simple script that enables/disables an iptables firewall.

When the firewall is enabled all packets except for those belonging to normal requests will be dropped.

This script must be run as root.
#!/bin/sh
#--------------------------------------------------------------
# Filename:      firewall.sh
# Description:  A script to enable/disable an iptables
#                      firewall that will block all incoming
#                      packets (except requests).
# Author:         Tom Arnold
#--------------------------------------------------------------

case $1 in
    --enable )
	echo "Enabling firewall..."
	iptables -F
	iptables -A INPUT -i lo -j ACCEPT
	iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
	iptables -A INPUT -j DROP
	;;

    --disable )
	echo "Disabling firewall..."
	iptables -F
	;;
    
    * )
	echo "Usage: sh firewall.sh [ACTION]"
	echo
	echo "t--enabletenable the firewall"
	echo "t--disabletdisable the firewall"
	echo
	echo "Report bugs to <[email protected]>."
	;;
esac


Is This A Good Question/Topic? 0
  • +

Page 1 of 1