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

Git SSH Keys for GitHub, GitLab, and Bitbucket on Linux

Git SSH Keys for GitHub, GitLab, and Bitbucket on Linux

Introduction Git connects to remotes by default via HTTPS, which requires you to enter your login and password every time you run a command like Git pull or git push, using the SSH protocol. You m

read more
Dotfiles: A Git-Based Strategy for Configuration Management

Dotfiles: A Git-Based Strategy for Configuration Management

Keeping your dotfiles โ€” those hidden configuration files that dot your home directory โ€” both safe and easily accessible across various machines can seem daunting. However, with the strategy outlined b

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

read more
Introduction to Linux CLI

Introduction to Linux CLI

Introduction The Linux operating system family is a group of free and open-source Unix systems. They consist of Red Hat, Arch Linux, Ubuntu, Debian, openSUSE, and Fedora. You must utilize a shell

read more
VIM Cheat Sheet

VIM Cheat Sheet

What Is VIM? VIM (Vi Improved) is a versatile text editor pre-installed on most Linux systems, known for its efficiency in command-line file editing. Its modal natureโ€”switching between modes like

read more
Git SSH Keys for GitHub, GitLab, and Bitbucket on Windows

Git SSH Keys for GitHub, GitLab, and Bitbucket on Windows

Introduction Git connects to remotes by default via HTTPS, which requires you to enter your login and password every time you run a command like Git pull or git push, using the SSH protocol. You m

read more