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

我试图阻止除美国和加拿大以外的所有stream量。 我添加了所有美国和加拿大的IP到ipset地理块,当我尝试这个命令。 我收到一个错误。

iptables -A INPUT -m set --set !geoblock src -j DROP -bash: !geoblock: event not found 

但是当我运行这个命令

 ipset list 

我得到所有的IP,所以没有任何错误的名称和ipset。 我在7.3.1611上使用iptables v1.4.21

正如Zoredache提到的bash错误表明这是一个引用问题。 把这个论点放在单引号中,或者用反斜线来避开感叹号,将会引起一些直接的问题:

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

要么

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

解:

以下是正确的命令行:

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. 

第一次更正:

 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. 

第二次更正:

 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 

现在工作