Enable or disable the DNS mock server. When enabled, MockServer starts a UDP DNS server that matches incoming DNS queries against expectations. DNS expectations use DnsRequestDefinition for matching and DnsResponse for responses. Supported record types: A, AAAA, CNAME, MX, SRV, TXT, PTR.
Type: boolean Default: false
Java Code:
ConfigurationProperties.dnsEnabled(boolean enable)
System Property:
-Dmockserver.dnsEnabled=...
Environment Variable:
MOCKSERVER_DNS_ENABLED=...
Property File:
mockserver.dnsEnabled=...
Example:
-Dmockserver.dnsEnabled="true"
The UDP port for the DNS mock server. Set to 0 to let the operating system assign an ephemeral port. Use MockServer.getDnsPort() to retrieve the actual bound port at runtime.
Type: integer Default: 0
Java Code:
ConfigurationProperties.dnsPort(int port)
System Property:
-Dmockserver.dnsPort=...
Environment Variable:
MOCKSERVER_DNS_PORT=...
Property File:
mockserver.dnsPort=...
Example:
-Dmockserver.dnsPort="5353"
The DNS mock listens on UDP only. A DNS response that does not fit the client's UDP payload limit is sent truncated, with the TC ("truncated") flag set, carrying as many complete records as fit. The limit is 512 bytes, or the larger buffer size the client advertises if it uses EDNS(0) — most modern resolvers advertise 4096.
Standard resolvers respond to the TC flag by retrying the query over TCP. Because MockServer does not currently serve DNS over TCP, that retry has nowhere to go. If you need to return many records, keep the response under the limit or make sure your client uses EDNS(0).
TXT values longer than 255 bytes are split across multiple character-strings, as RFC 1035 requires; resolvers rejoin them, so a long value such as a DKIM key is delivered intact.
A record that cannot be encoded as valid DNS — an unparseable IP address, an A record given an IPv6 value, a name label longer than 63 bytes, or a name longer than 255 bytes — causes the query to be answered with SERVFAIL, and the reason is logged. This is deliberate: returning a successful-looking response built from unencodable configuration would hide the mistake.