How to use IPTables on CentOS 7

Last Updated on July 19, 2015 by admin

Centos 7 replaced the traditional IPTables Linux Kernel Firewall with the Firewalld service. There are still a lot of scripts available that require the use of IPTables. A common example is the software Fail2ban.

In this guide, I will explain the installation of IPTables on Centos 7.x

The first step is to stop and mask the firewalld service:

systemctl stop firewalld
systemctl mask firewalld

Then install the "iptables-services" package with the yum package installer:

yum install iptables-services

And enable the new service:

systemctl enable iptables

IPTables is now ready to be used on your server. For example you can block an external IP address now with the iptables command:

iptables -A INPUT -s -j DROP

Rules that you set with iptables persist only until the next reboot. To save them permanently use the following command:

service iptables save

Leave a Comment