Sheet 02 · BlogSurveyed 2026

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.

How to Install and Setup FireWall on Amazon Linux 2

Published: 02 Mins read03 Mins listen
Markdown for AI(opens in a new tab)

Introduction

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

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

Step 1: install firewalld

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

Terminal window
# Update the system
sudo yum update -y

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

Terminal window
# Install FireWall
sudo yum install firewalld -y

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

Terminal window
# Check if the iptables service is running
sudo systemctl status iptables

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

Terminal window
# Stop the iptables service
sudo systemctl stop iptables

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

Terminal window
# Start the FireWall service
sudo systemctl start firewalld

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

Terminal window
# Check if the FireWall service is running
sudo 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
# Enable the FireWall service
sudo systemctl enable 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
# Configure the FireWall service
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-service=ssh
sudo firewall-cmd --reload

To list the zones firewalld ships with:

Terminal window
# List Firewalld Zones
sudo firewall-cmd --get-zones

To list the predefined services firewalld knows about:

Terminal window
# List Services Default Zone
sudo firewall-cmd --get-services

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

Terminal window
# Check the FireWall service configuration
sudo firewall-cmd --list-all

To dump the full configuration of every zone at once:

Terminal window
# List All Firewalld Zones
sudo firewall-cmd --list-all-zones

Step 3: set the default firewalld zone

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

Terminal window
# Set up the default Firewalld zone
sudo firewall-cmd --set-default-zone=public

Step 4: check the firewall status

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

Terminal window
# Check the FireWall status
sudo firewall-cmd --state

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
# Assign services to Firewalld zones
firewall-cmd --state
firewall-cmd --get-active-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
# Add services to Firewalld zones
firewall-cmd --add-service=rtmp
# Remove services from Firewalld zones
firewall-cmd --zone=public --remove-service=rtmp
# add port to zone
firewall-cmd --zone=public --add-port=80/tcp --permanent
# remove port from zone
firewall-cmd --zone=public --remove-port=80/tcp --permanent

Conclusion

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

References

Was this useful?

You might also enjoy

More posts on similar topics

How to Install Apache Web Server on Amazon Linux 2

How to Install Apache Web Server on Amazon Linux 2

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

How to Install PHP and MariaDB on Amazon Linux 2

How to Install PHP and MariaDB on Amazon Linux 2

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

How to Install WordPress on Amazon Linux 2

How to Install WordPress on Amazon Linux 2

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

How to Install and Configure Node.js on EC2 Instance Amazon Linux 2

How to Install and Configure Node.js on EC2 Instance Amazon Linux 2

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

How To Create An AWS EC2 Instance Using AWS CLI

How To Create An AWS EC2 Instance Using AWS CLI

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

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

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](

6 related posts