Skip to content

Allow and forbid ping in Linux

一、临时生效

1、允许ping

echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all 

2、禁止ping

echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 

二、永久生效

修改文件:/etc/sysctl.conf

1、允许ping

增加一行:

net.ipv4.icmp_echo_ignore_all=0

2、禁止ping

增加一行:

net.ipv4.icmp_echo_ignore_all=1

修改后使用以下命令使之生效:

sysctl -p

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try my iOS App