如何使用 iptables 阻止 IP

4 firewall iptables

所以这应该是一个简单的问题,但无论出于何种原因我都想不通。

这是我目前的规则:

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
Run Code Online (Sandbox Code Playgroud)

我试图阻止“hit-nxdomain.opendns.com”位置(虚拟位置)。当我输入一个真实的 IP 地址时,我可以从另一个位置使用。如果我尝试从该位置访问我的服务器,它仍然可以正常连接。如何让它删除来自该 IP 地址的所有请求?

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

EEA*_*EAA 7

获取该主机名的 IP:

$ host hit-nxdomain.opendns.com
hit-nxdomain.opendns.com has address 67.215.65.132
Run Code Online (Sandbox Code Playgroud)

阻止它:

$ iptables -I INPUT -s 67.215.65.132 -j DROP
Run Code Online (Sandbox Code Playgroud)