Home / Azure

AzureHow-toAdvanced

Azure Firewall FQDN network rules: DNS proxy design and fixing intermittent denies from resolution mismatches

Make FQDN-based network rules on Azure Firewall reliable. Enable DNS proxy, point spokes at the firewall, keep private DNS working and use the logs to prove a client and the firewall resolved a name differently.

Deepak Bhardwaj8 min read

Applies toAzure Firewall Standard and Premium with Firewall Policy, hub-spoke and secured Virtual WAN hubs

The problem

You allow sftp.partner.example on TCP 22 with an FQDN network rule. It works for an hour, then some connections are denied with No rule matched, and they recover by themselves. Application rules for HTTPS to the same kind of destinations never do this.

The cause is nearly always that the client and the firewall resolved the name to different IPs. Network rules match on IP addresses. The firewall turns the FQDN in the rule into IPs by resolving it itself. If the client resolved the same name through a different DNS path, gets a different CDN or geo answer, or holds an older cached record, the destination IP in the packet isn't in the firewall's list and the flow falls through to the default deny.

Application rules don't have this issue for HTTP/S because they match on the SNI or Host header, not on the destination IP.

How the pieces fit

Component Role
FQDN in a network rule Firewall resolves it and builds an IP list for the rule
DNS proxy on the firewall Firewall listens on UDP/TCP 53 on its private IP and forwards queries to its configured DNS servers
VNet DNS servers Spokes must use the firewall private IP so clients get the same answers the firewall uses
Firewall's upstream DNS Azure DNS, or custom servers such as DNS Private Resolver inbound endpoints or domain controllers

FQDN filtering in network rules requires DNS proxy to be enabled. It is only reliable when clients resolve through the firewall too.

1. Check the current state

RG=rg-hub
POLICY=afwp-hub

az network firewall policy show -g $RG -n $POLICY \
  --query "{proxy:dnsSettings.enableProxy, servers:dnsSettings.servers, sku:sku.tier}" -o json

# What DNS servers each spoke VNet hands out
az network vnet list --query "[].{vnet:name, rg:resourceGroup, dns:dhcpOptions.dnsServers}" -o table

If proxy is false or null, FQDN network rules won't work as you expect. If spokes list domain controllers or a resolver instead of the firewall IP, you have the mismatch described above.

2. Prove the mismatch from the logs

This needs resource-specific diagnostic tables (AZFWNetworkRule, AZFWDnsQuery). Look at what the client asked the firewall to resolve, and at what the firewall then denied:

let client = "10.20.1.15";
let window = 2h;
AZFWDnsQuery
| where TimeGenerated > ago(window) and SourceIp == client
| where QueryName has "partner.example"
| project TimeGenerated, SourceIp, QueryName, QueryType, ResponseCode, ErrorMessage
| order by TimeGenerated desc
AZFWNetworkRule
| where TimeGenerated > ago(2h)
| where SourceIp == "10.20.1.15" and DestinationPort == 22
| summarize hits = count() by Action, DestinationIp, Rule, ActionReason
| order by hits desc

How to read the results:

  • Denied flows but no AZFWDnsQuery rows from that client. The client isn't using the firewall for DNS. Fix step 3.
  • DNS rows exist, but denied destination IPs aren't among the current A records. The client cached an old answer (the TTL is longer than the provider's rotation) or uses a hard-coded IP.
  • ResponseCode is SERVFAIL or there are timeouts. The firewall's upstream DNS is failing. Check the AZFWFqdnResolveFailure table and fix the upstream.

To compare answers directly, run the same lookup from a VM against the firewall and against the server the client used to point at:

dig +short sftp.partner.example @10.0.1.4      # firewall private IP
dig +short sftp.partner.example @10.0.5.10     # old DNS server
Resolve-DnsName sftp.partner.example -Server 10.0.1.4 -Type A
Resolve-DnsName sftp.partner.example -Server 10.0.5.10 -Type A

Different answer sets confirm the cause.

3. Enable DNS proxy and point spokes at the firewall

Set the firewall's upstream servers first. If you use private endpoints or on-premises zones, the upstream must be able to resolve them. The usual choice is a DNS Private Resolver inbound endpoint or your domain controllers, not plain Azure DNS.

