This guide shows you how to configure your VPS firewall and system settings to respond to ICMP echo requests (ping) from external IP addresses. By default, many VPS providers and operating systems block ping for security, so you’ll learn the exact commands to enable it on common Linux distributions. You’ll need root or sudo access to your VPS and a basic familiarity with the command line.
What You’ll Need
- Root or sudo access to your VPS (via SSH)
- Your VPS’s operating system (Ubuntu/Debian, CentOS/RHEL, or other Linux)
- Knowledge of whether your provider has a separate cloud firewall (e.g., in the provider’s control panel)
Step-by-Step
- Log in to your VPS via SSH. Use your terminal (Linux/macOS) or PuTTY (Windows) to connect:
ssh user@your_vps_ip. Replaceuserwith your username andyour_vps_ipwith your server’s public IP. - Identify your firewall tool. Most modern VPS use
ufw(Ubuntu/Debian),firewalld(CentOS/RHEL), oriptablesdirectly. Runsudo ufw statusorsudo firewall-cmd --stateto see which is active. If neither is installed, you may be using plain iptables. - Allow ICMP echo requests via ufw (if using ufw). Run
sudo ufw allow icmpor more specificallysudo ufw allow proto icmp from any to any. This opens all ICMP types, but you can restrict to echo-request withsudo ufw allow proto icmp icmp-type echo-request. - Allow ICMP via firewalld (if using firewalld). Run
sudo firewall-cmd --permanent --add-icmp-block-inversion(this allows all ICMP types) orsudo firewall-cmd --permanent --add-icmp-block=echo-request(this blocks echo-request, so instead use--remove-icmp-block=echo-request). After changes, reload withsudo firewall-cmd --reload. - Allow ICMP via iptables (if using iptables directly). Run
sudo iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT. To make it persistent, save withsudo netfilter-persistent save(Debian/Ubuntu) orsudo service iptables save(RHEL/CentOS). - Check your VPS provider’s cloud firewall. Many providers (DigitalOcean, AWS, Azure, etc.) have a separate firewall in their control panel. Log into your provider’s dashboard, find your VPS, and ensure there’s an inbound rule allowing ICMP (or ping) from the desired IP or from anywhere (0.0.0.0/0). If you skip this, your server may still block ping.
- Test locally first. From your VPS, run
ping -c 4 127.0.0.1to confirm the kernel responds. Then try pinging your VPS’s public IP from your local machine. If it fails, proceed to troubleshooting.
Common Mistakes
- Forgetting the provider firewall. The most common issue is that the VPS’s internal firewall is configured, but the provider’s cloud firewall still blocks ICMP. Always check both.
- Allowing all ICMP types vs. only echo-request. Some guides suggest allowing all ICMP, which is fine for testing but less secure. Restricting to echo-request is safer.
- Not reloading firewalld. If you use firewalld and forget to run
sudo firewall-cmd --reload, changes won’t take effect. - Using the wrong interface. If you have multiple network interfaces, ensure you’re adding the rule to the correct one (e.g., eth0 vs. ens3).
- Not saving iptables rules. Without saving, rules are lost after reboot.
Tips
- For security, allow ping only from specific IPs or subnets if you don’t need it from anywhere. Use
sudo ufw allow from 203.0.113.0/24 proto icmpfor ufw, orsudo iptables -A INPUT -s 203.0.113.0/24 -p icmp --icmp-type echo-request -j ACCEPT. - To test without changing firewall rules, temporarily disable the firewall (not recommended for production) or use a tool like
tcpingto test TCP connectivity instead. - If you’re using a cloud provider like AWS, you can use Security Groups to allow ICMP; for Azure, use Network Security Groups (NSG).
- Consider using rate limiting on ICMP to prevent abuse:
sudo iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT.
Troubleshooting
If ping still doesn’t work after following the steps:
- Check the provider firewall again. Log into your provider’s dashboard and verify the inbound ICMP rule is active. Sometimes rules are not applied until you save or reboot.
- Test from the VPS itself. Run
ping -c 4 your_vps_public_ipfrom the VPS. If that fails, the issue is local. If it works, the issue is external (provider firewall or your local network). - Check if the kernel is ignoring ICMP. Run
sysctl net.ipv4.icmp_echo_ignore_all. If it returns 1, set it to 0 withsudo sysctl -w net.ipv4.icmp_echo_ignore_all=0and make it permanent by addingnet.ipv4.icmp_echo_ignore_all=0to/etc/sysctl.conf. - Verify iptables rules are in the right chain. Use
sudo iptables -L -n -vto see if your rule is present and the packet count is increasing when you ping. If not, the packet is being dropped before reaching your rule (maybe by a default DROP policy). - Check for other security software. Some VPS have fail2ban or other intrusion prevention that may block ICMP. Check logs with
sudo journalctl -u fail2banorsudo tail /var/log/syslog. - Reboot the VPS. Sometimes a reboot applies firewall changes cleanly, especially after iptables saves.
Frequently Asked Questions
Why is ping blocked by default on my VPS?
Many VPS providers and operating systems block ICMP to reduce the attack surface and prevent network reconnaissance. It’s a common security hardening step.
Is it safe to allow ping from anywhere?
Generally yes, but it reveals that your server is active and responsive. If you’re concerned, restrict ping to specific IPs or subnets.
What is the difference between ICMP and TCP ping?
ICMP ping uses the ICMP protocol (echo request/reply). TCP ping uses TCP packets (e.g., to port 80) to check if a service is up. Firewalls often block ICMP but allow TCP, so TCP ping may work when ICMP ping fails.
Do I need to allow both IPv4 and IPv6 ping?
If your VPS has an IPv6 address, you’ll need to configure both. For ufw, use sudo ufw allow proto ipv6-icmp; for iptables, use ip6tables commands.
How can I test ping from an external network without a second device?
You can use online ping tools (like ping.eu) that send ICMP requests from their servers. Just enter your VPS IP and see if they get a response.
Will allowing ping affect my VPS performance?
Minimally. Ping requests are small and low-volume. However, if you’re under a DDoS attack, ICMP can be used to amplify traffic, so consider rate limiting.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Valheim Server Not Showing in Community List Fixes
- DisplayPort vs HDMI: Which Cable Should You Use?
- Soundbar vs 2.1 Speaker System: Which Is Better?
- Survive Lava for Brainrot Tier List170 points
- MySQL Dump Import: Fix Common Errors
- Mouse Moving on Its Own? Causes & Fixes