{"id":25269,"date":"2018-01-18T02:09:19","date_gmt":"2018-01-18T08:09:19","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=25269"},"modified":"2022-12-05T06:41:21","modified_gmt":"2022-12-05T12:41:21","slug":"how-to-list-and-delete-iptables-firewall-rules","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-list-and-delete-iptables-firewall-rules\/","title":{"rendered":"How to List and Delete iptables Firewall Rules"},"content":{"rendered":"
<\/p>\n
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.\u00a0iptables requires elevated privileges to operate and must be executed by user\u00a0root, otherwise it fails to function.<\/p>\n
<\/p>\n
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<\/a> and run the following command:<\/p>\n To run the command above your user need to have If there are no rules added to the packet filtering ruleset the output should be similar to the one below:<\/p>\n Since NAT (Network Address Translation) can also be configured via iptables, you can use iptables to list the NAT rules:<\/p>\n The output will be similar to the one below if there are no rules added:<\/p>\n If this is the case we recommend you to check our tutorial on How to Set Up a Firewall with iptables on Ubuntu and CentOS<\/a> to make your server more secure.<\/p>\n At some point, you may need to delete a specific iptables firewall rule on your server. For that purpose you need to use the following syntax:<\/p>\n 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 delete that rule, you can use the following command:<\/p>\n Now that you deleted the iptables firewall rule you need to save the changes to make them persistent.<\/p>\n In case you are using Ubuntu VPS<\/a> you need to install additional package for that purpose. To install the required package use the following command:<\/p>\n On Ubutnu 14.04<\/strong> you can save and reload the firewall rules using the commands below:<\/p>\n On Ubuntu 16.04<\/strong> use the following commands instead:<\/p>\n If you are using CentOS VPS<\/a> you can save the changes using the command below:<\/p>\n Of course, you don\u2019t have to\u00a0list and delete iptables firewall rules if you use one of our Managed VPS Hosting<\/a> services, in which case you can simply ask our expert Linux admins to help you list and delete iptables firewall rules\u00a0on your server. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n PS<\/strong><\/span>. If you liked this post, on how to 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.<\/p>\n","protected":false},"excerpt":{"rendered":" We’ll show you, how to list and delete iptables firewall rules. Iptables is a command line utility that allows system … <\/p>\nsudo iptables -nvL<\/pre>\n
sudo<\/code> privileges. Otherwise, you need to add sudo user on your Linux VPS<\/a> or use the root user.<\/p>\n
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)\r\n pkts bytes target prot opt in out source destination\r\n\r\nChain FORWARD (policy ACCEPT 0 packets, 0 bytes)\r\n pkts bytes target prot opt in out source destination\r\n\r\nChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)\r\n pkts bytes target prot opt in out source destination\r\n<\/pre>\n
sudo iptables -t nat -n -L -v<\/pre>\n
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)\r\n pkts bytes target prot opt in out source destination\r\n\r\nChain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)\r\n pkts bytes target prot opt in out source destination\r\n\r\nChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)\r\n pkts bytes target prot opt in out source destination\r\n<\/pre>\n
How to Delete iptables Firewall Rules?<\/h2>\n
iptables [-t table] -D chain rulenum<\/pre>\n
sudo iptables -D INPUT -s 111.111.111.111 -p tcp --dport 22 -j DROP<\/pre>\n
sudo apt-get install iptables-persistent<\/pre>\n
sudo \/etc\/init.d\/iptables-persistent save\r\nsudo \/etc\/init.d\/iptables-persistent reload<\/pre>\n
sudo netfilter-persistent save\r\nsudo netfilter-persistent reload<\/pre>\n
service iptables save<\/pre>\n