1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
---
myst:
html_meta:
description: |
The VyOS firewall filters the traffic that the router receives,
forwards, or generates. It matches packets by their properties,
provides groups for reuse in rules, and includes a zone-based
firewall. It operates at an IP layer and a Bridge layer, and
processes packets at the processing points of each layer.
keywords: firewall, zone-based firewall, ip layer, bridge layer
---
(firewall)=
# Firewall
The VyOS firewall filters traffic that the router **receives**, **forwards**,
or **generates**. It matches packets by their addresses, ports, protocols,
connection state, and other properties; groups addresses, networks,
interfaces, and ports for reuse in rules; divides interfaces into zones;
and offloads forwarded connections to a flowtable.
The firewall operates at two processing layers. The layer at which the
firewall begins processing a packet depends on the interface that
received it:
- **IP layer**: Processes packets received on interfaces that are not bridge
member interfaces.
- **Bridge layer**: Processes packets received on bridge member interfaces.
Packets that the router generates have no receiving interface. The
firewall begins processing them at the IP layer. The firewall can
continue processing a packet at another layer, for example, when the
router sends the packet out through a bridge.
At each layer, the firewall processes packets at specific processing
points. The points at which a packet is processed depend on its source
and destination. By default, firewall rules apply to matching packets on
any interface of their processing layer.
```{warning}
During boot, the router configures interfaces before it applies the
firewall rules. Until then, the firewall does not filter traffic that
arrives on interfaces, which poses a security risk.
```
## Packet flow
The following diagram shows how the router processes packets and the
paths that traffic can take.
```{figure} /_static/images/firewall-gral-packet-flow.webp
```
### IP layer
The IP layer processes packets received on interfaces that are not
**bridge member interfaces**, packets that the router generates, and packets
that the Bridge layer passes on. Depending on its source and
destination, the firewall processes a packet at different processing
points, as outlined in the following table:
```{list-table}
:header-rows: 1
:widths: 12 18 22 48
* - Processing point (hook)
- Processing order
- Packet source or destination
- Configuration applied
* - prerouting
- First processing point at the IP layer for received packets.
- Received packets, regardless of their destination.
- **Firewall prerouting raw**: Rules that match received packets and apply an
action to them before connection tracking, such as dropping them or
exempting\* them from connection tracking.\
You define the rules under `set firewall [ipv4 | ipv6] prerouting raw ...`.
**Source validation**: Drops received packets whose source address fails the
reverse path check.\
You set the check mode under
`set firewall global-options source-validation ...` and
`set firewall global-options ipv6-source-validation ...`.
**Policy route**: Rules that match packets received on the interfaces you
specify and assign the matching packets to a routing table or
{abbr}`VRF (Virtual Routing and Forwarding)`, or modify packet properties.\
You define the rules under `set policy [route | route6] ...`.
**Destination {abbr}`NAT (Network Address Translation)`**: Rules that match
received packets and translate their destination address and port, or, for
IPv4, redirect them to the router itself.\
You define the rules under `set [nat | nat66] destination ...`.
* - input
- After the prerouting processing point.
- Packets whose destination is the router.
- **Global state policy**: Accepts, drops, or rejects packets according to the
state of their connection, before the input rules.\
You define the policy under `set firewall global-options state-policy ...`.
**Firewall input**: Rules that match received packets and apply an action to
them, such as accepting or dropping them.\
You define the rules under `set firewall [ipv4 | ipv6] input filter ...`.
**Zone policy**: Rules that match packets according to the zone of the
receiving interface and apply an action to them, such as accepting or
dropping them, after the input rules.\
You define the rules under `set firewall zone ...`.
* - forward
- After the prerouting processing point.
- Packets that the router routes through to another destination.
- **Global state policy**: Accepts, drops, or rejects packets according to the
state of their connection, before the forward rules.\
You define the policy under `set firewall global-options state-policy ...`.
**Firewall forward**: Rules that match received packets and apply an action
to them, such as accepting or dropping them.\
You define the rules under `set firewall [ipv4 | ipv6] forward filter ...`.
**Zone policy**: Rules that match packets according to the zones of the
receiving and outgoing interfaces and apply an action to them, such as
accepting or dropping them, after the forward rules.\
You define the rules under `set firewall zone ...`.
* - output
- First processing point at the IP layer for packets that the router
generates.
- Packets that the router generates.
- **Firewall output raw**: Rules that match generated packets and apply an
action to them before connection tracking, such as dropping them or
exempting\* them from connection tracking.\
You define the rules under `set firewall [ipv4 | ipv6] output raw ...`.
**Global state policy**: Accepts, drops, or rejects packets according to the
state of their connection, before the output filter rules.\
You define the policy under `set firewall global-options state-policy ...`.
**Firewall output filter**: Rules that match generated packets and apply an
action to them, such as accepting or dropping them.\
You define the rules under `set firewall [ipv4 | ipv6] output filter ...`.
**Zone policy**: Rules that match packets according to the zone of the
outgoing interface and apply an action to them, such as accepting or
dropping them, after the output filter rules.\
You define the rules under `set firewall zone ...`.
* - \-
- After the forward or output processing point.
- Packets that the router sends out, both transit packets and packets
that the router generates.
- **Source NAT**: Rules that match packets and translate their source address
and port.\
You define the rules under `set [nat | nat66] source ...`.
```
\* To exempt packets from connection tracking, you can also define rules
under `set system conntrack ignore [ipv4 | ipv6] ...`. These rules apply
to both received and generated packets and are maintained for
compatibility. VyOS recommends rules with the `notrack` action under
`set firewall [ipv4 | ipv6] prerouting raw` and `set firewall [ipv4 |
ipv6] output raw` instead, as `conntrack ignore` rules are expected to
be removed in the future.
At the IP layer, the firewall has no processing point after the forward
or output processing point. Source NAT applies after these points and is
configured separately under `set nat source` and `set nat66 source`.
After source NAT, a packet that the router sends out through a bridge is
passed to the Bridge layer, which processes it at its output processing
point.
After the router offloads a connection to a flowtable, the firewall does
not process the subsequent packets of that connection at any processing
point of the IP layer.
### Bridge layer
The Bridge layer processes packets received on **bridge member interfaces**
and packets that the IP layer passes on to send out through a bridge.
Depending on its source and destination, the firewall processes a packet
at different processing points, as outlined in the following table:
```{list-table}
:header-rows: 1
:widths: 12 18 22 48
* - Processing point (hook)
- Processing order
- Packet source or destination
- Configuration applied
* - prerouting
- First processing point at the Bridge layer for received packets.
- Received packets, regardless of their destination.
- **Bridge firewall prerouting**: Rules that match received packets and apply
an action to them, such as accepting or dropping them, or exempting them
from connection tracking.\
You define the rules under `set firewall bridge prerouting filter ...`.
* - input
- After the prerouting processing point.
- Packets whose destination is the bridge.
- **Global state policy**: Accepts, drops, or rejects packets according to the
state of their connection, before the input rules.\
You define the policy under `set firewall global-options state-policy ...`.
**Bridge firewall input**: Rules that match received packets and apply an
action to them, such as accepting or dropping them.\
You define the rules under `set firewall bridge input filter ...`.
* - forward
- After the prerouting processing point.
- Packets that the bridge forwards between its member interfaces.
- **Global state policy**: Accepts, drops, or rejects packets according to the
state of their connection, before the forward rules.\
You define the policy under `set firewall global-options state-policy ...`.
**Bridge firewall forward**: Rules that match received packets and apply an
action to them, such as accepting or dropping them.\
You define the rules under `set firewall bridge forward filter ...`.
* - output
- First processing point at the Bridge layer for packets that the
router sends out through a bridge.
- Packets that the router sends out through a bridge, both routed
packets and packets that the router generates.
- **Global state policy**: Accepts, drops, or rejects packets according to the
state of their connection, before the output rules.\
You define the policy under `set firewall global-options state-policy ...`.
**Bridge firewall output**: Rules that match outgoing packets and apply an
action to them, such as accepting or dropping them.\
You define the rules under `set firewall bridge output filter ...`.
```
After the bridge input processing point, accepted IPv4 and IPv6 packets
are passed to the IP layer, which processes them starting at IP
prerouting.
## Zone-based firewall
The zone-based firewall is not a separate service. It is part of the
same firewall, and you can use it together with the other firewall
rules. It lets you group interfaces into zones and assign rules to
control traffic between them. The local zone represents the router
itself.
The zone-based firewall processes packets at the following processing
points of the IP layer:
```{list-table}
:header-rows: 1
:widths: 55 45
* - Traffic
- Processing point
* - From one zone to another zone
- forward
* - From a zone to the local zone
- input
* - From the local zone to a zone
- output
```
At each point, the firewall applies zone rules after the input, forward,
or output filter rules.
## Firewall configuration
For information on firewall configuration, see the following pages:
```{toctree}
:includehidden: true
:maxdepth: 1
global-options
groups
bridge
ipv4
ipv6
flowtables
zone
```
|