I am practicing with iptables and... I need a rule that will block a certain host from pinging me but will let me to ping the host if needed (so I need to accept ping responses right?). Can you help me?

  • Some context, please. What is your current iptables ruleset (the output of iptables-save) ? Dec 5 '10 at 0:00

You can block ping (icmp echo requests) from all hosts using this

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

If you want to block a particular host then

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

Allow single ip using

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

Now drop ICMP packets from rest

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

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


If we start with everything blocked: Allow OUTPUT ICMP (to host only if you like) allow established ICMP connections INPUT (from host only if you like)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.