Created
June 14, 2014 14:31
-
-
Save vasnake/de19b6162ed97b0fd92b to your computer and use it in GitHub Desktop.
Reset (disable) firewall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# disable_fw.sh - Reset (disable) firewall | |
# --------------------------------------------------------------------------------------------------------------- | |
# Initially Written by Vivek Gite <vivek@nixcraft.com> | |
# Rewrited by Valentin Fedulov <vasnake@gmail.com> | |
# Source: http://www.cyberciti.biz/faq/turn-on-turn-off-firewall-in-linux/ | |
# --------------------------------------------------------------------------------------------------------------- | |
# You can copy / paste / redistribute this script under GPL version 2.0 or above | |
# ============================================================= | |
# set to true if it is CentOS / RHEL / Fedora box | |
RHEL=false | |
### no need to edit below ### | |
IPT=/sbin/iptables | |
IPT6=/sbin/ip6tables | |
main() { | |
if [ "$RHEL" == "true" ]; | |
then | |
# reset firewall using redhat script | |
/etc/init.d/iptables stop | |
/etc/init.d/ip6tables stop | |
else | |
# for all other Linux distro use following rules to reset firewall | |
reset_iptables ${IPT} "/proc/net/ip_tables_names" | |
reset_iptables ${IPT6} "/proc/net/ip6_tables_names" | |
fi | |
} | |
reset_iptables() { | |
local ipt_bin="${1}" | |
local tables="${2}" | |
$ipt_bin -P INPUT ACCEPT | |
$ipt_bin -P OUTPUT ACCEPT | |
$ipt_bin -P FORWARD ACCEPT | |
$ipt_bin -F | |
$ipt_bin -X | |
$ipt_bin -Z | |
for table in $(<$tables) | |
do | |
$ipt_bin -t $table -F | |
$ipt_bin -t $table -X | |
$ipt_bin -t $table -Z | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment