-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathiptables-ipset-block-gosnet.sh
executable file
·67 lines (56 loc) · 1.33 KB
/
iptables-ipset-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
#!/usr/bin/env sh
LOC="$(dirname ${0})"
. "${LOC}"/common.sh
iptables_ipset_block_gosnet_start() {
ipset create GOSNET hash:net
ipset create GOSNETWHITELIST hash:net
getwhitelist_v4 |
while read net; do
ipset add GOSNETWHITELIST "$net"
done
getblacklist_v4 |
while read net; do
ipset add GOSNET "$net"
done
getwhitelist_v6 |
while read net; do
ipset add GOSNETWHITELIST "$net"
done
getblacklist_v6 |
while read net; do
ipset add GOSNET "$net"
done
iptables -t filter -N BLOCKGOSNET
iptables -t filter -A BLOCKGOSNET -m set --match-set GOSNETWHITELIST src -j RETURN
iptables -t filter -A BLOCKGOSNET -m set --match-set GOSNET src -j DROP
iptables -t filter -I INPUT -j BLOCKGOSNET
iptables -t filter -I FORWARD -j BLOCKGOSNET
}
iptables_ipset_block_gosnet_stop() {
(
iptables -t filter -D INPUT -j BLOCKGOSNET
iptables -t filter -D FORWARD -j BLOCKGOSNET
iptables -t filter -F BLOCKGOSNET
iptables -t filter -X BLOCKGOSNET
ipset destroy GOSNET
ipset destroy GOSNETWHITELIST
) 2>/dev/null
}
case "$1" in
start)
iptables_ipset_block_gosnet_stop
iptables_ipset_block_gosnet_start
;;
stop)
iptables_ipset_block_gosnet_stop
;;
restart)
iptables_ipset_block_gosnet_stop
iptables_ipset_block_gosnet_start
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
;;
esac
exit 0