How to Install and Use Iptables on CentOS/RHEL 7

Latest Linux operating systems like CentOS/RedHat 7 and Fedora 21 are now using dynamic firewall daemon firewalld which provides a dynamically managed firewall. In this tutorial we will guide you how to install and enable an iptables firewall on CentOS 7 Linux.
First, we need to disable and remove firewalld firewall. Use following commands:

systemctl stop firewalld
systemctl disable firewalld
yum remove firewalld –y

Install iptables firewall on CentOS 7

To install Iptables package use following command:

yum install iptables-service –y

Once done enable iptables service and start using below commands.

# systemctl enable iptables
# systemctl start iptables

After install iptables firewall, set the iptables service to start automatically with system booting up:

# systemctl enable iptables

Now you can check the iptables service status using below command:

# systemctl status iptables

If you want to save the firewall policy , you need to update the iptables init script, Run the following command:

cp /usr/libexec/iptables/iptables.init /etc/init.d/iptables

Now you can use “/etc/init.d/iptables save ” command.

/etc/init.d/iptables save

To list iptables rules, use the below command:

# iptables- L

That’s all!