How can we help?
Categories
< All Topics
Print

How To List and Delete Iptables Firewall Rules

Introduction

On Linux servers, including those provided by ServerStadium (VM Pricing, Dedicated Servers), iptables serves as a powerful tool for network traffic control. Listing and removing iptables rules helps in managing server access and protecting against unauthorized network traffic.

Prerequisites

Listing Iptables Rules

  1. List All Iptables Rules:

    To view all current iptables rules:

    sudo iptables -L -v

    The -L option lists the rules, and -v provides verbose output.

  2. List Rules by Specific Chain:

    To list rules in a specific chain (e.g., INPUT, FORWARD, OUTPUT):

    sudo iptables -L [CHAIN-NAME] -v

    Replace [CHAIN-NAME] with the name of the chain.

Deleting Iptables Rules

  1. Delete by Rule Number:

    First, list the rules with line numbers:

    sudo iptables -L –line-numbers

    Then, delete a rule by its number in a specific chain:

    sudo iptables -D [CHAIN-NAME] [RULE-NUMBER]

    Replace [CHAIN-NAME] with the chain’s name and [RULE-NUMBER] with the rule’s line number.

  2. Delete by Rule Specification:

    Alternatively, delete a rule by specifying it:

    sudo iptables -D [CHAIN-NAME] -p [PROTOCOL] –dport [PORT] -j [TARGET]

    Replace the placeholders with the rule’s specifics. For example, -p tcp --dport 22 -j ACCEPT to delete a rule allowing SSH.

Saving Changes

  1. Save Iptables Changes:

    After modifying rules, save the changes to ensure they persist after a reboot:

    sudo iptables-save | sudo tee /etc/iptables/rules.v4

    This command saves the current rules to the iptables configuration file.

Conclusion

Effectively managing iptables rules is vital for the security and functionality of your ServerStadium Linux server. Listing and deleting rules as needed helps maintain optimal network settings and protect against threats. For further assistance, visit the ServerStadium knowledge base.

Table of Contents