Ping is a computer network administration utility used to test the reachability of a host on an Internet Protocol (IP) network. Ping operates by sending Internet Control Message Protocol (ICMP) echo request packets to the target host and waiting for an ICMP response. ICMP protocol is used by ping command to check the connectivity between two computers. By defaults all Linux CentOS servers will response on ICMP request. Hacker can misuse this service. They can generate countless ping requests to your Linux server. This is what called DOS denial of services.
Before changes, i can ping 192.168.1.44 as below :
D:\>ping 192.168.1.44 Pinging 192.168.1.44 with 32 bytes of data: Reply from 192.168.1.44: bytes=32 time=1ms TTL=64 Reply from 192.168.1.44: bytes=32 time=1ms TTL=64 Reply from 192.168.1.44: bytes=32 time=2ms TTL=64 Reply from 192.168.1.44: bytes=32 time=1ms TTL=64 Ping statistics for 192.168.1.44: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 1ms, Maximum = 2ms, Average = 1ms
In this post, i will show on how to block ICMP ping request from others.
Method 1 :
To disable ICMP ping immediately, type the following command :
[root@centos62 ~]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
Method 2 :
To disable ICMP ping after reboot, modify the /etc/sysctl.conf as below. This will permanently disable the ICMP ping echo. Kindly append at the end line of the file :
[root@centos62 ~]# vi /etc/sysctl.conf
.. .. .. # Controls the maximum size of a message, in bytes kernel.msgmnb = 65536 # Controls the default maxmimum size of a mesage queue kernel.msgmax = 65536 # Controls the maximum shared segment size, in bytes kernel.shmmax = 4294967295 # Controls the maximum number of shared memory segments, in pages kernel.shmall = 268435456 net.ipv4.icmp_echo_ignore_all = 1
Change will take effect after reboot :
[root@centos62 ~]# reboot
Try to ping again. The server will not reply now :
D:\>ping 192.168.1.44 Pinging 192.168.1.44 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 192.168.1.44: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),