Network Security Groups (NSGs) Overview

Network Security Groups (NSGs) act as a virtual firewall for your virtual machines and other Azure resources. They enable you to define security rules that allow or deny network traffic to and from resources in an Azure virtual network.

What are Network Security Groups?

An NSG contains a list of security rules that, when evaluated, allow or deny traffic based on attributes such as source and destination IP address, source and destination port, and protocol. NSGs can be associated with network interfaces (NICs) of virtual machines or with subnets within a virtual network.

Key Components of an NSG:

How NSGs Work

When network traffic is processed, the following occurs:

  1. Traffic is evaluated against the rules in the NSG associated with the NIC, if any.
  2. If no NSG is associated with the NIC, traffic is evaluated against the rules in the NSG associated with the subnet.
  3. Rules are evaluated based on their priority. The first rule that matches the traffic dictates the action (Allow or Deny).
  4. If no rule matches, the traffic is denied by default (for inbound) or allowed by default (for outbound).

Note: When an NSG is associated with both a subnet and a NIC, both NSGs are evaluated. Inbound traffic is first processed by the subnet NSG, then by the NIC NSG. Outbound traffic is first processed by the NIC NSG, then by the subnet NSG.

Benefits of Using NSGs

Common Use Cases

Understanding and effectively configuring Network Security Groups is crucial for maintaining a secure and well-controlled Azure environment.

Related Articles: