Hello @Sushmitha Suresh ,
Welcome to Microsoft Q&A Platform. Thank you for reaching out & hope you are doing well.
I understand that you've 2 VM's (web and DB server) in a subnet and you added NSG rule at subnet level which by default allows all outbound traffic to Internet, but you want to deny Internet access on the DB server only and would like to know where to add this rule.
For inbound traffic, Azure processes the rules in a network security group associated to a subnet first, if there's one, and then the rules in a network security group associated to the network interface, if there's one.
Refer: https://learn.microsoft.com/en-us/azure/virtual-network/network-security-group-how-it-works
If you want to deny the Internet to the DB server only, then you can do one of the following:
- Add a Deny rule on the existing subnet-level NSG with the source as Internet and destination as the IP address of the DB server with a lower number priority than the default rule.
- Or create a new NSG with deny action, source as Internet and destination "All" and add it to the NIC of the DB server.
However, Azure recommends the below:
Unless you have a specific reason to, we recommend that you associate a network security group to a subnet, or a network interface, but not both. Since rules in a network security group associated to a subnet can conflict with rules in a network security group associated to a network interface, you can have unexpected communication problems that require troubleshooting.
So, my advice is to go with the first option and add a Deny outbound rule on the existing subnet-level NSG with the source as Internet and destination as the private IP address of the DB server with a lower number priority than the default rule as below:
Kindly let us know if the above helps or you need further assistance on this issue.
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.