Skip to content

Firewall Management - FirewallD

The FirewallD is a default firewall management tool for Linux operating systems in distributions such as Fedora, Red Hat and CentOS. It acts as a front-end for the Linux kernel packet filtering framework, known as netfilter.

This firewall has some default rules and works with the concept of zones where the allowance of services is done within them.

The table below shows how the network firewall is configured after operating system installation:

RegraComportamento
INPUTLiberado o acesso conexões do tipo RELATED,ESTABLISHED.
FORWARDAceita apenas conexões do tipo RELATED,ESTABLISHED.
OUTPUTNão possui restrições.

firewalld manages a set of rules known as zones. Zones define the type of traffic that will be allowed based on the trust level of the network to which your server is connected. Each zone is tied to an existing network interface on the server.

The command below lists the existing zones:

Terminal window
firewall-cmd --get-zones

Below are the zones available in firewalld in order of trust level:

ZonaDescrição
dropAll packets are discarded.
blockAll packets are rejected.
publicA network you do not know, public.
externalExternal network where the server running firewalld acts as a
gatewayfor the internal network. It is configured with masquerading to preserve the internal network’s privacy.
internalIt is the internal part of the network. Devices on this network have a higher level of trust and additional services are available.
dmzDevices that are isolated, that is, that should not have access to your network. Only some incoming connections to these devices are allowed.
workWork devices with additional services allowed.
homeHome devices. These are more known devices and
trusted and that have permission to a few more services than the work zone.
trustedTrusted devices. Practically all services are available to devices in this zone.

The command below lists all existing rules in the firewalld service:

Terminal window
firewall-cmd --list-all

If you want to list only the rules of a specific zone use the —zone option:

Terminal window
firewall-cmd --zone=public --list-all

To modify the firewall input rules on Fedora, we use the firewall-cmd command.

The example below demonstrates how to open ports 80(TCP) and 443(TCP) for access from the public network, permanently, for an HTTP server via the command line:

Terminal window
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=443/tcp
firewall-cmd --set-default-zone=public
firewall-cmd --reload

where:

ParâmetroDescrição
--permanentAdds the rule permanently, that is, after restarting the filter the rules will remain. If this option is omitted the rules are valid until firewalld is restarted.
--zone=publicIt is the untrusted public zone. These are addresses you do not know but may be authorized on a case-by-case basis.
--add-port=80/tcpInformation about the port and protocol that will be added to the public zone.
--reloadReloads the rules preserving the state of connections.
--set-default-zone=publicSets the public zone as the default to be used.

The example below demonstrates how to open the SSH port for the Linux server:

Terminal window
firewall-cmd --permanent --zone=public --add-port=22/tcp
firewall-cmd --set-default-zone=public
firewall-cmd --reload

Below is shown how to allow full access to the server for the network whose origin is 192.168.1.0/24:

Terminal window
firewall-cmd --permanent --zone=public --add-source=127.0.0.1/8
firewall-cmd --reload
ParâmetroDescrição
--permanentAdds the rule permanently, that is, after restarting the filter the rules will remain. If this option is omitted the rules are valid until firewalld is restarted.
--zone=publicIt is the untrusted public zone. These are addresses you do not know but may be authorized on a case-by-case basis.
--add-source=192.168.1.0/24Information about the network or host that will be added to the public zone.
--reloadReloads the rules preserving the state of connections.

For this function it is necessary to have at least 2 network interfaces on the server, one that connects to the public network and another to the internal network.

In the example below, the eth0 interface is connected to the public network and eth1 to the internal network:

Terminal window
firewall-cmd --permanent --zone=internal --add-interface=eth1
firewall-cmd --permanent --zone=public --add-masquerade
firewall-cmd --reload
ParâmetroDescrição
--permanentAdds the rule permanently, that is, after restarting the filter the rules will remain. If
the option is omitted the rules are valid until firewalld is restarted.
--zone=public --zone=internalWe select the public zone to apply masquerading and the internal to indicate the internal network.
--add-masqueradeAdds masquerading in the selected zone.
--reloadReloads the rules preserving the state of connections.

To forward ports from the external network to an address on the internal network, use the commands below:

Terminal window
firewall-cmd --permanent --zone=public --add-forward-port=port=443:proto=tcp:toport=443:toaddr=192.168.1.11
firewall-cmd --reload
ParâmetroDescrição
--permanentAdds the rule permanently, that is, after restarting the filter the rules will remain. If this option is omitted the rules are valid until firewalld is restarted.
--zone=publicIt is the untrusted public zone. These are addresses you do not know but may be authorized on a case-by-case basis.
--add-forward-port=Enables the rule for port forwarding.
port=443Source port.
proto=tcpSource protocol.
toport=443Destination port.
toaddr=192.168.1.11Destination IP on the internal network.
--reloadReloads the rules preserving the state of connections.