summaryrefslogtreecommitdiff
path: root/docs/configuration/service/dns.md
blob: 8e98a43a99c49c4db0e244a54754214268031d14 (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
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
---
myst:
  html_meta:
    description: |
      DNS forwarding is a VyOS service that resolves DNS queries for
      connected clients by forwarding to configurable upstream servers
      or by operating as a full recursive resolver.
    keywords: dns, dns forwarding, recursive dns, authoritative dns, dnssec
---

(dns-forwarding)=

# DNS forwarding

VyOS provides DNS infrastructure for small networks, designed to be
lightweight and suitable for resource-constrained routers and
firewalls.

Connected clients are served through the DNS forwarding service,
configured under `service dns forwarding`. It can either forward
queries to configurable upstream DNS servers or operate as a full
recursive DNS server without requiring upstream DNS servers. Operating
without upstream servers avoids exposing client queries to an upstream
DNS operator.

## Configuration

```{note}
A DNS forwarding configuration is committable only when both
`listen-address` and `allow-from` are set. Otherwise, the commit
fails.
```

### Listener

```{cfgcmd} set service dns forwarding listen-address \<address\>

**Configure a local IPv4 or IPv6 address on which DNS forwarding
listens for incoming queries.**

The address must already be assigned to a local interface. Repeat the
command to configure multiple listen addresses. At least one
listen-address is required for a successful commit.
```

Example:

```none
set service dns forwarding listen-address 192.0.2.1
set service dns forwarding listen-address 2001:db8::1
```

```{cfgcmd} set service dns forwarding port \<1-65535\>

**Configure the port on which DNS forwarding listens for incoming
queries.**

The default is 53.
```

Example:

```none
set service dns forwarding port 5353
```

```{cfgcmd} set service dns forwarding allow-from \<prefix\>

**Restrict incoming queries to clients whose source IP is within the
specified IPv4 or IPv6 prefix.**

Repeat the command to allow multiple prefixes. At least one prefix is
required for a successful commit.
```

```{note}
Restrict `allow-from` to trusted networks. Do not use `0.0.0.0/0` or
`::/0` if the service is reachable from the public Internet.
```

Example:

```none
set service dns forwarding allow-from 192.0.2.0/24
set service dns forwarding allow-from 2001:db8::/32
```

```{cfgcmd} set service dns forwarding exclude-throttle-address \<address\>

**Prevent throttling of authoritative servers matching the specified
IPv4 or IPv6 address or prefix.**

DNS forwarding throttles authoritative servers that do not answer a
query or return responses DNS forwarding rejects. This command exempts
the specified addresses from throttling. Repeat the command to add
multiple addresses.
```

Example:

```none
set service dns forwarding exclude-throttle-address 192.0.2.53
set service dns forwarding exclude-throttle-address 2001:db8::53
```

### Upstream forwarding

```{cfgcmd} set service dns forwarding name-server \<address\>

**Forward queries to the specified IPv4 or IPv6 upstream DNS server.**

The upstream servers are configured directly under DNS forwarding.
Repeat the command to configure multiple upstream servers.
```

Example:

```none
set service dns forwarding name-server 192.0.2.53
set service dns forwarding name-server 2001:db8::53
```

```{cfgcmd} set service dns forwarding name-server \<address\> port \<1-65535\>

**Configure the destination port used when forwarding queries to the
specified upstream DNS server.**

The default is 53.
```

Example:

```none
set service dns forwarding name-server 192.0.2.53 port 853
```

```{cfgcmd} set service dns forwarding system

**Forward queries to the upstream DNS servers configured under `system
name-server`.**

The upstream servers are inherited from `system name-server`.
```

Example:

```none
set service dns forwarding system
```

```{cfgcmd} set service dns forwarding dhcp \<interface\>

**Forward queries to the DNS servers learned via the DHCPv4 or DHCPv6
client on the specified interface.**

Repeat the command to forward queries to DHCP-learned servers from
multiple interfaces.
```

Example:

```none
set service dns forwarding dhcp eth0
```

```{cfgcmd} set service dns forwarding source-address \<address\>

**Configure the local IPv4 or IPv6 address used as the source when DNS
forwarding initiates outbound queries.**

The default is `0.0.0.0` and `::`, which means that the source address
is selected per outgoing query. Repeat the command to configure
multiple source addresses.
```

Example:

```none
set service dns forwarding source-address 192.0.2.1
set service dns forwarding source-address 2001:db8::1
```

```{cfgcmd} set service dns forwarding no-serve-rfc1918

**Disable authoritative answering of queries for `10.in-addr.arpa`,
`168.192.in-addr.arpa`, and `16-31.172.in-addr.arpa` zones.**

These are the reverse-lookup zones for the RFC 1918 private address
ranges. Queries for these zones are then forwarded to the configured
upstream servers.
```

Example:

```none
set service dns forwarding no-serve-rfc1918
```

```{cfgcmd} set service dns forwarding ignore-hosts-file

**Do not use the local `/etc/hosts` file in name resolution.**

By default, DNS forwarding answers queries using `/etc/hosts` before
performing recursion or forwarding.
```

Example:

```none
set service dns forwarding ignore-hosts-file
```

### Cache and timers

```{cfgcmd} set service dns forwarding cache-size \<0-2147483647\>

**Configure the maximum number of DNS cache entries.**

The default is 10000. A value of 0 disables the cache.
```

Example:

```none
set service dns forwarding cache-size 1000000
```

```{cfgcmd} set service dns forwarding negative-ttl \<0-7200\>

**Configure the maximum time, in seconds, that negative answers
(NXDOMAIN and NODATA) are cached.**

The default is 3600.
```

Example:

```none
set service dns forwarding negative-ttl 60
```

```{cfgcmd} set service dns forwarding minimum-ttl-override \<0-2147483647\>

**Configure the minimum {abbr}`TTL (Time-to-Live)`, in seconds,
applied to cached records regardless of the TTL received from the
authoritative server.**

Records with a TTL below this value are cached with this minimum
TTL. The default is `1`.
```

```{note}
Change this only if you have a specific reason to raise short TTLs,
as higher values extend caching beyond the authoritative TTL. If the
record changes upstream, clients receive the outdated cached value
until the override expires.
```

Example:

```none
set service dns forwarding minimum-ttl-override 30
```

```{cfgcmd} set service dns forwarding timeout \<10-60000\>

**Configure the time, in milliseconds, to wait for a remote
authoritative server to respond to an outgoing query.**

The default is 1500.
```

Example:

```none
set service dns forwarding timeout 2000
```

```{cfgcmd} set service dns forwarding ttl-percent \<0-100\>

**Refresh cached records in the background when the remaining TTL
falls below this percentage of the original TTL.**

Clients continue to receive the existing cached answer during refresh.
The default is 0, which disables background refresh.
```

Example:

```none
set service dns forwarding ttl-percent 10
```

```{cfgcmd} set service dns forwarding serve-stale-extension \<0-65535\>

**Configure how many times an expired record's TTL can be extended by
30 seconds when the record cannot be refreshed.**

The default is 0, which disables serving stale records.
```

Example:

```none
set service dns forwarding serve-stale-extension 30
```

### DNSSEC and NXDOMAIN behavior

```{cfgcmd} set service dns forwarding dnssec \<off | process-no-validate | process | log-fail | validate\>

**Configure the DNSSEC processing mode for outgoing queries and
responses:**

- `off`: No DNSSEC processing. DO bits in client queries are ignored,
  and no DNSSEC records are requested from authoritative servers.
- `process-no-validate`: Returns DNSSEC records (RRSIG, NSEC) to
  clients that request them, but does not validate.
- `process`: Validates responses only when the client requests it (DO
  or AD bit set). Returns `SERVFAIL` on bogus data.
- `log-fail`: Validates all responses regardless of client request,
  logs bogus responses, but returns the same answers as `process`
  mode.
- `validate`: Validates all responses and returns `SERVFAIL` on bogus
  data regardless of client request.

The default is `process-no-validate`.
```

Example:

```none
set service dns forwarding dnssec validate
```

```{cfgcmd} set service dns forwarding nothing-below-nxdomain \<no | dnssec | yes\>

**Configure how DNS forwarding handles the NXDOMAIN cut.**

When DNS forwarding has a cached NXDOMAIN, it can also return NXDOMAIN
for any name beneath the denied name, without asking upstream. This
setting controls when that behavior applies:

- `no`: Never apply the NXDOMAIN cut.
- `dnssec`: Apply the NXDOMAIN cut only for DNSSEC-validated NXDOMAIN
  entries.
- `yes`: Apply the NXDOMAIN cut for any cached NXDOMAIN that is not
  bogus.

The default is `dnssec`.
```

Example:

```none
set service dns forwarding nothing-below-nxdomain yes
```

### DNS64

```{cfgcmd} set service dns forwarding dns64-prefix \<prefix\>

**Synthesize AAAA records from A records for names that have no AAAA
records, using the specified NAT64 IPv6 prefix.**

The prefix length must be exactly `/96`.
```

Example:

```none
set service dns forwarding dns64-prefix 2001:db8:64::/96
```

### EDNS Client Subnet

```{cfgcmd} set service dns forwarding options ecs-add-for \<prefix\>

**Configure which client source address is sent as the
{abbr}`ECS (EDNS Client Subnet)` value in outgoing queries.**

For clients whose source address matches the specified prefix, the
client's real address is sent. For non-matching clients, a
placeholder address is sent instead so no client-specific subnet is
exposed.

ECS is only sent for queries matching `edns-subnet-allow-list`. This
option controls only the value, not whether ECS is sent.

Prepend `!` to exclude a prefix. Repeat the command for multiple
entries.
```

Example:

```none
set service dns forwarding options ecs-add-for 192.0.2.0/24
set service dns forwarding options ecs-add-for !192.0.2.128/25
```

```{cfgcmd} set service dns forwarding options ecs-ipv4-bits \<0-32\>

**Configure the number of bits of the client's IPv4 address included
in the ECS option sent to authoritative servers.**

Applies only to queries where ECS is sent (those matching
`edns-subnet-allow-list`).
```

Example:

```none
set service dns forwarding options ecs-ipv4-bits 24
```

```{cfgcmd} set service dns forwarding options edns-subnet-allow-list \<value\>

**Enable ECS in outgoing queries when the destination server's address
is within the specified netmask, or when the query name is under the
specified domain.**

Repeat the command to add multiple entries.
```

Example:

```none
set service dns forwarding options edns-subnet-allow-list example.com
set service dns forwarding options edns-subnet-allow-list 192.0.2.0/24
```

### Per-domain forwarding

```{cfgcmd} set service dns forwarding domain \<domain-name\> name-server \<address\>

**Forward queries for the specified domain to the given IPv4 or IPv6
upstream DNS server.**

Repeat the command to configure multiple nameservers for the same
domain. Use this option to implement split-horizon DNS. The domain may
also be a reverse-lookup zone such as `2.0.192.in-addr.arpa`.
```

Example:

```none
set service dns forwarding domain example.com name-server 192.0.2.53
set service dns forwarding domain example.com name-server 2001:db8::53
```

```{cfgcmd} set service dns forwarding domain \<domain-name\> name-server \<address\> port \<1-65535\>

**Configure the port on the given upstream DNS server to which queries
for the specified domain are forwarded.**

The default is 53.
```

Example:

```none
set service dns forwarding domain example.com name-server 192.0.2.53 port 853
```

```{cfgcmd} set service dns forwarding domain \<domain-name\> addnta

**Configure the specified domain as an {abbr}`NTA (Negative Trust
Anchor)`, disabling DNSSEC validation for it.**

Configure this when queries for a DNSSEC-broken domain return
`SERVFAIL`, so the domain becomes reachable again.
```

Example:

```none
set service dns forwarding domain example.com addnta
```

```{cfgcmd} set service dns forwarding domain \<domain-name\> recursion-desired

**Set the {abbr}`RD (Recursion Desired)` bit in queries sent to the
upstream DNS server for this domain.**
```

Example:

```none
set service dns forwarding domain example.com recursion-desired
```

### Authoritative zones

DNS forwarding can host authoritative records for a domain, answering
directly rather than forwarding or recursing queries.

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> disable

**Prevent DNS forwarding from serving the specified authoritative
zone, without removing it from configuration.**

Queries for names in the zone are forwarded or recursed instead.
```

Example:

```none
set service dns forwarding authoritative-domain example.com disable
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records \<type\> \<name\> disable

**Prevent DNS forwarding from serving a specific record within the
authoritative zone, without removing it from configuration.**

Queries matching the record are forwarded or recursed instead.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records a www disable
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records \<type\> \<name\> ttl \<0-2147483647\>

**Configure the TTL, in seconds, for the specified record.**

The default is 300.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records a www ttl 600
```

#### Record types

The record-type commands in this section accept the following
record-name keywords:

- `@`: Represents a zone apex, e.g., `example.com`. Accepted by every
  record type.
- `any`: Represents a wildcard record, e.g., `*.example.com`, that
  matches every subdomain under the apex. Accepted by `a` and `aaaa`
  records only.

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records a \<name\> address \<ipv4-address\>

**Configure an {abbr}`A (IPv4 address)` record in the specified
authoritative zone.**

Supports `@` and `any` as `<name>`. Repeat the command to add multiple
IPv4 addresses to the same record.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records a www address 192.0.2.10
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records aaaa \<name\> address \<ipv6-address\>

**Configure an {abbr}`AAAA (IPv6 address)` record in the specified
authoritative zone.**

Supports `@` and `any` as `<name>`. Repeat the command to add multiple
IPv6 addresses to the same record.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records aaaa www address 2001:db8::10
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records cname \<name\> target \<target-domain-name\>

**Configure a {abbr}`CNAME (Canonical Name)` record in the specified
authoritative zone.**

Supports `@` as `<name>`.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records cname www target host.example.com
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records mx \<name\> server \<server\>

**Configure an {abbr}`MX (Mail Exchanger)` record in the specified
authoritative zone.**

Supports `@` as `<name>`. Repeat the command to add multiple mail
servers to the same record.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records mx @ server mail.example.com
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records mx \<name\> server \<server\> priority \<1-999\>

**Configure the priority of the specified MX record.**

Lower values are preferred. The default is 10.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records mx @ server mail.example.com priority 20
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records ns \<name\> target \<target-name\>

**Configure an {abbr}`NS (Name Server)` record in the specified
authoritative zone.**

Supports `@` as `<name>`. Repeat the command to add multiple
nameservers to the same record.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records ns @ target ns1.example.com
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records ptr \<name\> target \<target-name\>

**Configure a {abbr}`PTR (Pointer)` record in the specified
authoritative zone.**

Supports `@` as `<name>`.
```

Example:

```none
set service dns forwarding authoritative-domain 2.0.192.in-addr.arpa records ptr 10 target host.example.com
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records txt \<name\> value \<value\>

**Configure a {abbr}`TXT (Text)` record in the specified authoritative
zone.**

Supports `@` as `<name>`. Repeat the command to add multiple TXT
strings to the same record.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records txt @ value 'v=spf1 -all'
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records spf \<name\> value \<value\>

**Configure an {abbr}`SPF (Sender Policy Framework)` record in the
specified authoritative zone.**

Supports `@` as `<name>`.
```

```{note}
SPF records are deprecated in favor of TXT records. Prefer TXT records
for new deployments.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records spf @ value 'v=spf1 -all'
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records srv \<name\> entry \<0-65535\> hostname \<name\>

**Configure the target hostname of an {abbr}`SRV (Service Locator)`
record entry in the specified authoritative zone.**

Supports `@` as `<name>`.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records srv _sip._tcp entry 0 hostname sip.example.com
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records srv \<name\> entry \<0-65535\> port \<0-65535\>

**Configure the port of an SRV record entry in the specified
authoritative zone.**
```

Example:

```none
set service dns forwarding authoritative-domain example.com records srv _sip._tcp entry 0 port 5060
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records srv \<name\> entry \<0-65535\> priority \<0-65535\>

**Configure the priority of an SRV record entry in the specified
authoritative zone.**

Lower values are preferred. The default is 10.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records srv _sip._tcp entry 0 priority 20
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records srv \<name\> entry \<0-65535\> weight \<0-65535\>

**Configure the weight of an SRV record entry in the specified
authoritative zone.**

Weight is used to distribute load among entries with equal priority.
The default is 0.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records srv _sip._tcp entry 0 weight 50
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> order \<0-65535\>

**Configure the order field of a {abbr}`NAPTR (Naming Authority
Pointer)` rule in the specified authoritative zone.**

Supports `@` as `<name>`. Rules with lower order are evaluated first.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 order 10
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> preference \<0-65535\>

**Configure the preference field of a NAPTR rule in the specified
authoritative zone.**

Supports `@` as `<name>`. The default is 0.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 preference 50
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> lookup-a

**Set the A flag on a NAPTR rule in the specified authoritative
zone.**

When set, DNS forwarding treats the rule's output as a domain name and
looks up its A or AAAA record. No further NAPTR lookups follow.
```

```{note}
Set at most one of `lookup-a`, `lookup-srv`, `resolve-uri`, and
`protocol-specific` on the same NAPTR rule. These flags define
mutually exclusive next actions in the DNS resolution.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 lookup-a
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> lookup-srv

**Set the S flag on a NAPTR rule in the specified authoritative
zone.**

When set, DNS forwarding treats the rule's output as a domain name and
looks up its SRV record. No further NAPTR lookups follow.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 lookup-srv
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> resolve-uri

**Set the U flag on a NAPTR rule in the specified authoritative
zone.**

When set, DNS forwarding treats the rule's output as a URI and uses it
directly. No further DNS lookups follow.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 resolve-uri
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> protocol-specific

**Set the P flag on a NAPTR rule in the specified authoritative
zone.**

When set, DNS forwarding treats the rule's output according to the
associated application protocol. No further DNS lookups follow.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 protocol-specific
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> service \<service\>

**Configure the Service field of a NAPTR rule in the specified
authoritative zone.**

Defines the protocol and resolution service this rule offers in
`Protocol+ResolutionService` format (for example, SIP over TCP →
`SIP+D2T`).
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 service SIP+D2T
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> regexp \<expression\>

**Configure the Regexp field of a NAPTR rule in the specified
authoritative zone.**

A substitution expression in `!ere!replacement!` format, applied to
the query name to produce the next-lookup target or URI.
```

```{note}
A rule uses either `regexp` or `replacement`, not both. Setting both
produces a malformed NAPTR record.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 regexp !^.*$!sip:helpdesk@example.com!
```

```{cfgcmd} set service dns forwarding authoritative-domain \<domain-name\> records naptr \<name\> rule \<0-65535\> replacement \<target-name\>

**Configure the Replacement field of a NAPTR rule in the specified
authoritative zone.**

An absolute DNS name used as the target of the next lookup, whose type
depends on the rule's flag.
```

Example:

```none
set service dns forwarding authoritative-domain example.com records naptr @ rule 100 replacement sip.example.com
```

### Zone caching

DNS forwarding can load a zone directly into its cache via
AXFR or from a zone file at a URL.
Zone caching is configured under
`service dns forwarding zone-cache <domain-name>`.

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> source axfr \<address\>

**Configure DNS forwarding to load the specified zone via AXFR from
the given IPv4 or IPv6 DNS server.**
```

Example:

```none
set service dns forwarding zone-cache example.com source axfr 192.0.2.53
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> source url \<url\>

**Configure DNS forwarding to load the specified zone from the given
HTTP(S) URL pointing to a zone file.**
```

Example:

```none
set service dns forwarding zone-cache example.com source url https://zones.example.com/example.com.zone
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> options timeout \<1-3600\>

**Configure how long, in seconds, DNS forwarding waits for the zone to
be retrieved before aborting the attempt.**

The default is 20.
```

Example:

```none
set service dns forwarding zone-cache example.com options timeout 60
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> options refresh interval \<0-31536000\>

**Configure the interval, in seconds, between periodic retrievals of
the zone into the cache.**

The default is 86400. A value of 0 disables periodic refresh.
```

Example:

```none
set service dns forwarding zone-cache example.com options refresh interval 3600
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> options refresh on-reload

**Retrieve the zone into the cache only at startup and when the
service is reloaded.**
```

Example:

```none
set service dns forwarding zone-cache example.com options refresh on-reload
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> options retry-interval \<1-86400\>

**Configure the interval, in seconds, before retrying zone retrieval
after an error.**

The default is 60.
```

Example:

```none
set service dns forwarding zone-cache example.com options retry-interval 300
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> options max-zone-size \<0-1024\>

**Configure the maximum size, in megabytes, of a zone loaded into the
cache.**

The default is 0, which imposes no limit.
```

Example:

```none
set service dns forwarding zone-cache example.com options max-zone-size 100
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> options zonemd \<ignore | validate | require\>

**Configure how DNS forwarding treats the ZONEMD digest of a retrieved
zone:**

- `ignore`: Does not check the ZONEMD digest.
- `validate`: Validates the ZONEMD digest if present.
- `require`: Rejects the zone unless a valid ZONEMD digest is present.

The default is `validate`.
```

Example:

```none
set service dns forwarding zone-cache example.com options zonemd require
```

```{cfgcmd} set service dns forwarding zone-cache \<domain-name\> options dnssec \<ignore | validate | require\>

**Configure the DNSSEC validation policy for a retrieved zone:**

- `ignore`: No DNSSEC validation.
- `validate`: Rejects zones with incorrect signatures but accepts
  unsigned zones.
- `require`: Rejects the zone unless it is DNSSEC-signed and passes
  signature validation.

The default is `validate`.
```

Example:

```none
set service dns forwarding zone-cache example.com options dnssec require
```

## Operation

### Show

```{opcmd} show dns forwarding statistics

**Show operational statistics collected by DNS forwarding.**
```

```{opcmd} show log dns forwarding

**Show log entries for DNS forwarding since the last boot.**
```

```{opcmd} monitor log dns forwarding

**Follow the DNS forwarding service log in real time.**
```

### Reset and restart

```{opcmd} reset dns forwarding all

**Clear the entire DNS forwarding cache.**
```

```{opcmd} reset dns forwarding domain \<domain-name\>

**Clear the DNS forwarding cache entries for the specified domain
only.**
```

```{opcmd} restart dns forwarding

**Restart the DNS forwarding service.**

Restarting the service also clears its cache.
```

## Example

The following configuration implements split-horizon DNS for
`example.com` on a VyOS router with two interfaces (`eth0` WAN, `eth1`
LAN):

- DNS queries for `example.com` are forwarded to `192.0.2.254` and
  `2001:db8:cafe::1`.
- All other DNS queries are forwarded to a set of upstream servers,
  two of which use non-standard ports.
- DNS forwarding listens only on LAN interface addresses.
- DNS forwarding accepts DNS queries only from LAN clients.
- Reverse lookups for RFC 1918 zones are forwarded upstream rather
  than answered locally.

```none
set service dns forwarding domain example.com name-server 192.0.2.254
set service dns forwarding domain example.com name-server 2001:db8:cafe::1
set service dns forwarding name-server 192.0.2.1
set service dns forwarding name-server 192.0.2.2
set service dns forwarding name-server 192.0.2.3 port 853
set service dns forwarding name-server 2001:db8::1:ffff
set service dns forwarding name-server 2001:db8::2:ffff
set service dns forwarding name-server 2001:db8::3:ffff port 8053
set service dns forwarding listen-address 192.168.1.254
set service dns forwarding listen-address 2001:db8::ffff
set service dns forwarding allow-from 192.168.1.0/24
set service dns forwarding allow-from 2001:db8::/64
set service dns forwarding no-serve-rfc1918
```