Advertisement
Guest User

firewall_panic.sh

a guest
Jan 29th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.36 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # esta ip es la de la terminal del sysadmin
  4. ssh_src="192.168.1.145"
  5. ssh_sport="0:65535"
  6. ssh_dport="0:65535"
  7.  
  8. case "${1}" in
  9.         on)
  10.                 echo -n $"Firewall: Modo Panic - bloqueo de todas las comunicaciones:"
  11.  
  12.                 modprobe ip_tables
  13.  
  14.                 tables=`cat /proc/net/ip_tables_names`
  15.                 for t in ${tables}
  16.                 do
  17.                         iptables -t "${t}" -F
  18.                         iptables -t "${t}" -X
  19.                         iptables -t "${t}" -Z
  20.  
  21.                         # Find all default chains in this table.
  22.                         chains=`iptables -t "${t}" -nL | grep "^Chain " | cut -d ' ' -f 2`
  23.                         for c in ${chains}
  24.                         do
  25.                                 iptables -t "${t}" -P "${c}" ACCEPT
  26.  
  27.                                 if [ ! -z "${ssh_src}" ]
  28.                                 then
  29.                                         iptables -t "${t}" -A "${c}" -p tcp -s "${ssh_src}" --sport "${ssh_sport}" --dport "${ssh_dport}" -m state --state ESTABLISHED -j ACCEPT
  30.                                         iptables -t "${t}" -A "${c}" -p tcp -d "${ssh_src}" --dport "${ssh_sport}" --sport "${ssh_dport}" -m state --state ESTABLISHED -j ACCEPT
  31.                                 fi
  32.                                 iptables -t "${t}" -A "${c}" -j DROP
  33.  
  34.                         done
  35.                 done
  36.  
  37.                 echo "Firewall: bloqueo todas las comunicaciones:"
  38.                 echo
  39.  
  40.                 exit 0
  41.         ;;
  42.  
  43.         off)
  44.                 echo -n $"Firewall: Limpieza de todas las reglas:"
  45.                 modprobe ip_tables
  46.                 tables=`cat /proc/net/ip_tables_names`
  47.                 for t in ${tables}
  48.                 do
  49.                         iptables -t "${t}" -F
  50.                         iptables -t "${t}" -X
  51.                         iptables -t "${t}" -Z
  52.  
  53.                         chains=`iptables -t "${t}" -nL | grep "^Chain " | cut -d ' ' -f 2`
  54.                         for c in ${chains}
  55.                         do
  56.                                 iptables -t "${t}" -P "${c}" ACCEPT
  57.                         done
  58.                 done
  59.                 echo -n $"Firewall: firewall OK:"
  60.                 echo
  61.  
  62.                 exit 0
  63.         ;;
  64.  
  65.         *)
  66.                 echo "on|off"
  67.         ;;
  68. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement