如何否定iptables中的范围?

use*_*932 18 linux iptables

我见过人们在多个示例中使用感叹号 (!),但是当我尝试使用它时,却出现错误。

我正在尝试的规则:

-A OUTPUT -m owner --gid-owner 1006 -d ! 192.168.1.0/24 -j DROP

错误:

Bad argument '192.168.1.0/24'

什么是正确的语法?

小智 36

正如联机帮助页所述:

[!] -d, --destination address[/mask][,...]
       Destination  specification.   See  the  description  of  the  -s
       (source)  flag  for  a  detailed description of the syntax.  The
       flag --dst is an alias for this option.
Run Code Online (Sandbox Code Playgroud)

这使它

! -d 192.168.1.0/24
Run Code Online (Sandbox Code Playgroud)

  • 它与阴暗的博客无关,iptables 的语法发生了变化,感叹号在某些时候出现在标志之前。 (5认同)