block ICMP (Internet Control Message Protocol) echo requests "Ping"
To configure a server so that it does not respond to ping requests, you can block ICMP (Internet Control Message Protocol) echo requests, which are what ping
uses to check if a server is reachable. Here are some ways to achieve this depending on your server’s operating system.
For Linux (using iptables
or ufw
)
Using iptables
Open a terminal on your server.
Run the following command to drop ICMP echo requests:
sudo iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
This command adds a rule to the firewall to drop all incoming ping requests.
To make this rule persistent (so it survives a reboot), save your iptables rules:
sudo iptables-save > /etc/iptables/rules.v4
(Location of
rules.v4
may vary depending on distribution; for example, it might be/etc/iptables.up.rules
.)
Using ufw
(if ufw
is installed)
Open a terminal on your server.
Disable ICMP echo requests with:
sudo ufw deny proto icmp
This will configure
ufw
to block all ICMP requests, including pings.
For Windows Server (using Windows Firewall)
- Open Windows Defender Firewall with Advanced Security.
- Go to Inbound Rules.
- Look for File and Printer Sharing (Echo Request - ICMPv4-In) and File and Printer Sharing (Echo Request - ICMPv6-In) rules.
- Right-click on these rules and select Disable.
To Re-enable Ping Responses
To allow ping responses again:
Linux (iptables): Remove the rule by running:
sudo iptables -D INPUT -p icmp --icmp-type echo-request -j DROP
Linux (ufw): Run:
sudo ufw allow proto icmp
Windows: Re-enable the File and Printer Sharing (Echo Request) rules in the Windows Firewall.
These steps will configure your server to ignore ping requests, effectively making it “invisible” to ping commands while still accessible for other network services.