如何阻止所有不在 ipset 列表中的 ip

Shu*_*ath 3 firewall ip iptables centos

我正在尝试阻止除美国和加拿大之外的所有流量。当我尝试此命令时,我将所有美国和加拿大 IP 添加到 ipset geoblock 中。我收到错误。

iptables -A INPUT -m set --set !geoblock src -j DROP
-bash: !geoblock: event not found
Run Code Online (Sandbox Code Playgroud)

但是当我运行这个命令时

ipset list
Run Code Online (Sandbox Code Playgroud)

我获取了所有 IP,因此名称和 ipset 没有任何问题。我在 Cent 操作系统 7.3.1611 上使用 iptables v1.4.21

Jav*_*Dev 6

解决方案:

以下是正确的命令行:

iptables -A INPUT -m set ! --match-set geoblock src -j DROP

解释:

javier@equipo-javier:~$ sudo ipset create geoblock hash:net
javier@equipo-javier:~$ sudo iptables -A INPUT -m set --set '!geoblock' src -j DROP
--set option deprecated, please use --match-set
iptables v1.4.21: Set !geoblock doesn't exist.

Try `iptables -h' or 'iptables --help' for more information.
Run Code Online (Sandbox Code Playgroud)

第一次更正:

javier@equipo-javier:~$ sudo iptables -A INPUT -m set --match-set '!geoblock' src -j DROP
iptables v1.4.21: Set !geoblock doesn't exist.

Try `iptables -h' or 'iptables --help' for more information.
Run Code Online (Sandbox Code Playgroud)

第二次更正:

javier@equipo-javier:~$ sudo iptables -A INPUT -m set ! --match-set geoblock src -j DROP
javier@equipo-javier:~$ sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -m set ! --match-set geoblock src -j DROP
Run Code Online (Sandbox Code Playgroud)

现在有效