Allow/deny,disable or drop/block ping request
Ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network, and to measure the round-trip time for messages sent from the originating host to a destination computer and echoed back to the source. 

The name comes from active sonar terminology that sends a pulse of sound and listens for the echo to detect objects under water,although it is sometimes interpreted as a backronym to packet Internet groper
Blocking PING on server is helpful sometimes, if the server is continue to face any type of DDoS attack by using the PING feature. By using iptables we can simply stop the PING option.
STEP : 1
You can setup kernel variable to drop all ping packets. Type the following command at shell prompt:
This instructs the kernel to simply ignore all ping requests.
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
To enable ping request type the command:
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
You can add following line to /etc/sysctl.conf file:
# vi /etc/sysctl.conf 
Append following line:
net.ipv4.icmp_echo_ignore_all = 1
Save and close the file.
STEP : 2
Also we can manage it by the help of 'iptables'. The 'ping' is using ICMP to communicate. We can simply manage the 'icmp : Internet Controlled Message Protocol'from iptables.
The below pasted switches are required for creating a rule for managing icmp.
-A : Add a rule
-D : Delete rule from table
-p : To specify protocol (here 'icmp')
--icmp-type : For specifying type
-J : Jump to target
Normally using icmp types and its Codes Click here for ICMP Types and Codes
echo-request   :  8
echo-reply     :  0
How to block PING to your server with an error message?
In this way you can partially block the PING with an error message 'Destination Port Unreachable'. Add the following iptables rules to block the PING with an error message. (Use REJECT as Jump to target)
iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT
Result : - 
[root@redhat ~]# ping
Pinging [] with 32 bytes of data:
From icmp_seq=1 Destination Port Unreachable
From icmp_seq=2 Destination Port Unreachable
From icmp_seq=3 Destination Port Unreachable
To block without any messages use DROP as Jump to target.
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j DROP
Allow Ping from Outside to Inside
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
How to block PING from your server?
In this way you can block PING option from your server to outside. Add these rules to your iptables to do the same.

Block PING operation with message 'Operation not permitted'
iptables -A OUTPUT -p icmp --icmp-type echo-request -j DROP
root@test [~]# ping
PING ( 56(84) bytes of data.
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
ping: sendmsg: Operation not permitted
To block with out any error messages
For this, DROP the echo-reply to the INPUT chain of your iptables.
iptables -A OUTPUT -p icmp --icmp-type echo-request -j DROP
iptables -A INPUT -p icmp --icmp-type echo-reply -j DROP
Allow Ping from Inside to Outside
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
You can use the icmp code instead of icmp-type name for adding rule to iptables.

About Author:

I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Newer Post
Older Post


Post a Comment