如何使用iptables阻止IP

所以这应该是一个简单的问题,但无论如何我无法弄清楚。

这是我目前的规则:

Chain INPUT (policy ACCEPT) target prot opt source destination block all -- anywhere anywhere ACCEPT all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination block all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination block all -- anywhere anywhere ACCEPT all -- anywhere anywhere Chain block (3 references) target prot opt source destination DROP all -- hit-nxdomain.opendns.com anywhere 

我试图阻止“hit-nxdomain.opendns.com”位置(虚拟位置)。 当我把一个真正的IP地址,我可以从另一个位置使用。 如果我尝试从该位置打我的服务器,它仍然连接正常。 我怎样才能得到它从该IP地址的所有请求?

我正在使用链,因为我将使用脚本dynamic修改阻塞的IP地址,因此我需要能够清除链块而不破坏INPUT链并添加新地址。 你能告诉我我现在做错了吗? 正如我所说的,“hit-nxdomain.opendns.com”只是一个虚拟的名字。 但是,如果我有一个有效的IP,它不会阻止它。

获取该主机名的IP:

 $ host hit-nxdomain.opendns.com hit-nxdomain.opendns.com has address 67.215.65.132 

阻止它:

 $ iptables -I INPUT -s 67.215.65.132 -j DROP 

我没有看到规则的问题。 要阻止IP地址,请使用

  # iptables -A INPUT -s 127.0.0.100 -j DROP 

如果你仍然能够从该IP地址进行连接,那么使用tcpdump进行检查,如果实际上使用该IP连接,或者由于某种原因(代理,VPN,…),您可以使用iptables规则在主机上看到作为另一个IP地址。