---
title: "How to Install and Setup FireWall on Amazon Linux 2"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/how-to-install-and-setup-firewall-on-amazon-linux-2
---

![Blog post image for How to Install and Setup FireWall on Amazon Linux 2 - How to install and configure firewalld on Amazon Linux 2, including zones, services, and ports.](/_astro/hero.b8oDtFR4_2oM0R1.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[AWS](/blog/categories/aws)

Blog

[Prev in AWSHow to Install and Configure Node.js on EC2 Instance Amazon Linux 2](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)[Next in AWSHow to Install Apache Web Server on Amazon Linux 2](/blog/post/how-to-install-apache-web-server-on-amazon-linux-2)

[AWS](/blog/categories/aws)[EC2](/blog/categories/ec2)[Linux](/blog/categories/linux)[Firewall](/blog/categories/firewall)[Security](/blog/categories/security)

# How to Install and Setup FireWall on Amazon Linux 2

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 24 Oct 202202 Mins read03 Mins listen

[Markdown for AI(opens in a new tab)](/post/how-to-install-and-setup-firewall-on-amazon-linux-2/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

How to install and configure firewalld on Amazon Linux 2, including zones, services, and ports.

Series

[Amazon Linux 2 LAMP Stack Setup](/series/amazon-linux-2-lamp-stack-setup)1/4

[NextHow to Install Apache Web Server on Amazon Linux 2](/blog/post/how-to-install-apache-web-server-on-amazon-linux-2)

All posts in this series (4)

Blog4

1.  [How to Install and Setup FireWall on Amazon Linux 2You are here](/blog/post/how-to-install-and-setup-firewall-on-amazon-linux-2)
2.  [How to Install Apache Web Server on Amazon Linux 2](/blog/post/how-to-install-apache-web-server-on-amazon-linux-2)
3.  [How to Install PHP and MariaDB on Amazon Linux 2](/blog/post/how-to-install-php-and-mariadb-on-amazon-linux-2)
4.  [How to Install WordPress on Amazon Linux 2](/blog/post/how-to-install-wordpress-on-amazon-linux-2)

### How to Install and Setup FireWall on Amazon Linux 2

Contents

[Introduction](#introduction)[Prerequisites](#prerequisites)[Install and set up firewalld on Amazon Linux 2](#install-and-set-up-firewalld-on-amazon-linux-2)[Step 1: install firewalld](#step-1-install-firewalld)[Step 2: configure firewalld](#step-2-configure-firewalld)[Step 3: set the default firewalld zone](#step-3-set-the-default-firewalld-zone)[Step 4: check the firewall status](#step-4-check-the-firewall-status)[Step 5: assigning services to firewalld zones](#step-5-assigning-services-to-firewalld-zones)[Step 6: adding services to firewalld zones](#step-6-adding-services-to-firewalld-zones)[Conclusion](#conclusion)[References](#references)

## [Introduction](#introduction)

This tutorial covers installing and configuring firewalld on Amazon Linux 2, including setting the default zone and managing services and ports.

## [Prerequisites](#prerequisites)

To follow along with this tutorial, you will need:

-   An Amazon Linux 2 EC2 instance with a public IP address.
-   A user with sudo privileges.

## [Install and set up firewalld on Amazon Linux 2](#install-and-set-up-firewalld-on-amazon-linux-2)

### [Step 1: install firewalld](#step-1-install-firewalld)

Before we can install firewalld, we must first update the system.

Terminal window

```
1# Update the system2sudo yum update -y
```

Now that the system has been updated, we can install firewalld.

Terminal window

```
1# Install FireWall2sudo yum install firewalld -y
```

Next, after installing firewalld, it’s time to verify whether the _iptables_ service is running.

Terminal window

```
1# Check if the iptables service is running2sudo systemctl status iptables
```

If the _iptables_ service is running, we need to stop it.

Terminal window

```
1# Stop the iptables service2sudo systemctl stop iptables
```

Now that the _iptables_ service is stopped, we can start the firewalld service.

Terminal window

```
1# Start the FireWall service2sudo systemctl start firewalld
```

To verify that the firewalld service is running, we can use the following command.

Terminal window

```
1# Check if the FireWall service is running2sudo systemctl status firewalld
```

A newly installed firewalld service is not enabled at boot by default. To enable it, we can use the following command.

Terminal window

```
1# Enable the FireWall service2sudo systemctl enable firewalld
```

### [Step 2: configure firewalld](#step-2-configure-firewalld)

Now that the firewalld service is running, we can configure it. Allow HTTP, HTTPS, and SSH in the public zone, then reload.

Terminal window

```
1# Configure the FireWall service2sudo firewall-cmd --permanent --zone=public --add-service=http3sudo firewall-cmd --permanent --zone=public --add-service=https4sudo firewall-cmd --permanent --zone=public --add-service=ssh5sudo firewall-cmd --reload
```

To list the zones firewalld ships with:

Terminal window

```
1# List Firewalld Zones2sudo firewall-cmd --get-zones
```

To list the predefined services firewalld knows about:

Terminal window

```
1# List Services Default Zone2sudo firewall-cmd --get-services
```

To verify that the default zone is configured the way we expect, we can use the following command.

Terminal window

```
1# Check the FireWall service configuration2sudo firewall-cmd --list-all
```

To dump the full configuration of every zone at once:

Terminal window

```
1# List All Firewalld Zones2sudo firewall-cmd --list-all-zones
```

### [Step 3: set the default firewalld zone](#step-3-set-the-default-firewalld-zone)

To set the default firewalld zone, we can use the following command.

Terminal window

```
1# Set up the default Firewalld zone2sudo firewall-cmd --set-default-zone=public
```

### [Step 4: check the firewall status](#step-4-check-the-firewall-status)

To check the firewalld status, we can use the following command.

Terminal window

```
1# Check the FireWall status2sudo firewall-cmd --state
```

### [Step 5: assigning services to firewalld zones](#step-5-assigning-services-to-firewalld-zones)

Before we assign services to a zone, let’s check that firewalld is running and see which zones are currently active.

Terminal window

```
1# Assign services to Firewalld zones2firewall-cmd --state3firewall-cmd --get-active-zones
```

### [Step 6: adding services to firewalld zones](#step-6-adding-services-to-firewalld-zones)

To add and remove services and ports on a zone, we can use the following commands.

Terminal window

```
1# Add services to Firewalld zones2firewall-cmd --add-service=rtmp3
4# Remove services from Firewalld zones5firewall-cmd --zone=public --remove-service=rtmp6
7# add port to zone8firewall-cmd --zone=public --add-port=80/tcp --permanent9
10# remove port from zone11firewall-cmd --zone=public --remove-port=80/tcp --permanent
```

## [Conclusion](#conclusion)

This covered installing and configuring firewalld on Amazon Linux 2: enabling the service, setting the default zone, and managing services and ports.

## [References](#references)

-   [Firewalld Official Website](https://firewalld.org/)
-   [Firewalld Documentation - Introduction to firewalld](https://firewalld.org/documentation/man-pages/firewalld.html)
-   [Firewalld Documentation - firewall-cmd](https://firewalld.org/documentation/man-pages/firewall-cmd.html)
-   [Amazon EC2 User Guide for Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html)
-   [Security Groups for your VPC - AWS Documentation](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html) (Note: AWS Security Groups act as a primary firewall)
-   [Managing software on your Linux instance - AWS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-software.html)
-   [Controlling Services with systemctl - Red Hat](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-services) (Amazon Linux is RHEL-based)
-   [Using firewalld - Fedora Project Docs](https://docs.fedoraproject.org/en-US/quick-docs/firewalld/)
-   [Understanding Firewalld Zones - DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7#understanding-firewalld-zones)
-   [AWS - Amazon Linux 2 AMI Information](https://aws.amazon.com/amazon-linux-2/)
-   [iptables Tutorial - Netfilter project](https://www.netfilter.org/documentation/HOWTO//packet-filtering-HOWTO.html) (For context, as firewalld is a frontend for netfilter)

Was this useful?

## Tags

[#Firewalld](/blog/tags/firewalld)[#Amazon Linux 2](/blog/tags/amazon-linux-2)[#EC2 Security](/blog/tags/ec2-security)[#Linux Firewall](/blog/tags/linux-firewall)[#Iptables](/blog/tags/iptables)[#Network Security](/blog/tags/network-security)[#Server Security](/blog/tags/server-security)[#Firewall cmd](/blog/tags/firewall-cmd)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2 "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=How%20to%20Install%20and%20Setup%20FireWall%20on%20Amazon%20Linux%202&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2 "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2&title=How%20to%20Install%20and%20Setup%20FireWall%20on%20Amazon%20Linux%202&summary=How%20to%20install%20and%20configure%20firewalld%20on%20Amazon%20Linux%202%2C%20including%20zones%2C%20services%2C%20and%20ports.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=How%20to%20Install%20and%20Setup%20FireWall%20on%20Amazon%20Linux%202%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2 "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2&text=How%20to%20Install%20and%20Setup%20FireWall%20on%20Amazon%20Linux%202 "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2&title=How%20to%20Install%20and%20Setup%20FireWall%20on%20Amazon%20Linux%202 "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2&t=How%20to%20Install%20and%20Setup%20FireWall%20on%20Amazon%20Linux%202 "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2&media=&description=How%20to%20install%20and%20configure%20firewalld%20on%20Amazon%20Linux%202%2C%20including%20zones%2C%20services%2C%20and%20ports. "Share on Pinterest")[Email](<mailto:?subject=How%20to%20Install%20and%20Setup%20FireWall%20on%20Amazon%20Linux%202&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Fhow-to-install-and-setup-firewall-on-amazon-linux-2>)

## Comments

## You might also enjoy

More posts on similar topics

[![How to Install Apache Web Server on Amazon Linux 2](/_astro/hero.CFurz9Hr_Z2mT9lT.webp)](/blog/post/how-to-install-apache-web-server-on-amazon-linux-2)

## [How to Install Apache Web Server on Amazon Linux 2](/blog/post/how-to-install-apache-web-server-on-amazon-linux-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [Apache](/blog/categories/apache)
-   [Web Server](/blog/categories/web-server)
-   [Linux](/blog/categories/linux)
-   [Firewall](/blog/categories/firewall)

Introduction In this tutorial, we will learn how to install Apache web server on Amazon Linux 2. We will also learn how to configure Apache web server to serve a simple HTML web page. Prerequi

[#Apache Installation](/blog/tags/apache-installation)[#Amazon Linux 2](/blog/tags/amazon-linux-2)[#HTTPD](/blog/tags/httpd)+4 tags

[read more](/blog/post/how-to-install-apache-web-server-on-amazon-linux-2)

[![How to Install PHP and MariaDB on Amazon Linux 2](/_astro/hero.BxVn8-Uf_Z1fCiGj.webp)](/blog/post/how-to-install-php-and-mariadb-on-amazon-linux-2)

## [How to Install PHP and MariaDB on Amazon Linux 2](/blog/post/how-to-install-php-and-mariadb-on-amazon-linux-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [PHP](/blog/categories/php)
-   [MariaDB](/blog/categories/mariadb)
-   [Apache](/blog/categories/apache)
-   [LAMP Stack](/blog/categories/lamp-stack)
-   [Linux](/blog/categories/linux)

Introduction In this tutorial we will set up PHP and MariaDB on Amazon Linux 2. We will get PHP working with the Apache web server, secure the MariaDB install, and then connect the two with a smal

[#PHP Installation](/blog/tags/php-installation)[#MariaDB Installation](/blog/tags/mariadb-installation)[#Amazon Linux 2](/blog/tags/amazon-linux-2)+5 tags

[read more](/blog/post/how-to-install-php-and-mariadb-on-amazon-linux-2)

[![How to Install WordPress on Amazon Linux 2](/_astro/hero.CFnKBY7F_2mvbUb.webp)](/blog/post/how-to-install-wordpress-on-amazon-linux-2)

## [How to Install WordPress on Amazon Linux 2](/blog/post/how-to-install-wordpress-on-amazon-linux-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [WordPress](/blog/categories/wordpress)
-   [LAMP Stack](/blog/categories/lamp-stack)
-   [Linux](/blog/categories/linux)

Introduction This tutorial installs WordPress on Amazon Linux 2 and configures it to run with Apache, PHP, and MariaDB. Prerequisites To follow along with this tutorial, you will need:An

[#WordPress Installation](/blog/tags/wordpress-installation)[#Amazon Linux 2](/blog/tags/amazon-linux-2)[#Apache Setup](/blog/tags/apache-setup)+5 tags

[read more](/blog/post/how-to-install-wordpress-on-amazon-linux-2)

[![How to Install and Configure Node.js on EC2 Instance Amazon Linux 2](/_astro/hero.CIYv_zEL_2aFueX.webp)](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)

## [How to Install and Configure Node.js on EC2 Instance Amazon Linux 2](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [Node.js](/blog/categories/nodejs)
-   [Linux](/blog/categories/linux)

Introduction Node.js does not exist in the default Amazon Linux 2 repository. So, we need to add the Node.js repository to the system. In this post, we will learn how to install and configure Node

[#Node.js Installation](/blog/tags/nodejs-installation)[#Amazon Linux 2](/blog/tags/amazon-linux-2)[#AWS EC2 Setup](/blog/tags/aws-ec2-setup)+3 tags

[read more](/blog/post/how-to-install-and-configure-nodejs-on-ec2-instance-amazon-linux-2)

[![How To Create An AWS EC2 Instance Using AWS CLI](/_astro/hero.Dh2x9Phr_14dc4A.webp)](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

## [How To Create An AWS EC2 Instance Using AWS CLI](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [VPC](/blog/categories/vpc)
-   [AWS CLI](/blog/categories/aws-cli)
-   [WordPress](/blog/categories/wordpress)
-   [Linux](/blog/categories/linux)

Introduction In this tutorial we will create an AWS EC2 instance with the AWS CLI. We will build the network around it first, then launch the instance with a user data script that installs the Apa

[#AWS CLI EC2](/blog/tags/aws-cli-ec2)[#AWS CLI VPC](/blog/tags/aws-cli-vpc)[#VPC Configuration](/blog/tags/vpc-configuration)+8 tags

[read more](/blog/post/how-to-create-an-aws-ec2-instance-using-aws-cli)

[![How to Run an Apache Web Server Using Docker on an AWS EC2 Instance](/_astro/hero.WA3H4xsW_KuMrf.webp)](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

## [How to Run an Apache Web Server Using Docker on an AWS EC2 Instance](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [AWS](/blog/categories/aws)
-   [EC2](/blog/categories/ec2)
-   [Docker](/blog/categories/docker)
-   [Apache](/blog/categories/apache)
-   [Web Server](/blog/categories/web-server)

Introduction In this post, we will learn how to run an Apache web server using Docker on an AWS EC2 instance. We will use the following tools:AWS EC2 \[Docker\](

[#AWS EC2 Docker](/blog/tags/aws-ec2-docker)[#Apache Docker](/blog/tags/apache-docker)[#Containerization](/blog/tags/containerization)+4 tags

[read more](/blog/post/how-to-run-an-apache-web-server-using-docker-on-an-aws-ec2-instance)

6 related posts
