summaryrefslogtreecommitdiff
path: root/docs/configuration/firewall/groups.md
blob: c0db60d714f5ddccb3d926791e35825b6b6d4b73 (plain)
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
---
myst:
  html_meta:
    description: |
      Firewall groups are named collections of addresses, networks,
      ports, MAC addresses, interfaces, and domain names that you can
      reference in rules. They cover address, network, interface, port,
      MAC, domain, remote, and dynamic groups, and nested groups.
    keywords: firewall, groups, address group, remote group, dynamic group
---

(firewall-groups-configuration)=

# Firewall groups

Firewall groups are named collections of IP addresses, networks, ports, MAC
addresses, domain names, or interfaces. You can reference a group in firewall,
NAT, and policy route rules as a source or destination match, and an interface
group as an inbound or outbound interface match. Remote and dynamic
groups are available in firewall rules only.

Address, IPv6 address, network, IPv6 network, MAC, port, and interface groups
can include other groups of the same type. A rule that references a group
matches the members of that group and the members of the groups that it
includes.

## Configuration

### Address groups

An **address group** is a named collection of IPv4 addresses and IPv4 address
ranges. An **IPv6 address group** is the IPv6 equivalent.

```{cfgcmd} set firewall group address-group \<name\> address \<ipv4-address | ipv4-range\>

**Add an IPv4 address or address range to the specified address group.**

Repeat the command to add more addresses or ranges to the same group.
```

Example:

```none
set firewall group address-group ADR-INSIDE-v4 address 192.0.2.1
set firewall group address-group ADR-INSIDE-v4 address 198.51.100.1-198.51.100.8
```

```{cfgcmd} set firewall group ipv6-address-group \<name\> address \<ipv6-address | ipv6-range\>

**Add an IPv6 address or address range to the specified IPv6 address group.**

Repeat the command to add more addresses or ranges to the same group.
```

Example:

```none
set firewall group ipv6-address-group ADR-INSIDE-v6 address 2001:db8::1
set firewall group ipv6-address-group ADR-INSIDE-v6 address 2001:db8::10-2001:db8::1f
```

```{cfgcmd} set firewall group address-group \<name\> include \<name\>

**Include another address group in the specified address group.**

A rule that references the specified group matches the members of the specified
group and the members of the included group. The included group remains a
separate group that rules can reference separately.

The included group can itself include other address groups. The included group
must exist, and address groups must not include each other in a circle.
Otherwise, the commit fails.
```

Example:

```none
set firewall group address-group ADR-ALL-v4 include ADR-INSIDE-v4
```

```{cfgcmd} set firewall group ipv6-address-group \<name\> include \<name\>

**Include another IPv6 address group in the specified IPv6 address group.**

A rule that references the specified group matches the members of the specified
group and the members of the included group. The included group remains a
separate group that rules can reference separately.

The included group can itself include other IPv6 address groups. The included
group must exist, and IPv6 address groups must not include each other in a
circle. Otherwise, the commit fails.
```

Example:

```none
set firewall group ipv6-address-group ADR-ALL-v6 include ADR-INSIDE-v6
```

```{cfgcmd} set firewall group address-group \<name\> description \<text\>

**Configure a description for the specified address group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group address-group ADR-INSIDE-v4 description 'Inside hosts'
```

```{cfgcmd} set firewall group ipv6-address-group \<name\> description \<text\>

**Configure a description for the specified IPv6 address group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group ipv6-address-group ADR-INSIDE-v6 description 'Inside hosts'
```

### Remote groups

A **remote group** is a named collection of IPv4 and IPv6 addresses, address
ranges, and networks. The router downloads them from the HTTP or HTTPS URL that
you configure with the `url` option of the remote group.

The file at the URL is a plain text file. Each line holds one entry: an IPv4 or
IPv6 address, an address range, or a network in CIDR notation. A network must be
in canonical form, with no host bits set. For example, `192.0.2.0/24` is valid
and `192.0.2.1/24` is not. The file can contain IPv4 and IPv6 entries together.

The router reads the first word of each line, up to the first space. Separate
an entry from any following text, such as a comment, with a space. The router
ignores:

- Empty lines.
- Lines whose first word is not a valid IPv4 or IPv6 address, range, or network.

The router logs the first word of an ignored line when the word begins with a
letter or a digit. An ignored line whose first word begins with another
character, such as `#`, produces no log message.

The following example shows valid lines:

```none
192.0.2.1
192.0.2.1 # office
198.51.100.0/24
192.0.2.1-192.0.2.254
2001:db8::1
2001:db8:cafe::/48
2001:db8:cafe::1-2001:db8:cafe::ffff
```

The router downloads the file when it applies the firewall configuration and
then at the `interval` of the group or, when no `interval` is configured, at
`resolver-interval` (see `set firewall global-options resolver-interval`).

If a download fails, the router writes a message to the system log and uses the
last downloaded file, which it keeps in persistent storage. The router retries
the download after `resolver-interval`, or after the `interval` of the group, if
configured, whichever is shorter. If the router has not downloaded the file
before, the group has no addresses.

```{cfgcmd} set firewall group remote-group \<name\> url \<url\>

**Configure the URL from which the router downloads the file of the specified
remote group.**

The URL must use the `http` or `https` scheme.

To safely type or past a URL without worrying about having to escape
`?` and `&` characters in a query strings, enter an opening quote (`'`)
before typing or pasting, then close the quote.

You must configure `url` for every remote group. Otherwise, the commit fails.
```

Example:

```none
set firewall group remote-group RMT url 'https://api.example.com/list?key=YOUR_KEY&plaintext'
```

```{cfgcmd} set firewall group remote-group \<name\> interval \<60-2419200 | number+suffix\>

**Configure the interval at which the router downloads the file of the
specified remote group.**

Enter a number of seconds, or a number followed by the suffix `s`, `m`, `h`,
`d`, or `w`, for example `4h`. You can combine units, for example `1h30m`. The
interval must be between 60 seconds and 4 weeks. Otherwise, the configuration
is rejected.

When no `interval` is configured, the router uses `resolver-interval` (see
`set firewall global-options resolver-interval`).
```

Example:

```none
set firewall group remote-group RMT interval 4h
```

```{cfgcmd} set firewall group remote-group \<name\> description \<text\>

**Configure a description for the specified remote group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group remote-group RMT description 'Blocklist'
```

### Network groups

A **network group** is a named collection of IPv4 networks in CIDR notation. An
**IPv6 network group** is the IPv6 equivalent. Both group types can also contain
single hosts. You add a host to a network group with a prefix length of 32 and
to an IPv6 network group with a prefix length of 128.

```{cfgcmd} set firewall group network-group \<name\> network \<ipv4-network\>

**Add an IPv4 network to the specified network group.**

Repeat the command to add more networks to the same group.

A network must be in canonical form, with no host bits set. For example,
`192.0.2.0/24` is valid and `192.0.2.1/24` is not.
```

Example:

```none
set firewall group network-group NET-INSIDE-v4 network 192.0.2.0/24
set firewall group network-group NET-INSIDE-v4 network 198.51.100.0/24
set firewall group network-group NET-INSIDE-v4 network 203.0.113.10/32
```

```{cfgcmd} set firewall group ipv6-network-group \<name\> network \<ipv6-network\>

**Add an IPv6 network to the specified IPv6 network group.**

Repeat the command to add more networks to the same group.

A network must be in canonical form, with no host bits set. For example,
`2001:db8::/64` is valid and `2001:db8::1/64` is not.
```

Example:

```none
set firewall group ipv6-network-group NET-INSIDE-v6 network 2001:db8::/64
set firewall group ipv6-network-group NET-INSIDE-v6 network 2001:db8:1::10/128
```

```{cfgcmd} set firewall group network-group \<name\> include \<name\>

**Include another network group in the specified network group.**

A rule that references the specified group matches the members of the specified
group and the members of the included group. The included group remains a
separate group that rules can reference separately.

The included group can itself include other network groups. The included group
must exist, and network groups must not include each other in a circle.
Otherwise, the commit fails.
```

Example:

```none
set firewall group network-group NET-ALL-v4 include NET-INSIDE-v4
```

```{cfgcmd} set firewall group ipv6-network-group \<name\> include \<name\>

**Include another IPv6 network group in the specified IPv6 network group.**

A rule that references the specified group matches the members of the specified
group and the members of the included group. The included group remains a
separate group that rules can reference separately.

The included group can itself include other IPv6 network groups. The included
group must exist, and IPv6 network groups must not include each other in a
circle. Otherwise, the commit fails.
```

Example:

```none
set firewall group ipv6-network-group NET-ALL-v6 include NET-INSIDE-v6
```

```{cfgcmd} set firewall group network-group \<name\> description \<text\>

**Configure a description for the specified network group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group network-group NET-INSIDE-v4 description 'Inside networks'
```

```{cfgcmd} set firewall group ipv6-network-group \<name\> description \<text\>

**Configure a description for the specified IPv6 network group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group ipv6-network-group NET-INSIDE-v6 description 'Inside networks'
```

### Interface groups

An **interface group** is a named collection of interfaces. You reference an
interface group in the inbound interface match or the outbound interface match
of a rule. The rule then matches packets by the receiving interface or the
outgoing interface, and the packet matches if that interface is a member of the
group. To match all other interfaces, prepend `!` to the group name in the rule,
for example `outbound-interface group !LAN`.

```{cfgcmd} set firewall group interface-group \<name\> interface \<interface\>

**Add an interface to the specified interface group.**

Repeat the command to add more interfaces to the same group.
```

Example:

```none
set firewall group interface-group LAN interface eth1
```

```{cfgcmd} set firewall group interface-group \<name\> include \<name\>

**Include another interface group in the specified interface group.**

A rule that references the specified group matches the members of the specified
group and the members of the included group. The included group remains a
separate group that rules can reference separately.

The included group can itself include other interface groups. The included
group must exist, and interface groups must not include each other in a circle.
```

Example:

```none
set firewall group interface-group LAN-ALL include LAN
```

```{cfgcmd} set firewall group interface-group \<name\> description \<text\>

**Configure a description for the specified interface group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group interface-group LAN description 'Inside interfaces'
```

### Port groups

A **port group** is a named collection of ports and port ranges. A rule that
references a port group must set `protocol` to `tcp`, `udp`, or `tcp_udp`.
Otherwise, the commit fails. To match different ports for TCP and UDP, create a
port group and a rule for each protocol.

```{cfgcmd} set firewall group port-group \<name\> port \<port-number | port-range | service-name\>

**Add a port or a port range to the specified port group.**

Enter a port number from 1 to 65535, a port range such as `5000-5010`, or a
service name defined in `/etc/services`, such as `http`.

The first port of a range must be less than or equal to the last port.

Repeat the command to add more ports or ranges to the same group.
```

Example:

```none
set firewall group port-group PORT-TCP-SERVER1 port http
set firewall group port-group PORT-TCP-SERVER1 port 443
set firewall group port-group PORT-TCP-SERVER1 port 5000-5010
```

```{cfgcmd} set firewall group port-group \<name\> include \<name\>

**Include another port group in the specified port group.**

A rule that references the specified group matches the members of the specified
group and the members of the included group. The included group remains a
separate group that rules can reference separately.

The included group can itself include other port groups. The included group
must exist, and port groups must not include each other in a circle. Otherwise,
the commit fails.
```

Example:

```none
set firewall group port-group PORT-ALL include PORT-TCP-SERVER1
```

```{cfgcmd} set firewall group port-group \<name\> description \<text\>

