订阅内容

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.

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

按频道浏览

automation icon

自动化

有关技术、团队和环境 IT 自动化的最新信息

AI icon

人工智能

平台更新使客户可以在任何地方运行人工智能工作负载

open hybrid cloud icon

开放混合云

了解我们如何利用混合云构建更灵活的未来

security icon

安全防护

有关我们如何跨环境和技术减少风险的最新信息

edge icon

边缘计算

简化边缘运维的平台更新

Infrastructure icon

基础架构

全球领先企业 Linux 平台的最新动态

application development icon

应用领域

我们针对最严峻的应用挑战的解决方案

Original series icon

原创节目

关于企业技术领域的创客和领导者们有趣的故事