Skip to content

Commit 1147875

Browse files
committed
.
1 parent 40a0dcc commit 1147875

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

deny-except-jp.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# 日本のIPレンジを取得して許可
4+
wget http://nami.jp/ipv4bycc/cidr.txt.gz
5+
zcat cidr.txt.gz | grep ^JP > jp_cidr.txt
6+
cat jp_cidr.txt | awk {'print "ufw allow from "$2" to any"'} > set_allow_jp.sh
7+
sudo bash set_allow_jp.sh
8+
9+
# CloudflareのIPv4アドレスを許可
10+
curl https://www.cloudflare.com/ips-v4 -o cloudflare_ips_v4.txt
11+
cat cloudflare_ips_v4.txt | awk {'print "ufw allow from "$1" to any"'} > set_allow_cloudflare_v4.sh
12+
sudo bash set_allow_cloudflare_v4.sh
13+
14+
# CloudflareのIPv6アドレスを許可
15+
curl https://www.cloudflare.com/ips-v6 -o cloudflare_ips_v6.txt
16+
cat cloudflare_ips_v6.txt | awk {'print "ufw allow from "$1" to any"'} > set_allow_cloudflare_v6.sh
17+
sudo bash set_allow_cloudflare_v6.sh
18+
19+
# その他のIPをブロック
20+
sudo ufw default deny incoming
21+
sudo ufw enable

0 commit comments

Comments
 (0)