How to Enable & Disable Ping (ICMP Echo Requests) from IPTables on Linux Cloud Servers

2021-08-18 By Aaron 157396 Views linux ping networking
20 reviews

PING (Packet Internet Groper) command is used to check the network connectivity between a source and destination and it uses ICMP(Internet Control Message Protocol) to send echo request messages to the destination and wait for a response.


pingdiagram


This guide outlines the basic steps to disable and enable Ping from IPTables on the Linux server.





Disabling Ping:


  1. Verify the installation and check the version of the iptables by using the below command.

    # iptables --version
    

    pinglinux4

  2. The iptables is the Linux command line firewall which allows us to manage incoming and outgoing traffic based on a set of rules. The following rules are used to disable ping to and from the server normally.

    # iptables -A INPUT -p icmp --icmp-type echo-request -j REJECT
    
    A : This command switch is used to add the rule.
    

    Or else, use the below rules in order to disable ping without printing an error message.

    # iptables -A INPUT -p icmp --icmp-type echo-request -j DROP 
    
    # iptables -A OUTPUT -p icmp --icmp-type echo-reply -j DROP
    
  3. List the rules added in iptables using the below command.

    # iptables -L
    

    pinglinux5

  4. Once the ping is disabled, the server should now respond to ping requests as shown in the below image.

    pinglinux6





Enabling Ping:


  1. Run the below command to enable ping on the server. It removes the rules of any blocking ping and will make network troubleshooting easier.

    # iptables -D INPUT -p icmp --icmp-type echo-request -j DROP
    
    # iptables -D OUTPUT -p icmp --icmp-type echo-reply -j DROP
    
    D : This command switch is used to delete the rule.
    

    pinglinux7

  2. Once the ping is enabled, the server should now respond to ping requests as shown in the below image.

    pinglinux2

  3. If necessary, you may remove all custom rules from iptables by using the below command.

    # iptables -F
    

    Once you have removed the rules, please use the below command to check whether any more rules are present in iptables.

    # iptables -L
    

    pinglinux3


Related Tutorials


Other Information

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.