我试图添加一个iptables规则,以便丢弃除特定IP以外的任何传入数据包。 按照手册,我尝试运行这个:
> iptables -t filter -I INPUT -s !12.34.56.78 -p tcp -j DROP
但我得到这个错误:
iptables v1.4.12.1: host/network `!12.34.56.78' not found
manpages表示为-s / --src / --source参数... A "!" argument before the address specification inverts the sense of the address. ... ... A "!" argument before the address specification inverts the sense of the address. ... ... A "!" argument before the address specification inverts the sense of the address. ...
我带着这个惊叹号的第一个问题是shell将它扩展为历史命令。 解决schemeset +H被应用,似乎它不再是一个问题。
为什么感叹号不被接受,以指定一个反转的地址为手册说?
PS:当然,我试图用它之间的空间! 和IP,它不被接受。
编辑
在接受答案之前,也许任何人也可以帮助回答:为什么参数的顺序应该是! -s {IP} ! -s {IP}而不是-s !{IP}如手册所述? 只是更新版本的iptables改变了这个语法,同时保留旧的手册页? 或者是以某种方式configuration?
你将需要一个空间! 和IP地址
iptables -t filter -I INPUT -s ! 12.34.56.78 -p tcp -j DROP
如果您收到消息,如Using intrapositioned negation (select!这) is deprecated in favor of extrapositioned ( ! – select这个).
然后放置! 在“-s”选项之前 –
iptables -t filter -I INPUT ! -s 12.34.56.78 -p tcp -j DROP
你试试逃脱了! 从你的shell?
iptables -A INPUT \! -s 12.34.56.78 -p tcp -j DROP
编辑:我的道歉,我看你已经占了逃避!,所以你只是有错误的订单。 我上面粘贴的命令在我的机器上正常工作,应该为你做。