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
278
|
---
lastproofread: '2026-03-30'
---
# Firewall
:::{warning}
Due to a boot-time race condition, all interfaces initialize
before the firewall. This temporarily leaves the system open to all traffic
and poses a security risk.
:::
VyOS uses Netfilter. The Netfilter
project developed `iptables` and its successor `nftables` for the Linux
kernel to process packet data flows directly. This extends the concept of
zone-based security to let you manipulate data at multiple stages after the
network interface and driver accept it, and before sending it to its
destination (for example, a web server or another device).
The following is a simplified traffic flow diagram based on Netfilter
packet flow.
This diagram provides an overview of how packets are processed and the
possible paths traffic can take.
:::{figure} /_static/images/firewall-gral-packet-flow.webp
:::
The main points regarding packet flow and terminology in VyOS firewall
are:
- **Bridge Port?**: Choose the appropriate path based on whether the
interface where the packet was received is part of a bridge.
If the interface where the packet was received is not part of a bridge, the
packet is processed at the **IP Layer**:
```{eval-rst}
* **Prerouting**: The router processes all packets in this stage,
regardless of the destination. You can perform several actions in
this stage, and these actions are also defined in different parts of the
VyOS configuration. Order is important. The relevant configuration that
applies in this stage includes:
* **Firewall prerouting**: Rules you define under ``set firewall
[ipv4 | ipv6] prerouting raw...``. The system processes all rules in
this section before the connection tracking subsystem.
* **Conntrack Ignore**: Rules you define under ``set system conntrack
ignore [ipv4 | ipv6] ...``. You can configure this section with
``firewall [ipv4 | ipv6] prerouting ...``. For compatibility reasons,
this feature is supported, but will be deprecated in the future.
* **Policy Route**: Rules you define under ``set policy [route |
route6] ...``.
* **Destination NAT**: Rules you define under ``set [nat | nat66]
destination...``.
* **Destination is the router?**: Choose the appropriate path based on the
destination IP address. Transit traffic continues to **forward**, while
traffic destined for the router continues to **input**.
* **Input**: The stage where you filter and control traffic destined for
the router itself. This is where you enforce all rules for securing the
router. This includes IPv4 and IPv6 filtering rules, defined in:
* ``set firewall ipv4 input filter ...``.
* ``set firewall ipv6 input filter ...``.
* **Forward**: The stage where you filter and control transit traffic.
This includes IPv4 and IPv6 filtering rules, defined in:
* ``set firewall ipv4 forward filter ...``.
* ``set firewall ipv6 forward filter ...``.
* **Output**: The stage where you filter and control traffic that the
router originates. Note that this traffic comes from either a new
connection that an internal process on the VyOS router (such as NTP)
originates or a response to traffic the router receives externally through
**input** (for example, a response to an SSH login attempt). This includes
IPv4 and IPv6 rules, and two different sections apply:
* **Output Prerouting**: ``set firewall [ipv4 | ipv6] output
raw ...``. As described in **Prerouting**, the system processes
rules in this section before the connection tracking subsystem.
* **Output Filter**: ``set firewall [ipv4 | ipv6] output filter ...``.
* **Postrouting**: As in **Prerouting**, you can perform several actions
defined in different parts of VyOS configuration in this stage. This
includes:
* **Source NAT**: Rules you define under ``set [nat | nat66]
source...``.
```
If the interface where the packet was received is part of a bridge, the
packet is processed at the **Bridge Layer**:
```{eval-rst}
* **Prerouting (Bridge)**: The bridge processes all packets it receives in
this stage, regardless of the destination. First, you can apply filters
here, or you can configure rules that ignore the connection tracking
system. The relevant configuration that applies:
* ``set firewall bridge prerouting filter ...``.
* **Forward (Bridge)**: The stage where you filter and control traffic
that passes through the bridge:
* ``set firewall bridge forward filter ...``.
* **Input (Bridge)**: The stage where you filter and control traffic
destined for the bridge itself:
* ``set firewall bridge input filter ...``.
* **Output (Bridge)**: The stage where you filter and control traffic that
the bridge originates:
* ``set firewall bridge output filter ...``.
```
The following is the overall structure of the VyOS firewall CLI:
```none
- set firewall
* bridge
- forward
+ filter
- input
+ filter
- output
+ filter
- prerouting
+ filter
- name
+ custom_name
* flowtable
- custom_flow_table
+ ...
* global-options
+ all-ping
+ broadcast-ping
+ ...
* group
- address-group
- ipv6-address-group
- network-group
- ipv6-network-group
- interface-group
- mac-group
- port-group
- domain-group
* ipv4
- forward
+ filter
- input
+ filter
- output
+ filter
+ raw
- prerouting
+ raw
- name
+ custom_name
* ipv6
- forward
+ filter
- input
+ filter
- output
+ filter
+ raw
- prerouting
+ raw
- ipv6-name
+ custom_name
* zone
- custom_zone_name
+ ...
```
Here is a list of VyOS firewall CLI subcommands and their
corresponding pages in the documentation:
```{cfgcmd} set firewall bridge ...
Configure bridge firewall rules for traffic at the bridge layer.
See the Bridge Firewall Configuration page for detailed information.
```
```{cfgcmd} set firewall flowtable ...
Configure firewall flowtables for stateful connection tracking and rules.
See the Flowtables Firewall Configuration page for detailed information.
```
```{cfgcmd} set firewall global-options ...
Configure global firewall options such as ``all-ping``, ``broadcast-ping``,
``syn-cookies``, and other system-wide firewall settings.
See the Global Firewall Options page for detailed information.
```
```{cfgcmd} set firewall group ...
Organize firewall rules by creating reusable address, network, interface,
MAC, port, and domain groups. Use groups in multiple rules to simplify
configuration and maintenance.
See the Firewall Groups page for detailed information.
```
```{cfgcmd} set firewall ipv4 ...
Configure IPv4-specific firewall rules.
See the IPv4 Firewall Configuration page for detailed information.
```
```{cfgcmd} set firewall ipv6 ...
Configure IPv6-specific firewall rules.
See the IPv6 Firewall Configuration page for detailed information.
```
```{cfgcmd} set firewall zone ...
Configure zone-based firewall policies for controlling traffic between
different network zones.
See the Zone-Based Firewall Configuration page for detailed information.
```
For more information on firewall configuration, see the following pages:
```{toctree}
:includehidden: true
:maxdepth: 1
global-options
groups
bridge
ipv4
ipv6
flowtables
```
:::{note}
For more information on Netfilter hooks and Linux networking packet flows,
see the [Netfilter-Hooks](<https://wiki.nftables.org/wiki-nftables/index.php/Netfilter_hooks>)
documentation.
:::
## Zone-Based firewall
```{toctree}
:includehidden: true
:maxdepth: 1
zone
```
With zone-based firewalls, a new concept applies. In addition to the standard
in and out traffic flows, a local flow enables traffic originating from and
destined to the router itself. This means you must configure additional rules to
secure the firewall from the network, in addition to the existing inbound and
outbound rules.
To configure VyOS with zone-based firewall, see
{doc}`Zone-Based Firewall Configuration </configuration/firewall/zone>`.
As the following example image shows, you must configure rules to allow or block
traffic to or from the services running on the device that have open
connections on that interface.
:::{figure} /_static/images/firewall-zonebased.webp
:::
|