Technical Tip: FortiGate alt-primary, alt-secondary DNS server feature and configuration
Description
Â
This article describes the FortiGate alt-primary DNS server feature and its configuration.
Â
Scope
Â
FortiOS v7.0, v7.2, v7.4.
Â
Solution
Â
alt-primary and alt-secondary servers are configurable from the CLI.
Â
config system dnsn
set alt-primary {ipv4-address}
set alt-secondary {ipv4-address}
endÂ
Alt-dns servers are alternative DNS servers for FortiGate queries under a specific condition.
Â
FortiGate queries the configured alt-dns servers when FortiGate's primary/secondary DNS server returns a name resolution error (NXDOMAIN) for a name query.
Â
A common usage case for alt-dns servers is to resolve internal domain names that cannot be resolved by the public DNS servers.
Â
If using DNS port 53, the best way to see the DNS response is to run the packet sniffer below and convert it so it can be analyzed with Wireshark. See Technical Tip: How to import 'diagnose sniffer packet' data to WireShark.
Â
diagnose sniffer packet any "host x.x.x.x and host y.y.y.y and port 53" 6 0 l Â
Where x.x.x.x is the client IP and y.y.y.y is the DNS server IP.
Â
Wireshark capture can be taken on an internal client machine or on FortiGate. FortiGate provides the option to filter before starting the capture. IP address of internal client can be used to filter the capture.
Â

Â
As can be seen from the screenshot, an error in the DNS response is seen as ''No such name(3)'.
Â
Example workflow:
Â
config system dns
set primary 96.45.45.45
set secondary 96.45.46.46
set protocol dot
set server-hostname "globalsdns.fortinet.net"
set alt-primary 10.0.0.3
set alt-secondary 10.0.0.4
endÂ
FortiGate's primary and secondary DNS servers are configured as public DNS servers.
FortiGate must query www.test.lab.
DNS server selection takes place between primary and secondary DNS servers based on the 'set server-select-method' setting.
The query is sent to the chosen primary/secondary DNS server.
Public DNS servers return a name resolution error 'NXDOMAIN'.
Another server selection takes place between alt-primary and alt-secondary DNS servers.
The same query for www.test.lab is sent to the chosen alt-dns server.
Â
For alt-dns servers to be utilized, the following conditions must be met.
Â
Receives a nxdomain from 'primary/secondary DNS'.
Has alternate servers configured.
Domain forwarding is not configured.
The alternate DNS servers must support at least one protocol configured in 'config system dns'
Â
Domain Forwarding:Â
Technical Tip: DNS conditional forwarding
Â
The option 'set server-hostname' is not available when using the cleartext protocol.
Â
Note: Alternate DNS servers only apply for FortiGate's own DNS requests and clients using FortiGate as DNS server.Â
To configure FortiGate as a DNS server for clients using the firewall as a DHCP server, configure the DNS service following FortiGate DNS server and select 'Same as Interface IP' for DNS server under the DHCP server configuration. Go to Network -> Interfaces -> DHCP Server -> DNS server 'Same as interface IP'.

Â
FortiGate alt-dns query honors 'set server-select-method' configuration as well as 'protocol'.
Â
config system dns
set server-select-method { least-rtt | failover }
set protocol {cleartext | dot | doh}
endÂ
Related article:
Technical Tip: FortiGate DNS query preference when multiple DNS protocols are enabled
