Emm*_*-Ab 3 ubuntu iptables ipset
所以我有以下脚本来阻止 IP:
#!/bin/bash
# here's your list of IPS
CURRENT_BL=/path/to/my/ip_black_list.txt
# create/flush recreate the tables
iptables -F BLACKHOLE
iptables -N BLACKHOLE
for BAD_IP in $(cat $CURRENT_BL)
do
ipset add ipset-blacklist $BAD_IP 2>/dev/null || \
echo "Failed to add ${BAD_IP}"
done
# REJECT the matching target
iptables -A BLACKHOLE -p all -m set --match-set ipset-blacklist src -j REJECT
iptables -A BLACKHOLE -j RETURN
# assume your nginx is on 80 and 443
iptables -A INPUT -p tcp -m multiport --destination-ports 80,443 -j BLACKHOLE
iptables -A INPUT -p tcp -m multiport --destination-ports 80,443 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)
ipset 是使用以下命令创建的:
ipset create ipset-blacklist hash:ip
现在 IPv4 一切正常,但问题出在 IPv6 上,我收到以下错误 -Syntax error: cannot parse 2003:e6:6f03:7b80:21dc:54c8:ac26:552b: resolving to IPv4 address failed
我怎样才能让这个脚本读取两种类型的IP?
您需要使用以下命令创建 ipset:
$ sudo ipset create ipset-blacklist hash:ip family inet6
Run Code Online (Sandbox Code Playgroud)
该选项family { inet | inet6 }
定义要存储在集合中的 IP 地址的协议族。默认情况下它是inet
(IPv4)。欲了解更多信息,您可以查看man ipset
。
另外,您需要使用ip6tables
而不是iptables
. 否则,你会得到类似的错误(我用系列inet6创建了一个test6 ipset)
iptables v1.6.0:set test6的协议族是IPv6,不适用。
归档时间: |
|
查看次数: |
7265 次 |
最近记录: |