**Configure a description for the specified port group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group port-group PORT-TCP-SERVER1 description 'Server 1 ports'
```

### MAC groups

A **MAC group** is a named collection of MAC addresses. A rule that references a
MAC group matches packets whose source or destination MAC address is a member of
the group.

```{cfgcmd} set firewall group mac-group \<name\> mac-address \<mac-address\>

**Add a MAC address to the specified MAC group.**

Repeat the command to add more MAC addresses to the same group.
```

Example:

```none
set firewall group mac-group MAC-G01 mac-address 00:00:5e:00:53:02
```

```{cfgcmd} set firewall group mac-group \<name\> include \<name\>

**Include another MAC group in the specified MAC group.**

A rule that references the specified group matches the members of the specified
group and the members of the included group. The included group remains a
separate group that rules can reference separately.

The included group can itself include other MAC groups. The included group must
exist, and MAC groups must not include each other in a circle. Otherwise, the
commit fails.
```

Example:

```none
set firewall group mac-group MAC-ALL include MAC-G01
```

```{cfgcmd} set firewall group mac-group \<name\> description \<text\>

**Configure a description for the specified MAC group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group mac-group MAC-G01 description 'Office devices'
```

### Domain groups

A **domain group** is a named collection of domain names. The router resolves
the domain names to IPv4 and IPv6 addresses at `resolver-interval` (see
`set firewall global-options resolver-interval`). A rule that references a
domain group matches packets whose source or destination address is an address
of a domain name in that group. A domain group name must begin with a letter or
an underscore.

```{cfgcmd} set firewall group domain-group \<name\> address \<domain\>

**Add a domain name to the specified domain group.**

A domain name can contain letters, digits, hyphens, and dots, and must start
with a letter or a digit.

Repeat the command to add more domain names to the same group.
```

Example:

```none
set firewall group domain-group DOM address example.com
set firewall group domain-group DOM address www.example.net
```

```{cfgcmd} set firewall group domain-group \<name\> description \<text\>

**Configure a description for the specified domain group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group domain-group DOM description 'Update servers'
```

### Dynamic address groups

A **dynamic address group** is a named collection of the source or destination
IP addresses of packets that rules match. A rule adds these addresses to the
group when you configure `add-address-to-group` in the rule and name the group.
Several rules can add addresses to the same group.

You can reference the group as a source or destination match in firewall rules.
The router removes all addresses from dynamic address groups whenever it
applies the firewall configuration.

#### Define a dynamic address group

Dynamic address groups support both IPv4 and IPv6 families.

```{cfgcmd} set firewall group dynamic-group address-group \<name\>

**Define a dynamic IPv4 address group.**
```

Example:

```none
set firewall group dynamic-group address-group ALLOWED
```

```{cfgcmd} set firewall group dynamic-group ipv6-address-group \<name\>

**Define a dynamic IPv6 address group.**

The name must begin with a letter or a digit.
```

Example:

```none
set firewall group dynamic-group ipv6-address-group ALLOWED-v6
```

```{cfgcmd} set firewall group dynamic-group address-group \<name\> description \<text\>

**Configure a description for the specified dynamic address group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group dynamic-group address-group ALLOWED description 'Hosts that completed knocking'
```

```{cfgcmd} set firewall group dynamic-group ipv6-address-group \<name\> description \<text\>

**Configure a description for the specified dynamic IPv6 address group.**

The description can contain up to 255 characters.
```

Example:

```none
set firewall group dynamic-group ipv6-address-group ALLOWED-v6 description 'Hosts that completed knocking'
```

#### Add addresses to a dynamic address group

After you define dynamic address groups, reference them with
`add-address-to-group` in firewall rules to add addresses to them. A rule can
add the source address, the destination address, or both. The rule must
reference an existing dynamic address group of the matching family: IPv4 rules
use `dynamic-group address-group`, and IPv6 rules use
`dynamic-group ipv6-address-group`. Otherwise, the commit fails.

```{cfgcmd} set firewall [ipv4 | ipv6] [forward | input | output] filter rule \<1-999999\> add-address-to-group source-address address-group \<name\>
```

```{cfgcmd} set firewall [ipv4 | ipv6] name \<name\> rule \<1-999999\> add-address-to-group source-address address-group \<name\>
```

```{cfgcmd} set firewall [ipv4 | ipv6] [prerouting | output] raw rule \<1-999999\> add-address-to-group source-address address-group \<name\>

