iptables:如何从主机丢弃传入ping,但允许ping响应?

我正在练习iptables和…我需要一个规则,将阻止某些主机ping我,但会让我ping主机,如果需要(所以我需要接受ping响应?)。 你可以帮我吗?

您可以阻止来自所有使用此主机的ping(icmp回应请求)

 iptables -I INPUT -j DROP -p icmp --icmp-type echo-request 

如果你想要阻止一个特定的主机

 iptables -I INPUT -s 192.168.1.139 -j DROP -p icmp --icmp-type echo-request 

允许使用单个IP

iptables -A INPUT -s xxxx -p ICMP -icmp-type 8 -j ACCEPT

现在从rest中删除ICMP数据包

iptables -A INPUT -p ICMP -icmp-type 8 -j DROP

参考http://www.trickylinux.net/ping-single-ip-linux/