Monday, January 22, 2018

How To List and Delete iptables Firewall Rules

We’ll show you, how to list and delete iptables firewall rules.
Iptables is a command line utility that allows system administrators to
configure the packet filtering rule set on Linux. iptables requires
elevated privileges to operate and must be executed by user root,
otherwise it fails to function.

How to List iptables Firewall Rules

Iptables allows you to list all the rules which are already added to
the packet filtering rule set. In order to be able to check this you
need to have SSH access to the server. Connect to your Linux VPS via SSH and run the following command:

sudo iptables -nvL

To run the command above your user need to have sudo privileges. Otherwise, you need to add sudo user on your Linux VPS or use the root user.
If there are no rules added to the packet filtering ruleset the output should be similar to the one below:

How to Delete iptables Firewall Rules

At some point, you may need to remove a specific iptables firewall
rule on your server. For that purpose you need to use the following
syntax:

iptables [-t table] -D chain rulenum

For example, if you have a firewall rule to block all connections
from 111.111.111.111 to your server on port 22 and you want to remove
that rule, you can use the following command:

sudo iptables -D INPUT -s 111.111.111.111 -p tcp --dport 22 -j DROP

Now that you removed the iptables firewall rule you need to save the changes to make them persistent.
In case you are using Ubuntu VPS you need to install additional package for that purpose. To install the required package use the following command:

sudo apt-get install iptables-persistent

On Ubutnu 14.04 you can save and reload the firewall rules using the commands below:

If you are using CentOS VPS you can save the changes using the command below:

service iptables save

Of course, you don’t have to list and delete iptables firewall rules if you use one of our Managed VPS Hosting
services, in which case you can simply ask our expert Linux admins to
help you list and delete iptables firewall rules on your server. They
are available 24×7 and will take care of your request immediately.PS. If you
liked this post, on how to list and delete iptables firewall rules,
please share it with your friends on the social networks using the
buttons on the left or simply leave a reply below. Thanks.