-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiptables.sh
executable file
·125 lines (118 loc) · 2.77 KB
/
iptables.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
selection=0
port=0
ip=0
function input {
echo ""
echo "1) DROP all incoming traffic"
echo "2) Allow port"
echo "3) Allow port via ip or subnet"
echo "4) Drop port"
echo -n "Please Select by pressing (1-4) : "
read -r selection
case $selection in
1)
iptables -A INPUT -j DROP
echo "All incoming traffic blocked"
;;
2)
echo -n "Enter port number to Allow traffic : "
read -r port
iptables -I INPUT 1 -p tcp --dport $port -j ACCEPT
;;
3)
echo -n "Enter port number to Allow traffic->"
read -r port
echo -n "Standalone IP address Or with subnet (ex. 192.168.10.34) Input ->"
read -r ip
iptables -I INPUT 1 -p tcp --dport $port -s $ip -j ACCEPT
;;
4)
echo -n "Enter port number to Deny traffic->"
read -r port
iptables -I INPUT 1 -p tcp --dport $port -j DROP
;;
*)
echo "Select Correct Option, Please try again !"
;;
esac
}
function output {
echo ""
echo "1) DROP all outgoing traffic"
echo "2) Allow port"
echo "3) Allow port via ip or subnet"
echo "4) Drop port"
echo -n "Please Select by pressing (1-4) : "
read -r selection
case $selection in
1)
iptables -A OUTPUT -j DROP
echo "All incoming traffic blocked"
;;
2)
echo -n "Enter port number to Allow traffic : "
read -r port
iptables -I OUTPUT 1 -p tcp --sport $port -j ACCEPT
;;
3)
echo -n "Enter port number to Allow traffic->"
read -r port
echo -n "Standalone IP address Or with subnet (ex. 192.168.10.34) Input ->"
read -r ip
iptables -I OUTPUT 1 -p tcp --sport $port -s $ip -j ACCEPT
;;
4)
echo -n "Enter port number to Deny traffic->"
read -r port
iptables -I OUTPUT 1 -p tcp --sport $port -j DROP
;;
*)
echo "Select Correct Option, Please try again !"
;;
esac
}
function menu {
clear
while [ $selection!=5 ]
do
echo ""
echo "1) Incoming Traffic"
echo "2) Outgoing Traffic"
echo "3) Forword"
echo "4) Flush"
echo "5) iptable -L"
echo "6) exit"
echo -n "Please Select by pressing (1-6) ->" && read -r selection
clear
case $selection in
1)
input
;;
2)
output
;;
3)
echo "working on it"
;;
4)
iptables -F
echo "Previous Configuration of IPtables have been flushed !"
;;
5)
iptables -L
;;
6)
exit 0
;;
*)
echo "Select Correct Option, Please try again !"
;;
esac
done
}
echo "|| IPtable Configure Script ||"
iptables -F
echo "Previous Configuration of IPtables have been flushed !"
clear
menu