Dev.to Security πŸ” Cybersecurity πŸ‘ 2 πŸ“– 10 min read

Azure VM Can't Connect? 9 Causes (NSGs and Routes) and How to Find Yours

Prefer video? The full walkthrough is at the top of this post, and the most common cases have one-minute Shorts right where they come up. This guide first went out on the Azure Cloud in a Minute newsletter. The

Azure VM Can't Connect? 9 Causes (NSGs and Routes) and How to Find Yours

Prefer video? The full walkthrough is at the top of this post, and the most common cases have one-minute Shorts right where they come up. This guide first went out on the Azure Cloud in a Minute newsletter.

The one-minute answer

The problem: a VM can’t reach something, or nothing can reach the VM. The app is fine, the port is open on the server, and the connection still times out.

How Azure decides: two things in the network sit between the VM and the other side. Network security groups (NSGs) decide whether a flow is allowed, and there can be one on the subnet and another on the network interface. Routes decide where the packet goes next, and one user-defined route can send it to a firewall that drops it.

Where to look first: don’t read rules by eye. Network Watcher has two checks that answer the question directly: IP flow verify names the exact NSG rule that allows or denies a flow, and next hop shows where Azure sends the packet. Run both before you change anything.

The rest of this guide explains how Azure applies NSGs and routes, goes through the causes in the order worth checking, and ends with a checklist.

How Azure decides

A flow has to pass the security rules and then find a route. Here is how each part works.

NSGs: two layers, in a fixed order. An NSG can sit on the subnet, on the VM’s network interface, or both. When both exist, both have to allow the flow:

  • Inbound: the subnet NSG first, then the NIC NSG.
  • Outbound: the NIC NSG first, then the subnet NSG.
  • Traffic between two VMs in the same subnet goes through the same checks.

Inside one NSG, the lowest number wins. Rules have a priority from 100 to 4096. Azure reads them from the lowest number up and stops at the first rule that matches. Every NSG also has default rules you can’t remove, only override with a lower number:

  • Inbound: AllowVnetInBound (65000), AllowAzureLoadBalancerInBound (65001), DenyAllInBound (65500).
  • Outbound: AllowVnetOutBound (65000), AllowInternetOutBound (65001), DenyAllOutBound (65500).

NSGs are stateful. If a flow is allowed in one direction, the reply is allowed back automatically. You only write rules for the side that starts the connection.

Admin rules come first. If your organization uses Azure Virtual Network Manager, its security admin rules are evaluated before any NSG. A Deny there stops the traffic, an Always Allow skips the NSGs entirely, and a plain Allow passes the flow on to the NSGs.

Routes: the most specific prefix wins. For each packet, Azure picks the route with the longest matching prefix. When two routes have the same prefix, a user-defined route (UDR) beats a BGP route, and a BGP route beats a system route. The next hop can be the virtual network, the internet, a virtual network gateway, a virtual appliance such as a firewall, or None, which drops the packet. One exception: system routes for the virtual network, peerings and service endpoints win over BGP routes even when the BGP route is more specific, and a route table can’t override a service endpoint route.

Start with two checks

Both are in Network Watcher, and both answer in seconds. The VM has to be running, and Network Watcher has to be enabled in its region, which Azure does automatically when you create a virtual network there.

1. IP flow verify: is the flow allowed? Give it the direction, protocol, the VM’s IP and port, and the other side’s IP and port. It checks every NSG on the VM’s subnet and NIC, plus any Virtual Network Manager admin rules, and returns Allow or Deny with the name of the rule that decided it.

az network watcher test-ip-flow --vm myVM --resource-group myRG \
  --direction Inbound --protocol TCP \
  --local 10.0.0.4:443 --remote 203.0.113.10:60000
Access  RuleName
------  ------------------------------------
Deny    defaultSecurityRules/DenyAllInBound

It tests TCP and UDP only. For ICMP, such as ping, use NSG diagnostics instead.

