Home Servers Solution to Iptables and Firewall Issues on Amazon Linux and CentOS

Solution to Iptables and Firewall Issues on Amazon Linux and CentOS


iptables firewall geekact

Recently, I received a mail from reader named Jason. He notified me that he is getting errors like ‘iptables: unrecognized service’ when using iptables commands. I also received some emails in which readers said that they are getting ‘Firewall Not  Running’ when they query the system about iptables status. I found that it is mostly happening to Amazon generic linux. So I digged up for solution and found it. It can be used for Amazon linux or other like CentOS etc.

Solution to this is to remove Iptables and re-install it. However, it is not that simple as it looks. Removing Iptables results in a permanent unusable server with crash as it removes many packages and dependencies.

So I spend some time to come with the trick. Ahead are copy-paste codes to fix and solve this issue. Just remember to use sudo only if you are not a root user (as in Amazon linux);

Login to your server via SSH / PuTTy and copy paste this;

sudo rpm -e --nodeps iptables

and then;

sudo rpm -e --nodeps iptables-services

These above commands will remove Iptables and its services without removing any other files and dependencies.

Now try this;

sudo yum remove iptables

You shall get some prompt like “Iptables is not installed” or “Iptables is available but not installed”. Well that’s a good sign.

Restart the server;

sudo reboot

Re-login to your server via SSH (putty). I know its pain but…

Now reinstall iptables using below command. Please don’t forget the ‘*’. It is not written by mistake. Its a wildcard.

sudo yum install iptables*

Configure the service iptables to start every time with the server;

sudo chkconfig --level 2345 iptables on

Disable the IPV6 Firewall if you don’t have a Version 6 IP address. (Normally you will not have it. You have to get it separately);

sudo chkconfig ip6tables off

Let’s flush something out; 🙂

sudo iptables --flush

And then save the currently loaded rules;

sudo service iptables save

This step shall give you a good hint with OK that now everything is at place.

Let’s restart your server’s firewall;

sudo service iptables restart

There will be many OK’s now. Hang on!

Finally, we have to check that whatever we did, actually worked out;

sudo service iptables status

This will return some INPUT and OUTPUT rules. This means that your firewall is up and running.

You can now proceed to whatever you wanted to do next. As always comments and questions are welcome.


  1. Isac Petruzzi

    May 7, 2013 at 4:18 pm

    Worked like a charm! Thanks for saving me the headache!


  2. Grathy

    May 23, 2013 at 8:58 pm

    Saved my day! Amazing!


  3. Nina

    June 3, 2013 at 6:22 pm

    many thanks man! I was unable to remove packages as it was halting server. Kudos!


  4. tom

    October 25, 2013 at 5:28 pm

    I’m using Amazon Linux and I run the very first command as root user “rpm -e –nodeps iptables” and I get the error: “iptables” specifies multiple packages: iptables-1.4.18-1.22.amzn1.x86_64 iptables-1.4.18-1.22.amzn1.i686 Any idea what to do? Would love to get this to work.


Don't hesitate. Comment!

Check Also

Install CSF Firewall with Virtualmin Module

Managing Linux firewall can be pain without graphic interface. ConfigServer firewall comes…