/
scriptables.sh
44 lines (34 loc) · 1.02 KB
/
scriptables.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
#!/bin/bash +x
ip=/sbin/iptables
tcpservices="80 8080 443 22 123 3784"
udpservices="3784"
echo -n ">> Applying iptables rules... "
# flush current
$ip -F
$ip -X
$ip -Z
$ip -t nat -F
# default: DROP
$ip -P INPUT DROP
$ip -P OUTPUT DROP
$ip -P FORWARD DROP
# filtering...
# localhost - letmein
$ip -A INPUT -i lo -j ACCEPT
$ip -A OUTPUT -o lo -j ACCEPT
# allowed services
for service in $tcpservices ; do
$ip -A INPUT -p tcp -m tcp --dport $service -j ACCEPT
$ip -A OUTPUT -p tcp -m tcp --sport $service -m state --state RELATED,ESTABLISHED -j ACCEPT
done
for service in $udpservices ; do
$ip -A INPUT -p udp -m udp --dport $service -j ACCEPT
$ip -A OUTPUT -p udp -m udp --sport $service -m state --state RELATED,ESTABLISHED -j ACCEPT
done
$ip -A INPUT -j LOG --log-level 4
# dns...
$ip -A INPUT -p udp -m udp --sport 53 -j ACCEPT
$ip -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT
$ip -A INPUT -p tcp -m tcp --sport 53 -j ACCEPT
$ip -A OUTPUT -p tcp -m tcp --dport 53 -j ACCEPT
echo "OK. Check rules with iptables -L -n"