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:
- Conditions that must be met before the rule can be enacted.
- 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. ]
Sobre o autor
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.
Navegue por canal
Automação
Últimas novidades em automação de TI para empresas de tecnologia, equipes e ambientes
Inteligência artificial
Descubra as atualizações nas plataformas que proporcionam aos clientes executar suas cargas de trabalho de IA em qualquer ambiente
Nuvem híbrida aberta
Veja como construímos um futuro mais flexível com a nuvem híbrida
Segurança
Veja as últimas novidades sobre como reduzimos riscos em ambientes e tecnologias
Edge computing
Saiba quais são as atualizações nas plataformas que simplificam as operações na borda
Infraestrutura
Saiba o que há de mais recente na plataforma Linux empresarial líder mundial
Aplicações
Conheça nossas soluções desenvolvidas para ajudar você a superar os desafios mais complexos de aplicações
Programas originais
Veja as histórias divertidas de criadores e líderes em tecnologia empresarial
Produtos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Red Hat Cloud Services
- Veja todos os produtos
Ferramentas
- Treinamento e certificação
- Minha conta
- Suporte ao cliente
- Recursos para desenvolvedores
- Encontre um parceiro
- Red Hat Ecosystem Catalog
- Calculadora de valor Red Hat
- Documentação
Experimente, compre, venda
Comunicação
- Contate o setor de vendas
- Fale com o Atendimento ao Cliente
- Contate o setor de treinamento
- Redes sociais
Sobre a Red Hat
A Red Hat é a líder mundial em soluções empresariais open source como Linux, nuvem, containers e Kubernetes. Fornecemos soluções robustas que facilitam o trabalho em diversas plataformas e ambientes, do datacenter principal até a borda da rede.
Selecione um idioma
Red Hat legal and privacy links
- Sobre a Red Hat
- Oportunidades de emprego
- Eventos
- Escritórios
- Fale com a Red Hat
- Blog da Red Hat
- Diversidade, equidade e inclusão
- Cool Stuff Store
- Red Hat Summit