-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathiptables-block-gosnet.sh
executable file
·67 lines (54 loc) · 1.35 KB
/
iptables-block-gosnet.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
#!/usr/bin/env sh
LOC="$(dirname ${0})"
. "${LOC}"/common.sh
start() {
# Creating a chain
iptables -t raw -N BLOCKGOSNET
iptables -t raw -A BLOCKGOSNET -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Whitelist for IPv4
getwhitelist_v4 | while read net; do
iptables -t raw -A BLOCKGOSNET -s "${net}" -m comment --comment "Госорганы (WL)" -j RETURN
done
# Blacklist for IPv4
getblacklist_v4 | while read net; do
iptables -t raw -A BLOCKGOSNET -s "${net}" -m comment --comment "Госорганы (BL)" -j DROP
done
# Whitelist for IPv6
getwhitelist_v6 | while read net; do
ip6tables -t raw -A BLOCKGOSNET -s "${net}" -m comment --comment "Госорганы (WL)" -j RETURN
done
# Blacklist for IPv6
getblacklist_v6 | while read net; do
ip6tables -t raw -A BLOCKGOSNET -s "${net}" -m comment --comment "Госорганы (BL)" -j DROP
done
# Enabling
iptables -t raw -I PREROUTING -j BLOCKGOSNET
}
stop() {
# Disabling
iptables -t raw -D PREROUTING -j BLOCKGOSNET
# Cleaning the chain
iptables -t raw -F BLOCKGOSNET
# Removing the chain
iptables -t raw -X BLOCKGOSNET
}
case "${1}" in
start)
start;
;;
stop)
stop;
;;
restart)
stop &&
start || (
echo "Failed to stop while restarting";
exit 1
)
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
;;
esac
exit 0