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
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:
set service dns forwarding listen-address 192.0.2.1
set service dns forwarding listen-address 2001:db8::1
Configure the port on which DNS forwarding listens for incoming queries.
The default is 53.
Example:
set service dns forwarding port 5353
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:
set service dns forwarding allow-from 192.0.2.0/24
set service dns forwarding allow-from 2001:db8::/32
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:
set service dns forwarding exclude-throttle-address 192.0.2.53
set service dns forwarding exclude-throttle-address 2001:db8::53
Upstream forwarding
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:
set service dns forwarding name-server 192.0.2.53
set service dns forwarding name-server 2001:db8::53
Configure the destination port used when forwarding queries to the specified upstream DNS server.
The default is 53.
Example:
set service dns forwarding name-server 192.0.2.53 port 853
Forward queries to the upstream DNS servers configured under system name-server.
The upstream servers are inherited from system name-server.
Example:
set service dns forwarding system
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:
set service dns forwarding dhcp eth0
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:
set service dns forwarding source-address 192.0.2.1
set service dns forwarding source-address 2001:db8::1
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:
set service dns forwarding no-serve-rfc1918
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:
set service dns forwarding ignore-hosts-file
Cache and timers
Configure the maximum number of DNS cache entries.
The default is 10000. A value of 0 disables the cache.
Example:
set service dns forwarding cache-size 1000000
Configure the maximum time, in seconds, that negative answers (NXDOMAIN and NODATA) are cached.
The default is 3600.
Example:
set service dns forwarding negative-ttl 60
Configure the minimum TTL, 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:
set service dns forwarding minimum-ttl-override 30
Configure the time, in milliseconds, to wait for a remote authoritative server to respond to an outgoing query.
The default is 1500.
Example:
set service dns forwarding timeout 2000
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:
set service dns forwarding ttl-percent 10
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:
set service dns forwarding serve-stale-extension 30
DNSSEC and NXDOMAIN behavior
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). ReturnsSERVFAILon bogus data.log-fail: Validates all responses regardless of client request, logs bogus responses, but returns the same answers asprocessmode.validate: Validates all responses and returnsSERVFAILon bogus data regardless of client request.
The default is process-no-validate.
Example:
set service dns forwarding dnssec validate
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:
set service dns forwarding nothing-below-nxdomain yes
DNS64
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:
set service dns forwarding dns64-prefix 2001:db8:64::/96
EDNS Client Subnet
Configure which client source address is sent as the ECS 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:
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
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:
set service dns forwarding options ecs-ipv4-bits 24
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:
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
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:
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
Configure the port on the given upstream DNS server to which queries for the specified domain are forwarded.
The default is 53.
Example:
set service dns forwarding domain example.com name-server 192.0.2.53 port 853
Configure the specified domain as an NTA, disabling DNSSEC validation for it.
Configure this when queries for a DNSSEC-broken domain return
SERVFAIL, so the domain becomes reachable again.
Example:
set service dns forwarding domain example.com addnta
Set the RD bit in queries sent to the upstream DNS server for this domain.
Example:
set service dns forwarding domain example.com recursion-desired
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>.
Configure DNS forwarding to load the specified zone via AXFR from the given IPv4 or IPv6 DNS server.
Example:
set service dns forwarding zone-cache example.com source axfr 192.0.2.53
Configure DNS forwarding to load the specified zone from the given HTTP(S) URL pointing to a zone file.
Example:
set service dns forwarding zone-cache example.com source url https://zones.example.com/example.com.zone
Configure how long, in seconds, DNS forwarding waits for the zone to be retrieved before aborting the attempt.
The default is 20.
Example:
set service dns forwarding zone-cache example.com options timeout 60
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:
set service dns forwarding zone-cache example.com options refresh interval 3600
Retrieve the zone into the cache only at startup and when the service is reloaded.
Example:
set service dns forwarding zone-cache example.com options refresh on-reload
Configure the interval, in seconds, before retrying zone retrieval after an error.
The default is 60.
Example:
set service dns forwarding zone-cache example.com options retry-interval 300
Configure the maximum size, in megabytes, of a zone loaded into the cache.
The default is 0, which imposes no limit.
Example:
set service dns forwarding zone-cache example.com options max-zone-size 100
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:
set service dns forwarding zone-cache example.com options zonemd 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:
set service dns forwarding zone-cache example.com options dnssec require
Operation
Show
Reset and restart
Clear the DNS forwarding cache entries for the specified domain only.
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.comare forwarded to192.0.2.254and2001: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.
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