更新 防火墙.MD
This commit is contained in:
@@ -6,4 +6,24 @@
|
|||||||
~~~
|
~~~
|
||||||
apt update
|
apt update
|
||||||
apt install ipset curl -y
|
apt install ipset curl -y
|
||||||
|
~~~
|
||||||
|
2. 创建 ipset 集合存储中国大陆 IP 段, 创建集合,hash:net 存放网段
|
||||||
|
~~~
|
||||||
|
ipset create cn_ip hash:net family inet hashsize 1024 maxelem 65536
|
||||||
|
~~~
|
||||||
|
3. 获取中国大陆 IP 网段并导入 ipset
|
||||||
|
~~~
|
||||||
|
##### 清空旧集合
|
||||||
|
ipset flush cn_ip
|
||||||
|
#### 下载cn网段列表写入ipset
|
||||||
|
curl -s https://ftp.apnic.net/stats/apnic/delegated-apnic-latest | awk -F'|' '$2=="CN"&&$3=="ipv4"{printf("add cn_ip %s/%d\n",$4,32-log($5)/log(2))}' | ipset restore
|
||||||
|
~~~
|
||||||
|
⚠️网络不好时 curl 会失败,可以把文件下载到本地再导入。
|
||||||
|
4. iptables 规则:拒绝 cn_ip 集合访问本机 40000‑50000 TCP/UDP
|
||||||
|
~~~
|
||||||
|
#### TCP
|
||||||
|
iptables -A INPUT -m set --match-set cn_ip src -p tcp --dport 40000:50000 -j DROP
|
||||||
|
##### UDP
|
||||||
|
iptables -A INPUT -m set --match-set cn_ip src -p udp --dport 40000:50000 -j DROP
|
||||||
|
|
||||||
~~~
|
~~~
|
||||||
Reference in New Issue
Block a user