-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathiptables-remove
More file actions
executable file
·78 lines (65 loc) · 1.43 KB
/
iptables-remove
File metadata and controls
executable file
·78 lines (65 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Easy-IPtables
################
#
# This script is part of Easy-Iptables Suite
# It allows you to add or delete certain rules on iptables input chain
#
# Version: 0.1
# Author: Pol Jane pol@zyrcle.com
#
# Usage: iptables-add <rule_num>
#
# iptables-remove -n <num> -c <chain>
#
# Here our default values :)
CHAIN=INPUT
IPT_BIN="/sbin/iptables"
rule_number=
source=0.0.0.0
destination=
function usage() {
echo -e "[ iptables-remove usage: iptables-remove -n <num> -c <chain> ]"
echo -e "\t\t-n <num> Specify a rule number"
echo -e "\t\t-c <chain> Define chain where to add the rule"
echo -e "\t\t-h | --help Show this help"
}
if [[ ( $# -lt 1 ) || ( $# -eq "0" ) ]]; then
usage
fi
function check_if_ipt() {
if [[ ( ! -f $IPT_BIN ) || ( ! -x $IPT_BIN ) ]]; then
echo "ERROR: iptables Not Found"
exit 4
fi
}
check_if_ipt
# A string with command options
options=$@
# An array with all the arguments
arguments=($options)
# Loop index
index=0
for argument in $options
do
# Incrementing index
index=`expr $index + 1`
# The conditions
case $argument in
-n)
rule_number=${arguments[index]}
;;
-c)
CHAIN=${arguments[index]}
;;
-h|--help)
port=${arguments[index]}
;;
esac
done
if [ -z $port ]; then
iptables -D $CHAIN $rule_number
else
iptables -D $CHAIN $rule_number
fi
exit;