Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are several ways for Centos7 to temporarily or permanently disable the ping command?

Shulou Source: shulou.com Published: 2022-06-01 03:07:34 11月12日 Update

Today, I will talk to you about several methods of temporarily or permanently disabling ping commands in Centos7, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.

Some friends may find that when ping the IP of a server, the ping may not work, but it can be accessed normally. What's going on?

In fact, this server is set up with the ping command. If you are using a centos7 system and do not want others to ping, you can also set the disable ping command to achieve this.

Temporarily disable ping

Change the 0 in the / proc/sys/net/ipv4/icmp_echo_ignore_all file to 1 temporarily, so as to realize all requests to prohibit ICMP messages and achieve the effect of prohibiting Ping.

In this way, other hosts in the network will display a "request timeout" error when Ping the host, but the server can Ping other hosts at this time.

Permanently disable ping

# Editing configuration

Vim / etc/sysctl.conf

# set the ban on ping (if there is no need to add it repeatedly)

Net.ipv4.icmp_echo_ignore_all = 1

# refresh configuration

Sysctl-p

# enable ping

Net.ipv4.icmp_echo_ignore_all = 0

IPTABLES Firewall forbids ping

Classics ping

Iptables-An INPUT-p icmp--icmp-type 8-s 0 DROP 0-j DROP

Enable ping

Iptables-D INPUT-p icmp--icmp-type 8-s 0 DROP 0-j DROP

# Parameter remarks

-A: add firewall rules

INPUT: inbound rule

-p icmp: specifies that the protocol for packet inspection is ICMP protocol

-- icmp-type 8: specifies that the ICMP type is 8

-s: specify IP and mask, and "0 IP 0" indicates that this rule is for all CPMs and masks

After the above configuration, the internal ping will also become invalid, and after you disable ping through the firewall, you can ping your own internal network.

Once set up, another command to ping my IP or www.appjzw.com domain name will produce an error similar to the following figure.

After reading the above, do you have any further understanding of Centos7's methods of temporarily or permanently disabling the ping command? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Command permanent host content server rule firewall service configuration fire prevention method network error usage following figure again parameter can pass return domain name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple OPPO Reno macOS MariaDB