2. Next hop: where does the packet go? Give it the VM’s IP and the destination IP. It returns the next hop type, the next hop IP, and the route table that holds the route, or System Route if no UDR applies.

az network watcher show-next-hop --vm myVM --resource-group myRG \
  --source-ip 10.0.0.4 --dest-ip 10.20.1.5

If IP flow verify says Allow and next hop points where you expect, this VM’s own rules and first hop are fine. Both tools only look at this VM, so check the rest next: the NSGs at the other end (run IP flow verify on that VM too), the device at the next hop, the return path, and the VM itself.

The causes, one by one

Check them in this order. The first four are security rules, which IP flow verify catches. The next three are routes, which next hop catches. The last two are outside both checks.

A rule says no

1. A Deny rule with a lower number. You added an Allow for port 443 at priority 300, but a broader Deny at priority 200 matches first, and processing stops there. This often comes from a β€œdeny all from the internet” rule someone added for safety.

Fix: give your Allow a lower number than the Deny, or narrow the Deny. IP flow verify names the rule that matched.

2. The other NSG says no. You fixed the NIC NSG, but the subnet NSG still denies the flow, or the other way round. For inbound traffic the subnet NSG is checked first, so a deny there means the NIC NSG never gets a say.

Fix: check both layers. Microsoft recommends using one or the other, not both, because rules at two levels can conflict.

3. Nothing allows it. Without a matching Allow, the default DenyAllInBound rule blocks the flow. AllowVnetInBound uses the VirtualNetwork tag: your address space, peered and on-premises networks, and prefixes used in your UDRs. It isn’t meant for internet clients, which need an Allow of their own. Microsoft notes the tag might also contain default routes, so after adding a 0.0.0.0/0 UDR, check what it covers in the effective security rules. A VM with a Standard public IP is secure by default: traffic from the internet needs an NSG with an explicit Allow.

Fix: add an Allow for the exact source, port and protocol. Keep the source as narrow as you can, such as your office IP rather than Any.

4. A Virtual Network Manager admin rule. If your organization manages networks centrally, a security admin rule is evaluated before your NSGs. Its Deny wins, whatever your NSG says.

Fix: IP flow verify names admin rules too. No NSG rule can override an admin Deny, so whoever owns the Virtual Network Manager configuration has to change it.

The packet goes the wrong way

5. A route sends it to a firewall that drops it. A UDR with 0.0.0.0/0 or a broad private range points at Azure Firewall or another appliance. Next hop shows VirtualAppliance and the route table. The NSGs allow the flow, and the firewall has no rule for it. A third-party appliance also needs IP forwarding turned on for its NIC, or it can’t forward traffic that isn’t addressed to it.

Fix: add the rule on the firewall, or send that destination a different way with a more specific route.

6. Replies come back a different way. Traffic arrives on the VM’s public IP or a public load balancer, but a 0.0.0.0/0 route sends the reply through the firewall. The firewall is stateful, never saw the request, and drops the reply.

Fix: make both directions take the same path. Bring the traffic in through the firewall with a DNAT rule, instead of a public IP on the VM. For a public load balancer behind a firewall, Microsoft’s guide also adds a route for the firewall’s public IP with next hop Internet, and notes that an internal load balancer behind the firewall avoids the problem.

7. There’s no route, or the next hop is None. Next hop None means Azure drops the packet. Traffic to on-premises also fails if the route table on the subnet has gateway route propagation disabled, because the routes learned from the VPN or ExpressRoute gateway don’t reach that subnet.

Fix: compare the VM’s effective routes with where the traffic should go, and turn propagation back on or add the missing route. A UDR with next hop Virtual network gateway works only with a VPN gateway.

Outside the network checks

