Secure Azure Networks: Network Security Groups, Application Security Groups, Azure Firewall, Bastion and Service Endpoints
Network Security Groups
- An NSG is a list of allow and deny rules applied to a subnet or a NIC
- Rules have: priority (100 to 4096, lowest number first), source, destination, port, protocol and action
- NSGs are stateful: if inbound is allowed, the reply is allowed automatically
- If both subnet and NIC have an NSG, both must allow the traffic
| Default rule | Effect |
|---|---|
| AllowVnetInBound (65000) | Traffic inside the VNet is allowed |
| AllowAzureLoadBalancerInBound (65001) | Load balancer probes allowed |
| DenyAllInBound (65500) | Everything else inbound is blocked |
| AllowInternetOutBound (65001) | Outbound to internet allowed |
bash
az network nsg create -g rg-net -n nsg-web
az network nsg rule create -g rg-net --nsg-name nsg-web -n allow-https --priority 100 --direction Inbound --access Allow \
--protocol Tcp --destination-port-ranges 443 --source-address-prefixes Internet
az network nsg rule create -g rg-net --nsg-name nsg-web -n deny-ssh-internet --priority 200 --direction Inbound --access Deny \
--protocol Tcp --destination-port-ranges 22 --source-address-prefixes Internet
az network vnet subnet update -g rg-net --vnet-name vnet-app -n web --network-security-group nsg-web
Service tags Use service tags such as
Internet, VirtualNetwork, Storage and AzureLoadBalancer instead of long IP lists.
Application Security Groups (ASG)
Group VMs by role (for example asg-web, asg-db) and write rules using the groups. You do not need to change rules when IPs change.
bash
az network asg create -g rg-net -n asg-web
az network asg create -g rg-net -n asg-db
az network nsg rule create -g rg-net --nsg-name nsg-data -n web-to-db --priority 100 --access Allow --protocol Tcp \
--destination-port-ranges 1433 --source-asgs asg-web --destination-asgs asg-db
Troubleshoot NSG Rules
- Effective security rules on a NIC show the combined rules
- IP flow verify in Network Watcher tells which rule allows or denies a packet
- NSG flow logs record traffic for analysis
Azure Firewall
| Rule type | Use |
|---|---|
| DNAT | Publish an internal service through the firewall's public IP |
| Network rules | Allow by IP, port, protocol or service tag |
| Application rules | Allow by FQDN (for example *.microsoft.com) and HTTP/S |
- A managed, central firewall in a hub VNet. Force traffic through it with a route table (
0.0.0.0/0to firewall IP) - SKUs: Basic, Standard, Premium (TLS inspection, IDPS)
- Use Firewall Policy to manage rules
Azure Bastion
bash
az network vnet subnet create -g rg-net --vnet-name vnet-app -n AzureBastionSubnet --address-prefixes 10.20.250.0/26
az network public-ip create -g rg-net -n pip-bastion --sku Standard
az network bastion create -g rg-net -n bastion-app --vnet-name vnet-app --public-ip-address pip-bastion --sku Basic
- Browser-based RDP and SSH over TLS to VMs that have no public IP and no open management ports
Service Endpoints and Private Endpoints
| Service endpoint | Private endpoint | |
|---|---|---|
| How | Subnet gets a route to the service over the Azure backbone | A private IP in your subnet for the service |
| Service address | Still the public IP of the service | Private IP via private DNS |
| On-premises access | No | Yes (through VPN or ExpressRoute) |
| Cost | Free | Per endpoint and data |
| Best for | Simple restriction of PaaS to a subnet | Strong isolation, disable public access |
Practice
- Create an NSG that allows HTTPS and denies SSH from the internet
- Use ASGs to allow web to database only
- Deploy Bastion and connect to a VM without a public IP
- Use IP flow verify to test a rule
Conclusion
Use NSGs and ASGs to filter traffic, Azure Firewall for central control, Bastion for safe admin access and private endpoints to remove public exposure of PaaS services.
Quick Summary: NSG; ASG; troubleshoot; Firewall; Bastion; endpoints.