az network firewall policy update -g $RG -n $POLICY \
  --enable-dns-proxy true \
  --dns-servers 10.0.3.4 10.0.3.5

Then point each spoke at the firewall's private IP:

FW_IP=$(az network firewall show -g $RG -n afw-hub \
  --query "ipConfigurations[0].privateIPAddress" -o tsv)

az network vnet update -g rg-spoke1 -n vnet-spoke1 --dns-servers $FW_IP

Warning

Changing VNet DNS servers moves name resolution for every workload in that VNet onto the firewall. If the firewall's upstream can't resolve private endpoint zones or on-premises domains, apps fail at once. Test with Resolve-DnsName or dig against the firewall IP for every private zone you rely on before you change the VNet.

Existing VMs pick up the new DNS server when their DHCP lease renews, so force it in a controlled way:

ipconfig /renew; ipconfig /flushdns
# systemd-networkd based images (Ubuntu); use your distro's equivalent elsewhere
sudo networkctl reconfigure eth0
resolvectl status eth0 | grep -A2 "DNS Servers"

AKS nodes, App Service VNet integration and other managed services pick up VNet DNS changes on their own schedule. AKS node pools may need a node image upgrade or reimage, and App Service needs a restart.

Make sure NSGs and UDRs in the spokes allow UDP and TCP 53 to the firewall IP. TCP matters for large responses.

4. Write rules that survive DNS behaviour

az network firewall policy rule-collection-group collection add-filter-collection \
  -g $RG --policy-name $POLICY --rule-collection-group-name rcg-spokes \
  --name nc-partner-sftp --collection-priority 310 --action Allow \
  --rule-name partner-sftp --rule-type NetworkRule \
  --source-addresses 10.20.1.0/24 \
  --destination-fqdns sftp.partner.example \
  --destination-ports 22 --ip-protocols TCP

Design rules:

  • Use application rules for HTTP/S. They match SNI or Host and support wildcards. Use FQDN network rules only for non-HTTP protocols (SFTP, SQL, SMTP, custom TCP).
  • Network rule FQDNs don't take wildcards. List each name explicitly, or use an application rule if the protocol allows it.
  • Names behind CDNs or global load balancers rotate IPs fast. Even with DNS proxy, a client that keeps a long-lived connection to an IP the firewall has since dropped is normally fine (the existing session stays up). New connections to a stale cached IP are not. Keep client-side DNS caching short.
  • Don't mix IP and FQDN rules for the same destination unless you mean to. The IP rule hides FQDN problems during testing and then gets removed.

5. Keep private DNS working through the proxy

The firewall forwards to its configured servers. It doesn't read the private DNS zones linked to the spokes. Pick one model and stick to it:

Model Firewall upstream Private DNS zones linked to
Azure DNS only Default (Azure DNS) The hub VNet that contains the firewall
Hybrid DNS Private Resolver inbound endpoint IPs The resolver's VNet; on-prem forwards to the same inbound IPs
AD-integrated Domain controllers DCs conditionally forward Azure zones to Azure DNS or the resolver

A common failure after enabling DNS proxy: private endpoints suddenly resolve to public IPs. The zones were linked only to spokes, and the firewall's upstream can't see them. Link the zones to the VNet the upstream resolves from.

Symptom → cause → fix

Symptom Cause Fix
Intermittent No rule matched on an FQDN network rule Client and firewall resolve differently Point spokes at the firewall DNS proxy
FQDN network rule never matches DNS proxy disabled --enable-dns-proxy true
Private endpoints resolve publicly after the change Firewall upstream can't see private zones Link zones to the upstream's VNet or use DNS Private Resolver
Large DNS answers fail TCP 53 blocked to the firewall Allow TCP and UDP 53
Works after VM reboot only Old DNS server still in DHCP lease Renew the lease or restart networking

Prevent it next time

  • Enforce spoke DNS settings with Azure Policy (audit VNets whose dhcpOptions.dnsServers isn't the firewall IP) or Azure Virtual Network Manager.
  • Alert on a rise in AZFWNetworkRule denies for destinations that have an FQDN allow rule.
  • Track upstream DNS failures from AZFWDnsQuery (ResponseCode other than NOERROR and NXDOMAIN) as a firewall health signal.
  • Document the DNS path for every new FQDN rule in the rule description: protocol, why an application rule can't be used, and the owner.