Este conteúdo não está disponível no idioma selecionado.
Chapter 9. Configuring firewalld using System Roles
You can use the firewall System Role to configure settings of the firewalld service on multiple clients at once. This solution:
- Provides an interface with efficient input settings.
-
Keeps all intended
firewalldparameters in one place.
After you run the firewall role on the control node, the System Role applies the firewalld parameters to the managed node immediately and makes them persistent across reboots.
9.1. Introduction to the firewall RHEL System Role Copiar o linkLink copiado para a área de transferência!
RHEL System Roles is a set of contents for the Ansible automation utility. This content together with the Ansible automation utility provides a consistent configuration interface to remotely manage multiple systems.
The rhel-system-roles.firewall role from the RHEL System Roles was introduced for automated configurations of the firewalld service. The rhel-system-roles package contains this System Role, and also the reference documentation.
To apply the firewalld parameters on one or more systems in an automated fashion, use the firewall System Role variable in a playbook. A playbook is a list of one or more plays that is written in the text-based YAML format.
You can use an inventory file to define a set of systems that you want Ansible to configure.
With the firewall role you can configure many different firewalld parameters, for example:
- Zones.
- The services for which packets should be allowed.
- Granting, rejection, or dropping of traffic access to ports.
- Forwarding of ports or port ranges for a zone.
9.2. Resetting the firewalld settings using the firewall RHEL System Role Copiar o linkLink copiado para a área de transferência!
With the firewall RHEL system role, you can reset the firewalld settings to their default state. If you add the previous:replaced parameter to the variable list, the System Role removes all existing user-defined settings and resets firewalld to the defaults. If you combine the previous:replaced parameter with other settings, the firewall role removes all existing settings before applying new ones.
Perform this procedure on the Ansible control node.
Prerequisites
- You have prepared the control node and the managed nodes
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on the them. - The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
Procedure
Create a playbook file, for example
~/reset-firewalld.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the playbook:
ansible-playbook ~/configuring-a-dmz.yml
# ansible-playbook ~/configuring-a-dmz.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Run this command as
rooton the managed node to check all the zones:firewall-cmd --list-all-zones
# firewall-cmd --list-all-zonesCopy to Clipboard Copied! Toggle word wrap Toggle overflow
9.3. Forwarding incoming traffic from one local port to a different local port Copiar o linkLink copiado para a área de transferência!
With the firewall role you can remotely configure firewalld parameters with persisting effect on multiple managed hosts.
Perform this procedure on the Ansible control node.
Prerequisites
- You have prepared the control node and the managed nodes
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on the them. - The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
Procedure
Create a playbook file, for example
~/port_forwarding.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the playbook:
ansible-playbook ~/port_forwarding.yml
# ansible-playbook ~/port_forwarding.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
On the managed host, display the
firewalldsettings:firewall-cmd --list-forward-ports
# firewall-cmd --list-forward-portsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
9.4. Configuring ports using System Roles Copiar o linkLink copiado para a área de transferência!
You can use the RHEL firewall System Role to open or close ports in the local firewall for incoming traffic and make the new configuration persist across reboots. For example you can configure the default zone to permit incoming traffic for the HTTPS service.
Perform this procedure on the Ansible control node.
Prerequisites
- You have prepared the control node and the managed nodes
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on the them. - The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
Procedure
Create a playbook file, for example
~/opening-a-port.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
permanent: trueoption makes the new settings persistent across reboots.Run the playbook:
ansible-playbook ~/opening-a-port.yml
# ansible-playbook ~/opening-a-port.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
On the managed node, verify that the
443/tcpport associated with theHTTPSservice is open:firewall-cmd --list-ports
# firewall-cmd --list-ports 443/tcpCopy to Clipboard Copied! Toggle word wrap Toggle overflow
9.5. Configuring a DMZ firewalld zone by using the firewalld RHEL System Role Copiar o linkLink copiado para a área de transferência!
As a system administrator, you can use the firewall System Role to configure a dmz zone on the enp1s0 interface to permit HTTPS traffic to the zone. In this way, you enable external users to access your web servers.
Perform this procedure on the Ansible control node.
Prerequisites
- You have prepared the control node and the managed nodes
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on the them. - The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
Procedure
Create a playbook file, for example
~/configuring-a-dmz.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the playbook:
ansible-playbook ~/configuring-a-dmz.yml
# ansible-playbook ~/configuring-a-dmz.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
On the managed node, view detailed information about the
dmzzone:Copy to Clipboard Copied! Toggle word wrap Toggle overflow