Pejman Moghadam / Scripts

iptables modules unloader

Public domain


#!/bin/bash

remove_module()
{
  local LSMOD=$(lsmod | egrep "^$1 ")
  local DEPS=$(echo $LSMOD | awk '{print$4}')
  if [ "$DEPS" == "" ]; then
    /sbin/rmmod $1
  else
    local I=1
    local DEPMOD=$(echo $DEPS | awk -v I="$I" -F "," '{print$I}')
    while [ "$DEPMOD" != "" ]; do
      remove_module $DEPMOD
      I=$(expr $I + 1 )
      DEPMOD=$(echo $DEPS | awk -v I="$I" -F "," '{print$I}')
    done
    /sbin/rmmod $1
  fi
}

/usr/sbin/iptables -P INPUT ACCEPT
/usr/sbin/iptables -P OUTPUT ACCEPT
/usr/sbin/iptables -P FORWARD ACCEPT
/usr/sbin/iptables -t filter -F
/usr/sbin/iptables -t nat -F
/usr/sbin/iptables -t mangle -F
/usr/sbin/iptables -t filter -X
/usr/sbin/iptables -t nat -X
/usr/sbin/iptables -t mangle -X

remove_module x_tables
remove_module ip_tables
remove_module ebtables
remove_module nfnetlink
remove_module nf_conntrack
remove_module ts_kmp
remove_module ip_gre

BY: Pejman Moghadam
TAG: iptables, rmmod, bash-script, bash
DATE: 2009-04-25 16:19:58


Pejman Moghadam / Scripts [ TXT ]