Follow a Packet Through VNet, Subnet and Route Table
A VNet is a regional routing domain, and inside it a packet is a route lookup before it is a connection. The address space is the promise, a subnet is a slice of it, and a route table chooses the next hop for anything leaving that slice. Read the path in one direction before writing a single resource.
Address planning is the decision that is hardest to reverse. A spoke at 10.20.0.0/16 and a hub at 10.21.0.0/16 leave room for a gateway, a firewall and an endpoint subnet without overlap. Azure reserves five addresses in every subnet, the first four and the last, so a /24 leaves 251 usable addresses rather than 254.
System routes are a floor, not a design. Every subnet receives VnetLocal routes for the VNet prefixes, a default route to the Internet, and None routes for the RFC1918 blocks and 100.64.0.0/10. A None route is a blackhole, so an unpeered 10.22.0.0/16 fails instead of escaping to the internet.
A user-defined route wins only at the same prefix length. Azure selects the longest matching prefix, then breaks the tie by source: user-defined route, then BGP, then system. A route whose next hop is a service endpoint cannot be overridden, which is how a firewall UDR can look correct and still be bypassed.
Peering is two objects and zero transitivity. Each direction is a separate azurerm_virtual_network_peering, and forwarded traffic is denied unless both sides allow it. A spoke-to-spoke path through the hub needs an appliance, IP forwarding on its NIC and a route that names it.
Egress is a separate decision with a separate owner. The subnet flag default_outbound_access_enabled still defaults to true, so an implicit path is a choice made by omission. Set it false and supply a NAT gateway or firewall; on a private subnet, a UDR with the Internet next hop stops working.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
DNS["Private DNS answer
privatelink.blob.core.windows.net"] -.-> C["Client VM
snet-app 10.20.1.4"]
C --> N1{"NIC then subnet NSG
443 to 10.21.2.4?"}
N1 -- "deny at priority 1000" --> D1["Timeout at the client
flow log shows the deny"]
N1 -- "allow" --> R1{"Route lookup
longest prefix match"}
R1 -- "10.0.0.0/8 to None" --> D2["Blackholed
no peering route exists"]
R1 -- "10.21.0.0/16 to peering" --> P["VNet peering link
forwarded traffic allowed"]
P --> N2{"Hub NSG inbound
snet-pe 443?"}
N2 -- "deny" --> D3["Timeout at the endpoint
different owner, same symptom"]
N2 -- "allow" --> PE["Private endpoint NIC
10.21.2.4"]
PE --> S["Storage account
private link consent"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class N1,R1,N2 primary;
class C,P,PE,S secondary;
class D1,D2,D3 danger;
class DNS warn;
Figure 1 traces one allowed path and three independent ways to lose it. The client's NIC and subnet rules are evaluated before anything leaves, the route lookup decides whether the hub is reachable at all, and the hub's inbound rule is a second decision with a different owner. The red nodes share a symptom, a timeout, and nothing else.
Figure 2 puts the address plan beside the rules that read it. The effective route list on the client NIC is the shortest honest summary of the design: one VnetLocal entry, one peering entry and one None entry that explains a failure no firewall log will ever show. The amber band is the only thing that decides which of the two addresses the client actually asks for.
Choose NSGs and Service-Specific Subnet Requirements
An NSG is a stateful filter, not a router. It matches a five-tuple at the NIC and at the subnet, evaluates rules by priority from 100 to 4096, and stops at the first match. With no NSG attached, traffic is allowed.
Direction decides the order. Inbound traffic meets the subnet NSG and then the NIC NSG; outbound traffic meets the NIC NSG and then the subnet NSG. Both must allow, and a deny at either level ends the evaluation.
A rule cannot create reachability. An NSG decides whether a packet that already has a path may proceed; it never supplies the path. A denied rule and a missing route both surface as a timeout, which is why widening a rule is the wrong first move.
The defaults are permissive inside the VNet. AllowVnetInBound and AllowVnetOutBound at priority 65000 admit all VNet traffic, and DenyAllInBound at 65500 catches only what the earlier defaults did not allow. A sensitive subnet needs explicit deny rules below 65000, added after the allow list is complete.
Delegation is a subnet contract, not a label. A delegated subnet is reserved for one service, which then dictates minimum size, NSG support, route-table support and whether anything else may live there. The Terraform block is a delegation block, and the service name is the contract.
App Service regional integration delegates to Microsoft.Web/serverFarms. A /28 is the minimum and a /26 is the recommended production size, and the subnet must be empty, so no private endpoint can share it. Container Instances delegates to Microsoft.ContainerInstance/containerGroups under a similar contract.
SQL Managed Instance needs Microsoft.Sql/managedInstances and at least 32 addresses. A /27 is the documented minimum, and the range cannot be resized once instances exist. Platform subnets are just as strict: AzureFirewallSubnet at /26, GatewaySubnet at /27 and AzureBastionSubnet at /26.
A delegated subnet cannot host a private endpoint. The platform rejects the combination, so the endpoint needs its own subnet, and private endpoint policies should not be configured on a delegated one. That is a design constraint, not a plan-time warning.
Private endpoints change what the subnet filter sees. The subnet setting private_endpoint_network_policies defaults to Disabled, so NSG and UDR rules do not apply to endpoint traffic while they still apply to everything else in the subnet. Disabled, Enabled, NetworkSecurityGroupEnabled and RouteTableEnabled are the four states.
Enabling policy is a trade, not an upgrade. With the NSG state on, endpoint traffic is filtered, but the platform still installs a /32 route per endpoint, so the route table's view of that address is not the one you wrote.
This article targets Terraform 1.17.1 and hashicorp/azurerm 5.13.0. In that release the subnet takes a service_endpoint block, and the private_endpoint_network_policies argument replaces the older boolean that used to carry the same decision. Examples written for 3.x fail validation on the old argument instead of quietly meaning something else.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
START["Subnet purpose"] --> DEL{"Delegated to a service?"}
DEL -- "yes" --> SVC["Service contract wins
size, NSG and UDR support vary"]
SVC --> NOPE["No private endpoints here
platform rejects the mix"]
DEL -- "no" --> PEQ{"Hosts private endpoints?"}
PEQ -- "yes" --> POL{"private_endpoint_network_policies"}
POL -- "Disabled, the default" --> SKIP["NSG and UDR bypass the endpoint
other resources still filtered"]
POL -- "NetworkSecurityGroupEnabled" --> FILT["NSG applies to endpoint traffic
UDR does not"]
POL -- "Enabled" --> BOTH["NSG and UDR both apply
one /32 route per endpoint"]
PEQ -- "no" --> WORK["Ordinary workload subnet
NSG at subnet and NIC"]
WORK --> INB["Inbound: subnet, then NIC"]
INB --> OUTB["Outbound: NIC, then subnet"]
OUTB --> FIRST["First match wins
100 to 4096, then defaults"]
SKIP --> TEST["Prove DNS and path
before changing policy"]
FILT --> TEST
BOTH --> TEST
FIRST --> TEST
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class DEL,PEQ,POL,FIRST primary;
class START,SVC,WORK,INB,OUTB secondary;
class TEST,SKIP,FILT,BOTH ok;
class NOPE danger;
Figure 3 separates four subnet shapes that are often conflated. The left branch is a delegation contract, the middle branch is a private endpoint policy decision, and the right branch is an ordinary workload subnet. Each branch has a different failure signature, so the first question is always which branch the subnet belongs to.
Separate Private Endpoint Creation from DNS Resolution
Creating a private endpoint and making its name resolve are two operations with two owners. The endpoint resource creates a NIC, a private link connection and a consent state; DNS is a zone, a link and a record somewhere else. Terraform will happily do the first and leave the second undone.
The endpoint gives the service an address; DNS gives the client a reason to use it. The NIC holds the private IP and the fully qualified name, and the service keeps answering on its public name until something overrides it. Nothing about the endpoint changes the account's public endpoint by itself.
A private DNS zone is three objects. The zone owns the namespace, a virtual network link makes it resolvable, and an A record maps the resource name to the endpoint address. A zone with no link resolves nothing; a link with no record resolves the name to nothing.
The zone group is the only automatic record writer. A private_dns_zone_group block on the endpoint points at one or more zones and lets Azure maintain the record for the endpoint's lifetime. Omit it and the zone stays empty; write the record yourself and Terraform owns two objects that must be deleted in order.
Link the zone to every client VNet, not only the endpoint VNet. Resolution follows links, not peering, so a spoke that can route to the endpoint still resolves the public address until the zone is linked to it. In a hub-and-spoke design the hub holds the zone and every spoke gets a link.
Registration is not the endpoint record. The registration_enabled flag on a link is VM name auto-registration, and leaving it false is normal. Endpoint records come from the zone group and are not created by registration.
Keep one zone per service, and one record per resource. privatelink.blob.core.windows.net and privatelink.vaultcore.azure.net are different namespaces with different records. Putting two services in one zone, or two endpoints for the same service on one record, produces the record that disappears.
Azure DNS answers from 168.63.129.16; a custom resolver must forward to it. If the VNet sets dns_servers, those servers become the only resolver the workloads ask, and they must conditionally forward the privatelink namespaces to Azure DNS. Without that forwarder the zone is never consulted and the name resolves public.
On-premises needs a path to the zone, not just a VPN. A conditional forwarder must target a resolver that can see the zone, such as a Private Resolver inbound endpoint in the hub; 168.63.129.16 is not reachable from outside a VNet. A DNS forwarder VM works, but it becomes a subnet, a NIC and a patch owner.
Order protects the recovery path. Create the zone and link before the endpoint if the record must exist at create time, and change public access only after resolution and routing both pass. Disabling the public endpoint first removes the path an administrator would use to fix the mistake.
Test resolution and reachability as separate facts. A private answer with a timeout is routing or filtering; a public answer with a working connection is DNS. One check on a client in the subnet tells you which half of the design is wrong.
Compare Service Endpoints and Private Endpoints Precisely
A service endpoint lends the subnet's identity to a public endpoint; a private endpoint gives the service a local address. The first changes the source address the service sees and the route the packet takes, while the client still connects to the public name. The second changes the destination itself, so the client connects to an address inside the VNet.
The access contract differs in both directions. A service endpoint is admitted by a virtual network rule on the resource, and the subnet must be named there; the resource's public endpoint stays on. A private endpoint is admitted by private link consent, and the public endpoint can then be disabled entirely.
The naming contract is the part teams miss. Service endpoint traffic keeps resolving to the public address, because the route does the redirection. Private endpoint traffic needs a privatelink record, because no route trick turns a public name into a private destination.
The blast radius follows the object. One service endpoint covers every resource of that service from the subnet, and a service endpoint policy is the only way to narrow it to specific resources. One private endpoint covers exactly one resource and subresource, which is why blob, file and queue each need their own endpoint.
On-premises and cost complete the comparison. A service endpoint does not admit on-premises clients, which must be allowed through public IP rules instead. A private endpoint does admit them once routing and DNS exist, and it is billed hourly per endpoint plus per GB.
| Dimension | Service endpoint | Private endpoint |
|---|---|---|
| Address the client uses | The service's public IP | A private IP from the endpoint subnet |
| Name resolution | Unchanged, public answer | Privatelink zone record overrides the answer |
| Subnet requirement | Endpoint enabled on the client subnet | Endpoint NIC in a subnet, policy setting decides filtering |
| What the service sees | The subnet's private address, via the service tag | A connection from the private endpoint |
| On-premises clients | Not covered, allow public IPs instead | Covered once routing and DNS are in place |
| Public endpoint | Stays enabled | Can be disabled after validation |
| Cost shape | No charge for the endpoint | Hourly per endpoint plus per GB |
Table 1 keeps the two models apart by contract rather than by intent. The rows that decide most designs are the DNS answer, the on-premises path and the cost shape; the rest follow from them. A design that claims private access while the name still resolves public has chosen the first column without saying so.
Figure 4 shows the failure that looks like success. On the left the service endpoint path works and leaves the account public; on the right the same call reaches a private address. The red band is the third case, where the endpoint exists but the zone was never linked, so the client is refused by the public endpoint the design meant to retire.
Test Connectivity from the Actual Terraform Runner
The runner is part of the topology, and usually it is not in the VNet. A hosted CI agent reaches the ARM control plane over the internet, so it can plan and apply a private endpoint it cannot use. A self-hosted agent inside the spoke inherits the subnet's route table, NSG and DNS, which makes it the only honest place to test from.
A successful apply proves the control plane, not the data plane. The azurerm provider creates the endpoint through ARM, and refreshing that resource reads its control-plane state rather than the blob. A plan can be clean while every data-plane call from the same machine fails, and that is expected rather than a defect.
Resolve from a client that uses the VNet resolver. The runner's own resolver answers for the runner, so a public answer there says nothing about the subnet. Query from a NIC in snet-app, or use a connectivity test that runs from that subnet.
Read effective routes on the client NIC, not the route table. The table shows what was written; the NIC shows what survived longest-prefix selection. A route that exists in the table but loses to a more specific system route is invisible until you look at the effective list.
Prove the allowed path, then the denied path. An allowed read should show a private destination address and a success; a denied read should show a refusal from the service, not a hang. The distinction matters because a refusal means DNS and routing worked and authorization said no.
Break DNS last and restore it first. Unlinking the zone is the cleanest way to prove the name is what steers traffic, and it is also the fastest way to strand your own session. Record the answer before and after, then restore the link before any other test.
Destroy in reverse and look for what bills. Endpoint NICs, zone links, NAT gateways and public IPs all survive a partial destroy. Check the state list before the portal, because the state names the owner and the portal shows the subscription.
Test Connectivity from the Actual Terraform Runner
Status: design-only. One spoke, one hub, one storage account and one runner in snet-app; the trace is a design, not a claim that it ran.
Prerequisites. Terraform 1.17.1 and hashicorp/azurerm 5.13.0, a subscription with the Network and Storage providers registered, a storage account, and a self-hosted runner or jump host in the spoke.
Steps.
- Apply the network stack: VNet,
snet-app,snet-pe, NSG, route table and peering. - Apply the storage account and the private endpoint with a zone group for the blob zone.
- Record the endpoint NIC address and the record name the zone group created.
- Resolve the blob name from the runner in
snet-appand note whether the answer is private. - Read the effective routes on the runner NIC and confirm the peering entry won.
- Read one blob with the workload identity and record the destination address.
- Unlink the zone, resolve again, and record the public answer.
- Restore the link, disable public access, and repeat the read from outside the VNet.
| Check | Method | Pass condition | Failure signal |
|---|---|---|---|
| Resolution | Resolve from a NIC in snet-app | Answer is the endpoint address | Public answer, so DNS is unfinished |
| Route | Effective routes on the client NIC | Peering entry wins for the hub prefix | None route wins, or no peering entry |
| Allowed call | Read a blob as the workload identity | Success with a private destination | Timeout, which points at NSG or route |
| Denied call | Read after public access is disabled from outside | Refusal from the service | Success, which means the public path is open |
| DNS proof | Unlink the zone and resolve again | Public answer returns | Still private, so another zone answers |
| Cleanup | List state after destroy | No endpoint NIC or zone link remains | Orphan NIC or link still billing |
Expected observation. The runner in the spoke resolves the blob name to the endpoint address, the effective route list shows the peering entry, and the read succeeds against the private destination. After the zone is unlinked the answer becomes public, and after public access is disabled the same call is refused rather than timing out.
Failure check. The lab fails if the answer stays public with the zone linked, if the allowed read times out, if the outside read succeeds after public access is disabled, or if a plan is treated as proof of connectivity. It also fails if the only evidence is a terminal transcript.
Cost and cleanup. One private endpoint, one zone and link set, one NAT gateway if you added egress, and one small runner. Destroy the endpoint before the zone, release any public IP, and confirm no interface remains in snet-pe.
Evidence to keep. The resolved address, the effective route list, one allow and one deny response, and the state list after destroy.
Next in the Series
In Azure Compute: VMs, Scale Sets, Disks and Application Health, we'll explore Release compute capacity with verified images, identities and load-balancing behavior.