|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: "Concepts" |
| 4 | +--- |
| 5 | + |
| 6 | +## Introduction |
| 7 | + |
| 8 | +Firewalld is a simple, stateful, zone-based firewall. Policies and zones |
| 9 | +are used to organize firewall rules. The network is logically divided |
| 10 | +into zones and the traffic flowing between them can be governed by |
| 11 | +policies. |
| 12 | + |
| 13 | +This looks like the following: |
| 14 | + |
| 15 | +```mermaid |
| 16 | +graph LR; |
| 17 | + A("internal<br>(zone)") -->|policyA| B("external<br>(zone)") |
| 18 | + B -->|policyB| A |
| 19 | +``` |
| 20 | + |
| 21 | +Policies may apply firewall rules to all traffic types. This includes |
| 22 | +filtering input, forwarded, and output traffic; as well as performing |
| 23 | +network address translations (NAT). |
| 24 | + |
| 25 | +## Zone Principles |
| 26 | + |
| 27 | +Firewalld follows some strict principles in regards to zones. |
| 28 | + |
| 29 | +1. traffic ingresses one and only one zone |
| 30 | +2. traffic egresses one and only one zone |
| 31 | +3. a zone defines a level of trust |
| 32 | +4. intra-zone (within the same zone) is allowed by default |
| 33 | +5. inter-zone (zone to zone) is denied by default |
| 34 | + |
| 35 | +Principle 4 and 5 are actually a consequence of Principle 3. |
| 36 | + |
| 37 | +Principle 4 is configurable via zone option `--remove-forward`. |
| 38 | +Principle 5 is configurable by adding new policies. |
| 39 | + |
| 40 | +## Firewall Rules |
| 41 | + |
| 42 | +Policies apply firewall rules in a stateful, unidirectional manner. This |
| 43 | +means you only need to consider one direction of the traffic. The |
| 44 | +traffic's return path is implicitly allowed due to firewalld's stateful |
| 45 | +filtering. |
| 46 | + |
| 47 | +Policies are associated with an ingress zone and an egress zone. The |
| 48 | +ingress zone is where the traffic originated (received). The egress zone |
| 49 | +is where the traffic leaves (sent). |
| 50 | + |
| 51 | +In this example, `myPolicy` will filter forwarded traffic originating |
| 52 | +from the `internal` ingress zone and destined for the `external` egress |
| 53 | +zone. |
| 54 | + |
| 55 | +`myPolicy` is created with these commands: |
| 56 | + |
| 57 | +``` |
| 58 | +# firewall-cmd --permanent --new-policy myPolicy |
| 59 | +# firewall-cmd --permanent --policy myPolicy --add-ingress-zone internal |
| 60 | +# firewall-cmd --permanent --policy myPolicy --add-egress-zone external |
| 61 | +``` |
| 62 | + |
| 63 | +And conceptually looks like this: |
| 64 | + |
| 65 | +```mermaid |
| 66 | +graph LR; |
| 67 | + A("internal<br>(zone)") -->|myPolicy| B("external<br>(zone)") |
| 68 | +``` |
| 69 | + |
| 70 | +This is a common scenario for a home network. To allow the LAN |
| 71 | +(internal) access the internet you can allow all traffic by setting the |
| 72 | +default target of the policy using `--set-target`. |
| 73 | + |
| 74 | +``` |
| 75 | +# firewall-cmd --permanent --policy myPolicy --set-target ACCEPT |
| 76 | +# firewall-cmd --reload |
| 77 | +``` |
| 78 | + |
| 79 | +Alternatively, a strict network may allow only a subset of traffic. In |
| 80 | +this example, only `http` and `https` are allowed; other traffic will be |
| 81 | +rejected. |
| 82 | + |
| 83 | +``` |
| 84 | +# firewall-cmd --permanent --policy myPolicy --add-service http |
| 85 | +# firewall-cmd --permanent --policy myPolicy --add-service https |
| 86 | +# firewall-cmd --reload |
| 87 | +``` |
| 88 | + |
| 89 | +## Zone Firewall Rules |
| 90 | + |
| 91 | +In addition to logically separating the network, zones implicitly |
| 92 | +provide a policy for traffic destined to the host running firewalld |
| 93 | +(input). This is useful for simple use cases where end-stations provide |
| 94 | +services, e.g. a web server. In these scenarios explicit policies are |
| 95 | +not necessary. |
| 96 | + |
| 97 | +This looks like the following: |
| 98 | + |
| 99 | +```mermaid |
| 100 | +graph LR; |
| 101 | + A("internal<br>(zone)") -->|implicit<br>zone policy| B("HOST") |
| 102 | +``` |
| 103 | + |
| 104 | +This example allows `https` for clients in the internal zone. |
| 105 | + |
| 106 | +``` |
| 107 | +# firewall-cmd --permanent --zone internal --add-service https |
| 108 | +# firewall-cmd --reload |
| 109 | +``` |
| 110 | + |
| 111 | +## Runtime and Permanent Configuration |
| 112 | + |
| 113 | +Firewalld maintains separate runtime and permanent configurations. This |
| 114 | +allows runtime only changes. The runtime configuration does not persist |
| 115 | +after a firewalld reload or restart. At startup it is populated from the |
| 116 | +permanent configuration. |
| 117 | + |
| 118 | +This example modifies the `permanent` configuration. Then it uses the |
| 119 | +`--reload` option to reload firewalld, thus making the runtime and |
| 120 | +permanent configurations identical. |
| 121 | + |
| 122 | +``` |
| 123 | +# firewall-cmd --permanent --policy myPolicy --add-service http |
| 124 | +# firewall-cmd --permanent --policy myPolicy --add-service https |
| 125 | +# firewall-cmd --reload |
| 126 | +``` |
| 127 | + |
| 128 | +It's worth noting that during a reload firewalld will maintain existing |
| 129 | +connections. That is, they experience no traffic interruption. |
| 130 | + |
| 131 | +To modify the `runtime` configuration, you simply omit the `--permanent` |
| 132 | +option. |
| 133 | + |
| 134 | +``` |
| 135 | +# firewall-cmd --policy myPolicy --add-service ssh |
| 136 | +``` |
| 137 | + |
| 138 | +If you followed that command with a `--reload`, then the `ssh` service |
| 139 | +would not be present in `myPolicy`. |
0 commit comments