**Add the source address of the packets that the rule matches to the
specified dynamic address group.**
```

Example:

```none
set firewall ipv4 input filter rule 10 add-address-to-group source-address address-group ALLOWED
set firewall ipv4 name KNOCK rule 10 add-address-to-group source-address address-group ALLOWED
set firewall ipv4 prerouting raw rule 10 add-address-to-group source-address address-group ALLOWED
set firewall ipv6 input filter rule 10 add-address-to-group source-address address-group ALLOWED-v6
set firewall ipv6 name KNOCK6 rule 10 add-address-to-group source-address address-group ALLOWED-v6
set firewall ipv6 prerouting raw rule 10 add-address-to-group source-address address-group ALLOWED-v6
```

```{cfgcmd} set firewall [ipv4 | ipv6] [forward | input | output] filter rule \<1-999999\> add-address-to-group destination-address address-group \<name\>
```

```{cfgcmd} set firewall [ipv4 | ipv6] name \<name\> rule \<1-999999\> add-address-to-group destination-address address-group \<name\>
```

```{cfgcmd} set firewall [ipv4 | ipv6] [prerouting | output] raw rule \<1-999999\> add-address-to-group destination-address address-group \<name\>

**Add the destination address of the packets that the rule matches to the
specified dynamic address group.**
```

Example:

```none
set firewall ipv4 forward filter rule 10 add-address-to-group destination-address address-group SEEN-SERVERS
set firewall ipv4 name KNOCK rule 20 add-address-to-group destination-address address-group SEEN-SERVERS
set firewall ipv4 prerouting raw rule 10 add-address-to-group destination-address address-group SEEN-SERVERS
set firewall ipv6 forward filter rule 10 add-address-to-group destination-address address-group SEEN-SERVERS-v6
set firewall ipv6 name KNOCK6 rule 20 add-address-to-group destination-address address-group SEEN-SERVERS-v6
set firewall ipv6 prerouting raw rule 10 add-address-to-group destination-address address-group SEEN-SERVERS-v6
```

#### Set a timeout for added addresses

You can set a timeout for the addresses that a rule adds to a dynamic address
group. The router removes an address with a timeout from the group when the
timeout expires. An address that has no timeout remains in the group until the
router removes all addresses from dynamic address groups.

```{cfgcmd} set firewall [ipv4 | ipv6] [forward | input | output] filter rule \<1-999999\> add-address-to-group [destination-address | source-address] timeout \<number+suffix\>
```

```{cfgcmd} set firewall [ipv4 | ipv6] name \<name\> rule \<1-999999\> add-address-to-group [destination-address | source-address] timeout \<number+suffix\>
```

```{cfgcmd} set firewall [ipv4 | ipv6] [prerouting | output] raw rule \<1-999999\> add-address-to-group [destination-address | source-address] timeout \<number+suffix\>

**Configure how long an address that the rule adds remains in the dynamic
address group.**

Specify the timeout as a number followed by `s` (seconds), `m` (minutes),
`h` (hours), or `d` (days).

Set a timeout for the source address together with the command that adds the
source address to a dynamic address group. Set a timeout for the destination
address together with the command that adds the destination address to a
dynamic address group. Otherwise, the commit fails.
```

In the following example, the rule adds the source address to group `A` for two
minutes and the destination address to group `B` for one hour:

```none
set firewall ipv4 input filter rule 10 add-address-to-group source-address address-group A
set firewall ipv4 input filter rule 10 add-address-to-group source-address timeout 2m
set firewall ipv4 input filter rule 10 add-address-to-group destination-address address-group B
set firewall ipv4 input filter rule 10 add-address-to-group destination-address timeout 1h
```

#### Reference a dynamic address group in a rule

You reference a dynamic address group in the source or destination of IPv4 and
IPv6 firewall rules, like other groups. A rule matches packets whose source or
destination IP address is in a dynamic address group.

Example:

```none
set firewall ipv4 input filter rule 10 source group dynamic-address-group ALLOWED
set firewall ipv6 input filter rule 10 destination group dynamic-address-group BLOCKED
```

## Operation

```{opcmd} show firewall group

**Show all firewall groups.**
```

```{opcmd} show firewall group \<name\>

**Show the firewall groups with the specified name.**

The `<name>` must match the name of the group exactly. Groups of different types
can have the same name, and the command shows all of them.
```

```{opcmd} show firewall group detail

**Show all firewall groups with the description of each group.**
```

```{opcmd} show firewall group \<name\> detail

**Show the firewall groups with the specified name and the description of each
group.**

The `<name>` must match the name of the group exactly. Groups of different types
can have the same name, and the command shows all of them.
```

## Examples

### Create and use firewall groups

The following commands create an address group, two network groups, an interface
group, and a port group:

```none
set firewall group address-group SERVERS address 198.51.100.101
set firewall group address-group SERVERS address 198.51.100.102
set firewall group network-group TRUSTEDv4 network 192.0.2.0/30
set firewall group network-group TRUSTEDv4 network 203.0.113.128/25
set firewall group ipv6-network-group TRUSTEDv6 network 2001:db8::/64
set firewall group interface-group LAN interface eth2.2001
set firewall group interface-group LAN interface bond0
set firewall group port-group PORT-SERVERS port http
set firewall group port-group PORT-SERVERS port 443
set firewall group port-group PORT-SERVERS port 5000-5010
```

The following commands reference the groups in firewall, NAT, and policy route
rules:

```none
set firewall ipv4 output filter rule 10 action accept
set firewall ipv4 output filter rule 10 outbound-interface group !LAN
set firewall ipv4 forward filter rule 20 action accept
set firewall ipv4 forward filter rule 20 source group network-group TRUSTEDv4
set firewall ipv6 input filter rule 10 action accept
set firewall ipv6 input filter rule 10 source group network-group TRUSTEDv6
set nat destination rule 101 inbound-interface group LAN
set nat destination rule 101 destination group address-group SERVERS
set nat destination rule 101 protocol tcp
set nat destination rule 101 destination group port-group PORT-SERVERS
set nat destination rule 101 translation address 203.0.113.250
set policy route PBR rule 201 destination group port-group PORT-SERVERS
set policy route PBR rule 201 protocol tcp
set policy route PBR rule 201 set table 15
```

### Restrict SSH access with port knocking

You can use dynamic address groups to implement port knocking: the router
accepts SSH connections from a client only after the client sends TCP packets to
a sequence of ports in the correct order. The following configuration uses the
ports 9990, 9991, and 9992:

```none
set firewall global-options state-policy established action 'accept'
set firewall global-options state-policy invalid action 'drop'
set firewall global-options state-policy related action 'accept'
set firewall group dynamic-group address-group ALLOWED
set firewall group dynamic-group address-group PN_01
set firewall group dynamic-group address-group PN_02
set firewall ipv4 input filter default-action 'drop'
set firewall ipv4 input filter rule 5 action 'accept'
set firewall ipv4 input filter rule 5 protocol 'icmp'
set firewall ipv4 input filter rule 10 action 'drop'
set firewall ipv4 input filter rule 10 add-address-to-group source-address address-group 'PN_01'
set firewall ipv4 input filter rule 10 add-address-to-group source-address timeout '2m'
set firewall ipv4 input filter rule 10 description 'Port_knock 01'
set firewall ipv4 input filter rule 10 destination port '9990'
set firewall ipv4 input filter rule 10 protocol 'tcp'
set firewall ipv4 input filter rule 20 action 'drop'
set firewall ipv4 input filter rule 20 add-address-to-group source-address address-group 'PN_02'
set firewall ipv4 input filter rule 20 add-address-to-group source-address timeout '3m'
set firewall ipv4 input filter rule 20 description 'Port_knock 02'
set firewall ipv4 input filter rule 20 destination port '9991'
set firewall ipv4 input filter rule 20 protocol 'tcp'
set firewall ipv4 input filter rule 20 source group dynamic-address-group 'PN_01'
set firewall ipv4 input filter rule 30 action 'drop'
set firewall ipv4 input filter rule 30 add-address-to-group source-address address-group 'ALLOWED'
set firewall ipv4 input filter rule 30 add-address-to-group source-address timeout '2h'
set firewall ipv4 input filter rule 30 description 'Port_knock 03'
set firewall ipv4 input filter rule 30 destination port '9992'
set firewall ipv4 input filter rule 30 protocol 'tcp'
set firewall ipv4 input filter rule 30 source group dynamic-address-group 'PN_02'
set firewall ipv4 input filter rule 99 action 'accept'
set firewall ipv4 input filter rule 99 description 'Port_knock 04 - Allow ssh'
set firewall ipv4 input filter rule 99 destination port '22'
set firewall ipv4 input filter rule 99 protocol 'tcp'
set firewall ipv4 input filter rule 99 source group dynamic-address-group 'ALLOWED'
```

Before a client sends the first knocking packet, the dynamic address groups
contain no addresses:

```none
vyos@vyos:~$ show firewall group
Firewall Groups

