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.