https://github.com/17mon/china_ip_list/blob/master/china_ip_list.txt
写个 bash 脚本让 iptables 只允许上面的中国 ip 访问就行
#!/bin/bash
# 清空所有规则
iptables -F
# 允许本地回环接口的通信
iptables -A INPUT -i lo -j ACCEPT
# 允许已建立的连接和相关连接
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# 获取中国的 IP 段列表(这需要您事先准备好)
CHINA_IP_RANGES=(
"1.0.1.0/24"
"2.0.0.0/16"
# ..... 添加更多的中国 IP 段
)
# 对于每个中国的 IP 段,添加允许规则
for ip_range in "${CHINA_IP_RANGES[@]}"
do
iptables -A INPUT -s $ip_range -j ACCEPT
done
# 拒绝其他所有的输入连接
iptables -A INPUT -j DROP