You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-network/virtual-network-nsg-manage-log.md
+23-19Lines changed: 23 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ author: asudbring
7
7
manager: mtillman
8
8
ms.service: azure-virtual-network
9
9
ms.topic: how-to
10
-
ms.date: 03/22/2023
10
+
ms.date: 07/11/2025
11
11
ms.author: allensu
12
12
ms.custom: devx-track-azurecli
13
13
ms.devlang: azurecli
@@ -20,12 +20,12 @@ A network security group (NSG) includes rules that allow or deny traffic to a vi
20
20
21
21
When you enable logging for an NSG, you can gather the following types of resource log information:
22
22
23
-
-**Event**: Entries are logged for which NSG rules are applied to virtual machines, based on a MAC address.
24
-
-**Rule counter**: Contains entries for how many times each NSG rule is applied to allow or deny traffic. The status for these rules is collected every 300 seconds.
23
+
-**Event**: Entries are logged for the NSG rules applied to virtual machines, based on a MAC address.
24
+
-**Rule counter**: Tracks how many times each NSG rule is applied to allow or deny traffic. The status for these rules is collected every 300 seconds.
25
25
26
-
Resource logs are available only for NSGs deployed through the Azure Resource Manager deployment model. You can't enable resource logging for NSGs deployed through the classic deployment model. For more information, see [Understand deployment models](../azure-resource-manager/management/deployment-models.md).
26
+
Resource logs are available only for NSGs deployed through the Azure Resource Manager (ARM) deployment model. You can't enable resource logging for NSGs deployed through the classic deployment model. For more information, see [Understand deployment models](../azure-resource-manager/management/deployment-models.md).
27
27
28
-
Resource logging is enabled separately for *each* NSG for which to collect diagnostic data. If you're interested in *activity*, or *operational*, logs instead, see [Overview of Azure platform logs](/azure/azure-monitor/essentials/platform-logs-overview). If you're interested in IP traffic flowing through NSGs, see [Flow logs for network security groups](../network-watcher/network-watcher-nsg-flow-logging-overview.md).
28
+
Resource logging is enabled separately for *each* NSG from which you want to collect diagnostic data. If you're interested in *activity* or *operational* logs instead, see [Overview of Azure platform logs](/azure/azure-monitor/essentials/platform-logs-overview). If you're interested in IP traffic flowing through the virtual network, see [Virtual network flow logs](../network-watcher/vnet-flow-logs-overview.md).
29
29
30
30
## Enable logging
31
31
@@ -36,7 +36,7 @@ You can use the [Azure portal](#azure-portal), [Azure PowerShell](#azure-powersh
36
36
1. Sign in to the [Azure portal](https://portal.azure.com).
37
37
1. In the search box at the top of the Azure portal, enter **network security groups**. Select **Network security groups** in the search results.
38
38
1. Select the NSG for which you want to enable logging.
39
-
1. Under **Monitoring**, select **Diagnostic settings**, and then select **Add diagnostic setting**.
39
+
1. Under **Monitoring**, select **Diagnostic settings**, then select **Add diagnostic setting**.
40
40
41
41
:::image type="content" source="./media/virtual-network-nsg-manage-log/turn-on-diagnostics.png" alt-text="Screenshot that shows the diagnostic settings for an NSG with Add diagnostic setting highlighted." lightbox="./media/virtual-network-nsg-manage-log/turn-on-diagnostics.png":::
There are two categories of logging that you can enable. For more information, see [Log categories](#log-categories). Enable resource logging for the NSG with the [New-AzDiagnosticSetting](/powershell/module/az.monitor/new-azdiagnosticsetting) cmdlet. The following example logs both event and counter category data to the workspace for an NSG. It uses the IDs for the NSG and workspace that you got with the previous commands:
86
+
There are two categories of logging that you can enable. For more information, see [Log categories](#log-categories). Enable resource logging for the NSG with the [New-AzDiagnosticSetting](/powershell/module/az.monitor/new-azdiagnosticsetting) cmdlet. The following example logs both event and rule counter category data to the workspace for an NSG. It uses the IDs for the NSG and workspace that you obtained with the previous command:
87
87
88
88
```azurepowershell-interactive
89
89
New-AzDiagnosticSetting `
@@ -102,7 +102,7 @@ View and analyze logs. For more information, see [View and analyze logs](#view-a
102
102
103
103
You can run the commands in this section in [Cloud Shell](https://shell.azure.com/bash) or by running the Azure CLI from your computer. Cloud Shell is a free interactive shell. It has common Azure tools preinstalled and configured to use with your account.
104
104
105
-
If you run the CLI from your computer, you need version 2.0.38 or later. Run `az --version` on your computer to find the installed version. If you need to upgrade, see [Install the Azure CLI](/cli/azure/install-azure-cli). If you run the CLI locally, you also need to run `az login` to sign in to Azure with an account that has the [necessary permissions](virtual-network-network-interface.md#permissions).
105
+
If you run the CLI from your computer, you need version 2.0.28 or later. Run `az --version` on your computer to find the installed version. If you need to upgrade, see [Install the Azure CLI](/cli/azure/install-azure-cli). If you run the CLI locally, you also need to run `az login` to sign in to Azure with an account that has the [necessary permissions](virtual-network-network-interface.md#permissions).
106
106
107
107
To enable resource logging, you need the ID of an existing NSG. If you don't have an existing NSG, create one by using [az network nsg create](/cli/azure/network/nsg#az-network-nsg-create).
108
108
@@ -116,9 +116,9 @@ nsgId=$(az network nsg show \
116
116
--output tsv)
117
117
```
118
118
119
-
You can write resource logs to different destination types. For more information, see [Log destinations](#log-destinations). In this article, logs are sent to a Log Analytics workspace destination, as an example. For more information, see [Log categories](#log-categories).
119
+
You can write resource logs to different destination types. For more information, see [Log destinations](#log-destinations). In this article, logs are sent to a Log Analytics workspace destination as an example. For more information, see [Log categories](#log-categories).
120
120
121
-
Enable resource logging for the NSG with [az monitor diagnostic-settings create](/cli/azure/monitor/diagnostic-settings#az-monitor-diagnostic-settings-create). The following example logs both event and counter category data to an existing workspace named `myWorkspace`, which exists in a resource group named `myWorkspaces`. It uses the ID of the NSG that you saved by using the previous command.
121
+
Enable resource logging for the NSG with [az monitor diagnostic-settings create](/cli/azure/monitor/diagnostic-settings#az-monitor-diagnostic-settings-create). The following example logs both event and rule counter category data to an existing workspace named `myWorkspace`, which exists in a resource group named `myWorkspaces`. It uses the ID of the NSG you obtained with the previous command:
122
122
123
123
```azurecli-interactive
124
124
az monitor diagnostic-settings create \
@@ -146,11 +146,14 @@ You can send diagnostics data to the following options:
146
146
147
147
## Log categories
148
148
149
-
JSON-formatted data is written for the following log categories: event and rule counter.
149
+
JSON-formatted data is written for the following log categories:
150
+
151
+
-[Event](#event)
152
+
-[Rule counter](#rule-counter)
150
153
151
154
### Event
152
155
153
-
The event log contains information about which NSG rules are applied to virtual machines, based on a MAC address. The following data is logged for each event. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
156
+
The event log contains information of NSG rules applied to virtual machines, based on a MAC address. The following data is logged for each event. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
154
157
155
158
```json
156
159
{
@@ -181,7 +184,7 @@ The event log contains information about which NSG rules are applied to virtual
181
184
182
185
### Rule counter
183
186
184
-
The rule counter log contains information about each rule applied to resources. The following example data is logged each time a rule is applied. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
187
+
The rule counter log contains information of each NSG rule applied to resources. The following example data is logged each time a rule is applied. In the following example, the data is logged for a virtual machine with the IP address 192.168.1.4 and a MAC address of 00-0D-3A-92-6A-7C.
185
188
186
189
```json
187
190
{
@@ -204,29 +207,30 @@ The rule counter log contains information about each rule applied to resources.
204
207
```
205
208
206
209
> [!NOTE]
207
-
> The source IP address for the communication isn't logged. You can enable [NSG flow logging](../network-watcher/network-watcher-nsg-flow-logging-portal.md) for an NSG, which logs all of the rule counter information and the source IP address that initiated the communication. NSG flow log data is written to an Azure Storage account. You can analyze the data with the [traffic analytics](../network-watcher/traffic-analytics.md) capability of Azure Network Watcher.
210
+
> The source IP address for the communication isn't logged. You can enable [Virtual network flow logs](../network-watcher/vnet-flow-logs-overview.md) for the NSG's virtual network, which logs all of the IP traffic flowing through a virtual network. Virtual network flow log data is written to an Azure Storage account in the same subscription and region of the virtual network. You can analyze the data with the [traffic analytics](../network-watcher/traffic-analytics.md) capability of Azure Network Watcher.
208
211
209
212
## View and analyze logs
210
213
211
214
If you send diagnostics data to:
212
215
213
216
-**Azure Monitor logs**: You can use the [NSG analytics](/azure/azure-monitor/insights/azure-networking-analytics?toc=%2fazure%2fvirtual-network%2ftoc.json) solution for enhanced insights. The solution provides visualizations for NSG rules that allow or deny traffic, per MAC address, of the network interface in a virtual machine.
214
-
-**Azure Storage account**: Data is written to a *PT1H.json* file. You can find the:
217
+
-**Azure Storage account**: Data is written to a *PT1H.json* file. You can find the following logs:
218
+
219
+
- Event log found in the path: *insights-logs-networksecuritygroupevent/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
215
220
216
-
- Event log that's in the following path: *insights-logs-networksecuritygroupevent/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
217
-
- Rule counter log that's in the following path: *insights-logs-networksecuritygrouprulecounter/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
221
+
- Rule counter log found in the path: *insights-logs-networksecuritygrouprulecounter/resourceId=/SUBSCRIPTIONS/[ID]/RESOURCEGROUPS/[RESOURCE-GROUP-NAME-FOR-NSG]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG NAME]/y=[YEAR]/m=[MONTH/d=[DAY]/h=[HOUR]/m=[MINUTE]*
218
222
219
223
To learn how to view resource log data, see [Azure platform logs overview](/azure/azure-monitor/essentials/platform-logs-overview).
220
224
221
225
## Related content
222
226
223
227
- For more information about activity logging, see [Overview of Azure platform logs](/azure/azure-monitor/essentials/platform-logs-overview).
224
228
225
-
Activity logging is enabled by default for NSGs created through either Azure deployment model. To determine which operations were completed on NSGs in the activity log, look for entries that contain the following resource types:
229
+
Activity logging is enabled by default for NSGs created through either the ARM or classic deployment model. To determine which operations were completed on NSGs in the activity log, look for entries that contain the following resource types:
- To learn how to log diagnostic information, see [Log network traffic to and from a virtual machine by using the Azure portal](../network-watcher/network-watcher-nsg-flow-logging-portal.md).
236
+
- To learn how to log diagnostic information for traffic flowing through the virtual network that match NSG rules, see [how to manage virtual network flow logs](../network-watcher/vnet-flow-logs-manage.md).
0 commit comments