In my previous article, "Beginner's guide to firewalld in Linux," we explored the basics of creating allow and deny lists for both services and ports inside of existing zones. If this doesn't sound familiar, I recommend that you check out that previous piece. However, if you are up to speed with firewalld, zone-based firewalls, and service/port-based rules, then you are in the right place. In this article, we look at three slightly more advanced features of firewalld and how to configure each. Let's get into it.

Create custom zones

As discussed previously, zone-based firewalls need zones to operate. The goal is to have different security measures for particular zones of the network. Let us assume that we need to create a new zone called enable_test. To do this, we use the following command:

[root@server ~]# firewall-cmd --permanent --new-zone=enable_test
success

This command creates a new, permanent zone titled enable_test. There are no services or ports added to enable_test yet. Therefore, no traffic is allowed in or out. If you have a configuration file that you normally use for firewall zone configs, you can use it by using this command:

[root@server ~]# firewall-cmd --permanent --new-zone-from-file=file --name=enable_test
success

Note 1: In --new-zone-from-file=file, file = the file path of the config.

Note 2: When creating zones, you must use the --permanent flag. You must also --reload the config for the changes to take place.

Assign an interface

Now that we have our new enable_test zone created, we need to associate a network interface with the zone. If we don't do this, we won't be able to use the new zone. I am going to associate it with the interface enp0s8.

Add the interface to the zone:

[root@server ~]# firewall-cmd --permanent --zone=enable_test --add-interface=enp0s8
success

Verify the interface association:

[root@server ~]# firewall-cmd --zone=enable_test --list-interfaces
enp0s8

If you need to remove the interface:

[root@server ~]# firewall-cmd --remove-interface=enp0s8 --zone=enable_test 
success

Advanced rule creation

Now, here is where things get interesting. There is a lot of flexibility in the rules you can create with firewalld. You aren't limited to just "deny this port," "allow this service," and so on... You can create highly complex rules for specific situations. These rules are known as rich rules.

Something to know about firewall rules—in general, they are made up of two parts:

  1. Conditions that must be met before the rule can be enacted.
  2. Actions to be carried out once those conditions are met. These actions are accept, reject, and drop.

Let's assume that we want to create a rule that states something like this:

Reject all FTP connections from Fedora client 2 (172.25.1.7)

[root@server ~]# firewall-cmd --zone=enable_test --add-rich-rule="rule \
family="ipv4" \
source address=172.25.1.7 \
service name=ftp \
reject \

Most of these options are self-explanatory; however, you must start with the keyword rule. The family option states the type of traffic to enact the rule on. If left blank, it will default to both IPv4 and IPv6 packets.

Need more info?

As you might have guessed, there are a huge number of options to create even more complex rules. Be sure to check out the firewalld documentation for further information. Hopefully, this look behind one of our most important curtains has been an enlightening experience. While firewalls and security systems are quite complex, at their most basic levels, they are just a set of rules—rules designed not to be broken.

[ Network getting out of control? Check out Network automation for everyone, a free book from Red Hat. ]


저자 소개

Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. Now that he has surfaced, he lives with his wife and son near Raleigh, where he worked as a data storage engineer before finding his way to the Red Hat team. He has written numerous technical documents, from military procedures to knowledgebase articles and even some training curricula. In his free time, he blends a passion for hiking, climbing, and bushcraft with video games and computer building. He is loves to read and enjoy a scotch or bourbon. Find him on Twitter or on LinkedIn.

UI_Icon-Red_Hat-Close-A-Black-RGB

채널별 검색

automation icon

오토메이션

기술, 팀, 인프라를 위한 IT 자동화 최신 동향

AI icon

인공지능

고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트

open hybrid cloud icon

오픈 하이브리드 클라우드

하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요

security icon

보안

환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보

edge icon

엣지 컴퓨팅

엣지에서의 운영을 단순화하는 플랫폼 업데이트

Infrastructure icon

인프라

세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보

application development icon

애플리케이션

복잡한 애플리케이션에 대한 솔루션 더 보기

Virtualization icon

가상화

온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래