As you probably know, ping is a tool that lets you ckeck the reachability of another host, in other words it lets you verify that a particular IP address exists and can accept requests.
ping sends ICMP (Internet Control Message Protocol) messages encapsulated into IP packets to check the reachability of a given host. The basic mechanism is simple, ping sends an ICMP echo request message (type 0) and waits for an ICMP echo reply message (type
by the receiving host. If the destination host is unreachable you’ll get back something like this:
From hostX (192.168.X.Y) icmp_seq=1 Destination Host Unreachable
… or nothing at all if the host rejects pings.
In some occasions, for security reasons (i.e to avoid some kinds of DoS attacks) it’s recommended to disable replies to pings. To prevent your GNU/Linux hosts from replying to pings simply type the following:
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
… and if you want to ignore pings to broadcast…
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
Or this other to enable replies to pings:
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
Bear in mind that these parametes must be set after each reboot. To have this permanently in your machine add the following to /etc/sysctl.conf:
icmp.echo.ignore.all = 1
icmp.echo.ignore.broadcasts = 1
References: