Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/linux/init/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ int GenerateSystemdUnits(int Argc, char** Argv)
// Mask NetworkManager-wait-online.service for the same reason, as it causes timeouts on distros using NetworkManager.
THROW_LAST_ERROR_IF(symlink("/dev/null", std::format("{}/NetworkManager-wait-online.service", installPath).c_str()) < 0);

// Enable DNS response caching in systemd-resolved. On some distros (notably Ubuntu) the default
// Cache=no-negative discards negative (NODATA/NXDOMAIN) responses, which causes repeated wire
// queries for unsupported record types (e.g. AAAA on IPv4-only networks). This override aligns
// all distros with the upstream systemd default of Cache=yes, ensuring systemd-resolved provides
// effective DNS caching inside the VM.
THROW_LAST_ERROR_IF(UtilMkdirPath("/run/systemd/resolved.conf.d", 0755) < 0);
constexpr auto* resolvedCacheConfig = "[Resolve]\nCache=yes\n";
THROW_LAST_ERROR_IF(WriteToFile("/run/systemd/resolved.conf.d/wsl-dns-cache.conf", resolvedCacheConfig) < 0);

// Only create the wslg unit if both enabled in wsl.conf, and if the wslg folder actually exists.
if (enableGuiApps && access("/mnt/wslg/runtime-dir", F_OK) == 0)
{
Expand Down
8 changes: 7 additions & 1 deletion src/windows/common/DnsResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ try
// Only unicast UDP & TCP queries are tunneled. Pass this flag to tell Windows DNS client to *not* resolve using multicast.
request.queryOptions |= DNS_QUERY_NO_MULTICAST;

// DnsQueryRaw bypasses the Windows DNS cache internally, which means all responses return with TTL values
// reset to their original values. Pass this flag so that the DNS client preserves the real (decremented) TTL
// values from cached upstream responses, enabling downstream caches (e.g. systemd-resolved) to use meaningful TTLs.
request.queryOptions |= DNS_QUERY_DONT_RESET_TTL_VALUES;

// In a DNS request from Linux there might be DNS records that Windows DNS client does not know how to parse.
// By default in this case Windows will fail the request. When the flag is enabled, Windows will extract the
// question from the DNS request and attempt to resolve it, ignoring the unknown records.
Expand All @@ -253,7 +258,8 @@ try
}

// Start the DNS request
// N.B. All DNS requests will bypass the Windows DNS cache
// N.B. DnsQueryRaw bypasses the Windows DNS cache; DNS_QUERY_DONT_RESET_TTL_VALUES is set above
// so that responses carry real TTL values for downstream caching (e.g. systemd-resolved).
const auto result = s_dnsQueryRaw.value()(&request, &localContext->m_cancelHandle);
if (result != DNS_REQUEST_PENDING)
{
Expand Down