Since 2016 · 50,000+ customers · ★ 5.0 on Google Live chatWhatsAppTelegramOpen a ticket
Get started
Linux

How to Disable or Turn Off the Firewall on CentOS

How to disable the firewall on CentOS guide by 99RDP

CentOS, CentOS Stream, Rocky Linux and AlmaLinux all use firewalld as their default firewall. Sometimes you need to switch it off for a few minutes to test whether it is blocking a service, or replace it with another firewall such as plain iptables or nftables rules. This guide shows how to stop firewalld for the current session, disable it permanently, mask it so nothing starts it again, and turn it back on. It also covers the safer alternative: opening only the port you need.

Quick answerTo turn the firewall off now and keep it off after a reboot, run:

sudo systemctl stop firewalld
sudo systemctl disable firewalld

A server without a firewall is exposed to every scan on the internet. Only disable firewalld when you have another firewall in place (a provider-level firewall, or your own nftables rules), or for a short test that you will undo.

Comparison of stopping, disabling and masking firewalld on CentOS and Rocky Linux
Stop, disable or mask?

Check the current firewall status

Before changing anything, see whether firewalld is running:

sudo systemctl status firewalld
sudo firewall-cmd --state

active (running) and running mean the firewall is on. List what it currently allows with:

sudo firewall-cmd --list-all

Save this output somewhere. If you later turn the firewall back on, it is useful to know which services and ports were open.

Method 1: Stop firewalld temporarily

To turn the firewall off until the next reboot:

sudo systemctl stop firewalld

This is the best option for troubleshooting. If an application starts working once firewalld is stopped, the firewall was blocking it, and you can open the correct port instead of leaving the server unprotected. After a reboot, firewalld starts again on its own.

Comparison of stopping, disabling and masking firewalld on CentOS
Stop, disable or mask?

Method 2: Disable firewalld permanently

To stop the firewall and prevent it from starting at boot:

sudo systemctl stop firewalld
sudo systemctl disable firewalld

You can also do both in one command:

sudo systemctl disable --now firewalld

Confirm it is off:

sudo systemctl is-enabled firewalld
sudo systemctl is-active firewalld

You should see disabled and inactive.

Method 3: Mask firewalld

A disabled service can still be started by another package or by an administrator. Masking it blocks every attempt to start it:

sudo systemctl mask --now firewalld

Mask firewalld only when you are replacing it with another firewall, so that two firewalls do not fight over the same rules. To undo it, run sudo systemctl unmask firewalld.

Disable iptables on older systems

CentOS 6 and some custom CentOS 7 builds use the iptables service instead of firewalld. To check and stop it on CentOS 7 with iptables-services installed:

sudo systemctl status iptables
sudo systemctl stop iptables
sudo systemctl disable iptables

On CentOS 6 the older commands apply:

sudo service iptables stop
sudo chkconfig iptables off

To clear all loaded rules immediately without stopping a service (saved rules return on reboot), set the default policies to accept and then flush:

sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -F

Set the policies to ACCEPT before flushing. If you flush while the INPUT policy is DROP, you will lock yourself out of SSH.

Better than disabling the firewall: open only the port or service you need with firewall-cmd
Open a port instead

The safer alternative: open only the port you need

Most people who search for "turn off firewall" actually need one port to work, for a web server, a game server or a custom application. Opening that port keeps everything else protected:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

Check the result with sudo firewall-cmd --list-all. If you changed the SSH port, add the new port before you reload, or you could lose access to the server.

Turn the firewall back on

sudo systemctl unmask firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --state

firewalld keeps its permanent configuration while it is disabled, so the services and ports you allowed earlier come back when it starts.

A note on CentOS versions

CentOS Linux 7 reached end of life on 30 June 2024 and no longer receives security updates. The commands in this guide work the same on CentOS Stream 9 and 10, Rocky Linux and AlmaLinux 8, 9 and 10, which are the usual replacements. If you still run CentOS 7 on an internet-facing server, plan a migration rather than removing its firewall.

Frequently asked questions

How do I check if the firewall is running on CentOS?

Run sudo firewall-cmd --state. It prints running when firewalld is active. sudo systemctl status firewalld shows more detail, including whether it is enabled at boot.

Is it safe to disable the firewall on a VPS?

Not on its own. A public server is scanned within minutes of going online. Disable firewalld only for a short test, or when another firewall (your provider's network firewall or your own nftables rules) protects the server.

What is the difference between disable and mask?

disable stops the service starting at boot, but it can still be started manually or by another service. mask links the unit to /dev/null so it cannot be started at all until you unmask it.

Does disabling firewalld remove my rules?

No. The permanent configuration in /etc/firewalld/ stays in place, and the same rules apply when you enable firewalld again.

Does SELinux count as a firewall?

No. SELinux controls what processes may do on the system, not network traffic. If a service still fails with firewalld stopped, check SELinux with getenforce and the audit log rather than disabling it.

Nishant Kumar, Sr. Server Engineer at 99RDP
Written byNishant KumarSr. Server Engineer, 99RDP. Part of the team that runs our servers and answers support.
Keep reading

More Linux guides

All Linux guides

Need a server for this?

✓ Setup in minutes✓ Full admin access✓ 7-day refund on new services