Part 33 ~๐ Azure NSGs in Action: From Theory to Real-World Security
Intermidiate Bonus~ Azure Networking
Part 33 ~๐ Azure NSGs in Action: From Theory to Real-World Security
Intermidiate Bonus~ Azure Networking
Youโve explored the theory behind NSGs. You know what they are, where they go, and how they work.
But theory isnโt enough.
Now itโs time to apply it โ step by step โ with real scenarios, best practices, and the kind of decisions cloud architects make every day.

Letโs move from โwhat is an NSGโ to โhow do I use it to secure my network?โ
๐งช Scenario: A Simple Two-Tier Architecture
Youโre building a basic web app in Azure:
- A Frontend subnet with web servers
- A Backend subnet with database servers
Your goals:
- โ Allow users to access the website
- โ Let web servers talk to the database
- โ Block backend servers from reaching the internet
- ๐ Secure admin access with RDP (temporarily)
Letโs build the NSGs to make this happen.
๐ง Step 1: Create NSGs
Youโll need two NSGs:
frontend-nsgโ attach to the frontend subnetbackend-nsgโ attach to the backend subnet
๐ง One subnet = one NSG. But one NSG can be reused across subnets if needed.
๐ Step 2: Define Custom Rules
๐ Step-by-Step: Building NSGs
๐ข Frontend NSG (Web Department)
โ Allow HTTP (Port 80) โ So users can access your website
โ Allow RDP (Port 3389) โ For admin access (but consider Bastion for production)
๐ง Best Practice: Never allow RDP from โAnyโ in production. Use IP whitelisting or Bastion.
๐๏ธ Backend NSG (Database Department)
โ Allow SQL (Port 1433) โ So web servers can query the database โ Restrict source to frontend subnet for tighter control
โ Allow RDP (Port 3389) โ For admin access
โ Deny Internet Outbound โ Prevent data exfiltration or accidental exposure
๐ง Industry Principle: Backend systems should be shielded from direct internet access. Always.
๐ Step 3: Understand Default Rules
Azure includes default rules in every NSG:

๐ง You canโt delete these โ but you can override them with custom rules (priority 100โ4096).
๐ง Rule Evaluation: Who Wins?
NSG rules are evaluated by priority:
- Lower number = higher priority
- First match wins
- Later rules are ignored
Example:
- Rule 100: Deny internet outbound
- Rule 200: Allow outbound to
8.8.8.8โ Result: Deny wins
โ Always check for rule conflicts. One misordered rule can break or expose your app.
๐งช Are These Rules Doing Anything Yet?
Not until a VM is deployed.
NSGs are like guards waiting at empty desks. Once a VM is connected to a NIC, traffic starts flowing โ and the NSG starts filtering.
๐ง Subnet-level NSGs apply to all NICs inside. NIC-level NSGs override or complement them.
โ Best Practices You Should Follow
Hereโs what experienced teams do:
- ๐ Start with deny-all, then allow only whatโs needed
- ๐งฑ Use subnet NSGs for broad control, NIC NSGs for exceptions
- ๐งช Test with Network Watcher before going live
- ๐ซ Avoid โAnyโ in production โ use IP ranges or service tags
- ๐ฆ Group similar VMs into subnets for easier rule management
- ๐งญ Name rules clearly:
Allow-HTTP-From-Internet,Deny-All-Outbound, etc. - ๐ง Use service tags (like Internet, VirtualNetwork) for cleaner rule
- ๐งญ Document rule intent in the NSG name and description
๐งญ Final Takeaways
- NSGs are stateless: they donโt remember past traffic
- Rules apply in both directions โ inbound and outbound
- Priority matters: lower number wins
- NSGs are your first layer of defense โ simple, fast, and essential
๐ Whatโs Next?
Youโve built NSGs. Youโve defined rules. Youโve secured your subnets.
But hereโs a real-world challenge:
What happens when you deploy 1,000 VMs into a single subnet?
Letโs say half of them are web servers, some are app servers, and others are database nodes. You want to allow HTTP only to web servers, SQL only to databases, and RDP only to a few admin boxes.
Now imagine writing NSG rules for each IP manually. Or worse โ trying to track which IP belongs to which role.
Thatโs where things break down.
โ NSGs donโt understand โroles.โ They only understand IPs.
So how do you group VMs by function, not by address?
In the next session, weโll explore Application Security Groups (ASGs) โ Azureโs way of tagging VMs by purpose and writing NSG rules that target those tags.
Itโs like saying:
โAllow HTTP to all machines tagged as WebServers.โ โBlock internet access from anything tagged as Backend.โ
No IPs. No manual tracking. Just clean, scalable logic.
Letโs make NSGs smarter โ by combining them with ASGs.
๋ฉํ๋ฐ์ดํฐ
- post_id
- 7e53fde6e59e
- slug
- part-6-azure-nsgs-in-action-from-theory-to-real-world-security-7e53fde6e59e
- url
- https://medium.com/@barmanshubham70/part-6-azure-nsgs-in-action-from-theory-to-real-world-security-7e53fde6e59e
- canonical_url
- https://medium.com/@barmanshubham70/part-6-azure-nsgs-in-action-from-theory-to-real-world-security-7e53fde6e59e
- author_url
- https://medium.com/@barmanshubham70
- status
- ok
- fetched_at
- 2026-06-10 08:34:46