Type something to search...
How to Install and Setup FireWall on Amazon Linux 2

How to Install and Setup FireWall on Amazon Linux 2

Introduction

We will learn how to install and setup FireWall on Amazon Linux 2 in this tutorial. We will also discover how to set up FireWall so that it functions with the Amazon Linux 2.

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 Setup Firewalld on Amazon Linux 2

Step 1: Install Firewalld

Before we can install FireWall, 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 FireWall.

Terminal window
# Install FireWall
sudo yum install firewalld -y

Next, after installing FireWall, 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 FireWall service.

Terminal window
# Start the FireWall service
sudo systemctl start firewalld

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

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

Newly installed FireWall services are not enabled by default. To enable the FireWall service, we can use the following command.

Terminal window
# Enable the FireWall service
sudo systemctl enable firewalld

Step 2: Configure Firewalld

Now that the FireWall service is running, we can configure it. To configure the FireWall service, we can use the following command.

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

List Firewalld Zones

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

List Services Default Zone

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

To verify that the FireWall service is configured correctly, we can use the following command.

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

List All Firewalld Zones

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

Step 3: Set Up Default Firewalld Zone

To set up 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 FireWall Status

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

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

Step 5: Assigning Services to Firewalld Zones

To assign services to Firewalld zones, we can use the following command.

Terminal window
# Assign services to Firewalld zones
firewall-cmd --state
firewall-cmd --get-active-zones

Step 6: Adding Services to Firewalld Zones

To add services to Firewalld zones, we can use the following command.

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

In this tutorial, we learned how to install and setup FireWall on Amazon Linux 2. We also learned how to set up FireWall so that it functions with the Amazon Linux 2.

References

Related Posts

Check out some of our other posts

How To Create A Custom VPC Using AWS CLI

How To Create A Custom VPC Using AWS CLI

Introduction In the sample that follows, an IPv4 CIDR block, a public subnet, and a private subnet are all created using AWS CLI instructions. You can run an instance in the public subnet and con

read more
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 run simple HTML web page. Prerequisit

read more
How to Install PHP and MariaDB on Amazon Linux 2

How to Install PHP and MariaDB on Amazon Linux 2

Introduction We will learn how to set up PHP and MariaDB on Amazon Linux 2 in this tutorial. We will also discover how to set up PHP so that it functions with the Apache web server. We will also

read more
How to Install WordPress on Amazon Linux 2

How to Install WordPress on Amazon Linux 2

Introduction We will learn how to install WordPress on Amazon Linux 2 in this tutorial. We will also discover how to set up WordPress so that it functions with the Apache web server. We will also

read more
How To Create An AWS EC2 Instance Using AWS CLI

How To Create An AWS EC2 Instance Using AWS CLI

Introduction We will learn how to create an AWS EC2 instance using AWS CLI in this tutorial. We will also discover how to set up an AWS EC2 instance so that it functions with the Apache web serve

read more
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]

read more