Name     Type                    References            Members    Timeout    Expires
-------  ----------------------  --------------------  ---------  ---------  ---------
ALLOWED  address_group(dynamic)  ipv4-input-filter-30  N/D        N/D        N/D
PN_01    address_group(dynamic)  ipv4-input-filter-10  N/D        N/D        N/D
PN_02    address_group(dynamic)  ipv4-input-filter-20  N/D        N/D        N/D
```

With this configuration, a client must complete the following steps to connect
to the router with SSH.

1. Send TCP packets to destination port 9990. The router adds the source address
   of the client to dynamic address group `PN_01` for two minutes.

```none
vyos@vyos:~$ show firewall group
Firewall Groups

Name     Type                    References            Members       Timeout    Expires
-------  ----------------------  --------------------  ------------  ---------  ---------
ALLOWED  address_group(dynamic)  ipv4-input-filter-30  N/D           N/D        N/D
PN_01    address_group(dynamic)  ipv4-input-filter-10  203.0.113.10  120        119
PN_02    address_group(dynamic)  ipv4-input-filter-20  N/D           N/D        N/D
```

2. Within two minutes, send TCP packets to destination port 9991. The router
   adds the source address to dynamic address group `PN_02` for three minutes.

```none
vyos@vyos:~$ show firewall group
Firewall Groups

Name     Type                    References            Members       Timeout    Expires
-------  ----------------------  --------------------  ------------  ---------  ---------
ALLOWED  address_group(dynamic)  ipv4-input-filter-30  N/D           N/D        N/D
PN_01    address_group(dynamic)  ipv4-input-filter-10  203.0.113.10  120        106
PN_02    address_group(dynamic)  ipv4-input-filter-20  203.0.113.10  180        179
```

3. Within three minutes, send TCP packets to destination port 9992. The router
   adds the source address to dynamic address group `ALLOWED` for two hours.

```none
vyos@vyos:~$ show firewall group
Firewall Groups

Name     Type                    References            Members         Timeout    Expires
-------  ----------------------  --------------------  ------------  ---------  ---------
ALLOWED  address_group(dynamic)  ipv4-input-filter-30  203.0.113.10       7200       7199
PN_01    address_group(dynamic)  ipv4-input-filter-10  203.0.113.10        120         89
PN_02    address_group(dynamic)  ipv4-input-filter-20  203.0.113.10        180        162
```

4. Within two hours, connect to the router with SSH. Rule 99 accepts the SSH
   packets because the source address is in the dynamic address group
   `ALLOWED`.