8. The subnet has no way out to the internet. New virtual networks now use private subnets by default: the portal already does, and so does the API version released after March 31, 2026. A VM there gets no default outbound IP, so internet calls, Windows activation and Windows Update fail even though every NSG allows them, and IP flow verify still says Allow. Existing virtual networks aren’t changed, and templates pinned to older API versions keep the old behaviour. In a private subnet, a UDR with next hop Internet also stops working.

Fix: add an explicit way out. Microsoft recommends a NAT gateway for most cases. A Standard public IP, a load balancer with outbound rules, or a firewall with a UDR also work. Email on port 25 is a separate case: Azure blocks outbound port 25 for pay-as-you-go subscriptions, among others, so send through an authenticated SMTP relay, usually on port 587.

This one changed recently and catches a lot of new VMs, so here it is in under a minute:

9. The VM itself. If NSGs and routes are fine, look inside the VM: the operating system firewall, a service that isn’t running, or one that only listens on 127.0.0.1.

Fix: from the VM, check the service is listening on the right address and port, and check the OS firewall rules.

How to check it

Run these with the VM running, for the exact IPs and port of the failing connection.

1. Test the flow. IP flow verify, as above. Note the rule name it returns.

2. See every rule that applies. Effective security rules combine the subnet NSG and the NIC NSG in one list. In the portal: the VM β†’ Networking β†’ Network settings β†’ the network interface β†’ Help β†’ Effective security rules. The portal shows the first 50 rules; Download gives you all of them. Nothing shows if no NSG is attached to the NIC or its subnet.

az network nic list-effective-nsg --name myVM-nic --resource-group myRG

3. See every route that applies. Effective routes show the system routes, your UDRs and the gateway routes for that NIC, and which ones are active. In the portal they sit next to the effective security rules, under Help.

az network nic show-effective-route-table --name myVM-nic --resource-group myRG

4. Find the next hop. Next hop, as above. VirtualAppliance means a firewall or appliance decides next, so check its rules and logs.

5. Check the subnet’s way out. For internet traffic, look at the subnet’s Default outbound access setting and whether it has a NAT gateway.

6. Test again with a new connection. NSG rules only affect new connections. When you remove a rule that allowed a connection, a session that was already open stays up. It works the other way too: a new Deny doesn’t drop a session that’s already open. So retest with a fresh connection, not a window you already had open.

Checklist

  1. The VM is running, and you test with the exact IPs, port and protocol of the failing connection.
  2. IP flow verify says Allow, in the direction the connection starts.
  3. No lower-numbered Deny matches, in the subnet NSG or the NIC NSG.
  4. Both NSG layers allow the flow, if both exist.
  5. Traffic from the internet has an explicit Allow for a narrow source.
  6. No Virtual Network Manager admin rule denies it.
  7. Next hop points where you expect, and any firewall at that hop allows the flow.
  8. Replies take the same path as requests.
  9. Routes to on-premises are in the effective routes, with gateway route propagation on where needed.
  10. For internet access, the subnet has an explicit way out, such as a NAT gateway.
  11. Inside the VM, the service is listening on the right address and the OS firewall allows the port.
  12. You retested with a new connection.

From the field

Most of my Azure networking work has been multi-site: plants and offices joined into hub-and-spoke networks, with a firewall in the hub. When a VM couldn’t connect, everyone opened the NSG first. The cases that took longest were rarely there. They were a 0.0.0.0/0 route sending replies through the firewall, or a new subnet the firewall had no rule for. So now I run IP flow verify and next hop for the exact flow before I change anything. Those two answers usually tell me which team to call: the network team, the firewall owner, or the server team.

Keep going

Related guides:

Shorts from this guide: NSG allow rule ignored, NSG allows 443, traffic still blocked, new VM has no internet.

Get the next one: new guides go out first on the Azure Cloud in a Minute newsletter, with a long video and Shorts on YouTube. I also run AWS Cloud in a Minute and Kubernetes in a Minute.

Sources

All from Microsoft Learn:

Independent writer, not affiliated with or endorsed by Microsoft.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.