Skip to content

Commit fa470ea

Browse files
committed
add create section
1 parent 583babe commit fa470ea

File tree

1 file changed

+125
-3
lines changed

1 file changed

+125
-3
lines changed

articles/network-watcher/nsg-flow-logs-manage.md

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ In this article, you learn how to create, change, enable, disable, or delete a n
7171

7272
*Microsoft.Insights* provider must be registered to successfully log traffic flowing through a virtual network. If you aren't sure if the *Microsoft.Insights* provider is registered, check its status in the Azure portal by following these steps:
7373

74-
1. In the search box at the top of the portal, enter *subscriptions*. Select **Subscriptions** from the search results.
74+
1. In the search box at the top of the portal, enter ***subscriptions***. Select **Subscriptions** from the search results.
7575

7676
:::image type="content" source="./media/subscriptions-portal-search.png" alt-text="Screenshot that shows how to search for Subscriptions in the Azure portal." lightbox="./media/subscriptions-portal-search.png":::
7777

7878
1. Select the Azure subscription that you want to enable the provider for in **Subscriptions**.
7979

8080
1. Under **Settings**, select **Resource providers**.
8181

82-
1. Enter *insight* in the filter box.
82+
1. Enter ***insight*** in the filter box.
8383

8484
1. Confirm the status of the provider displayed is **Registered**. If the status is **NotRegistered**, select the **Microsoft.Insights** provider then select **Register**.
8585

86-
:::image type="content" source="./media/nsg-flow-logs-portal/register-microsoft-insights.png" alt-text="Screenshot that shows how to register Microsoft Insights provider in the Azure portal." lightbox="./media/nsg-flow-logs-portal/register-microsoft-insights.png":::
86+
:::image type="content" source="./media/register-microsoft-insights.png" alt-text="Screenshot that shows how to register Microsoft Insights provider in the Azure portal." lightbox="./media/register-microsoft-insights.png":::
8787

8888
# [**PowerShell**](#tab/powershell)
8989

@@ -105,6 +105,128 @@ az provider register --namespace 'Microsoft.Insights'
105105

106106
---
107107

108+
## Create a flow log
109+
110+
Create a flow log for your network security group. The flow log is saved in an Azure storage account.
111+
112+
# [**Portal**](#tab/portal)
113+
114+
1. In the search box at the top of the portal, enter ***network watcher***. Select **Network Watcher** from the search results.
115+
116+
1. Under **Logs**, select **Flow logs**.
117+
118+
1. In **Network Watcher | Flow logs**, select **+ Create** or **Create flow log** blue button.
119+
120+
:::image type="content" source="./media/nsg-flow-logs-portal/flow-logs.png" alt-text="Screenshot of Flow logs page in the Azure portal." lightbox="./media/nsg-flow-logs-portal/flow-logs.png":::
121+
122+
1. On the **Basics** tab of **Create a flow log**, enter or select the following values:
123+
124+
| Setting | Value |
125+
| ------- | ----- |
126+
| **Project details** | |
127+
| Subscription | Select the Azure subscription of your network security group that you want to log. |
128+
| Flow log type | Select **Network security group** then select **+ Select target resource**. <br> Select the network security group that you want to flow log, then select **Confirm selection**. |
129+
| Flow Log Name | Enter a name for the flow log or leave the default name. Azure portal uses ***{ResourceName}-{ResourceGroupName}-flowlog*** as a default name for the flow log. **myNSG-myResourceGroup-flowlog** is the default name used in this article. |
130+
| **Instance details** | |
131+
| Subscription | Select the Azure subscription of your storage account. |
132+
| Storage accounts | Select the storage account that you want to save the flow logs to. If you want to create a new storage account, select **Create a new storage account**. |
133+
| Retention (days) | Enter a retention time for the logs (this option is only available with [Standard general-purpose v2](../storage/common/storage-account-overview.md?toc=/azure/network-watcher/toc.json#types-of-storage-accounts) storage accounts). Enter *0* if you want to retain the flow logs data in the storage account forever (until you delete it from the storage account). For information about pricing, see [Azure Storage pricing](https://azure.microsoft.com/pricing/details/storage/). |
134+
135+
:::image type="content" source="./media/nsg-flow-logs-portal/create-nsg-flow-log-basics.png" alt-text="Screenshot of creating an NSG flow log in the Azure portal.":::
136+
137+
> [!NOTE]
138+
> If the storage account is in a different subscription, the network security group and storage account must be associated with the same Microsoft Entra tenant. The account you use for each subscription must have the [necessary permissions](required-rbac-permissions.md).
139+
140+
1. To enable traffic analytics, select **Next: Analytics** button, or select the **Analytics** tab. Enter or select the following values:
141+
142+
| Setting | Value |
143+
| ------- | ----- |
144+
| Flow logs version | Select the version of the network security group flow log, available options are: **Version 1** and **Version 2**. The default version is version 2. For more information, see [Flow logging for network security groups](nsg-flow-logs-overview.md). |
145+
| Enable traffic analytics | Select the checkbox to enable traffic analytics for your flow log. |
146+
| Traffic analytics processing interval | Select the processing interval that you prefer, available options are: **Every 1 hour** and **Every 10 mins**. The default processing interval is every one hour. For more information, see [Traffic analytics](traffic-analytics.md). |
147+
| Subscription | Select the Azure subscription of your Log Analytics workspace. |
148+
| Log Analytics Workspace | Select your Log Analytics workspace. By default, Azure portal creates ***DefaultWorkspace-{SubscriptionID}-{Region}*** Log Analytics workspace in ***defaultresourcegroup-{Region}*** resource group. |
149+
150+
:::image type="content" source="./media/nsg-flow-logs-portal/create-nsg-flow-log-analytics.png" alt-text="Screenshot that shows how to enable traffic analytics for a new flow log in the Azure portal.":::
151+
152+
> [!NOTE]
153+
> To create and select a Log Analytics workspace other than the default one, see [Create a Log Analytics workspace](/azure/azure-monitor/logs/quick-create-workspace?toc=/azure/network-watcher/toc.json)
154+
155+
1. Select **Review + create**.
156+
157+
1. Review the settings, and then select **Create**.
158+
159+
160+
# [**PowerShell**](#tab/powershell)
161+
162+
1. Get the properties of the network security group that you want to create the flow log for and the storage account that you want to use to store the created flow log using [Get-AzNetworkSecurityGroup](/powershell/module/az.network/get-aznetworksecuritygroup) and [Get-AzStorageAccount](/powershell/module/az.storage/get-azstorageaccount) respectively.
163+
164+
```azurepowershell-interactive
165+
# Place the network security group properties into a variable.
166+
$nsg = Get-AzNetworkSecurityGroup -Name 'myNSG' -ResourceGroupName 'myResourceGroup'
167+
168+
# Place the storage account properties into a variable.
169+
$sa = Get-AzStorageAccount -Name 'myStorageAccount' -ResourceGroupName 'myResourceGroup'
170+
```
171+
172+
> [!NOTE]
173+
> - If the storage account is in a different subscription, the network security group and storage account must be associated with the same Azure Active Directory tenant. The account you use for each subscription must have the [necessary permissions](required-rbac-permissions.md).
174+
175+
1. Create the flow log using [New-AzNetworkWatcherFlowLog](/powershell/module/az.network/new-aznetworkwatcherflowlog). The flow log is created in the Network Watcher default resource group **NetworkWatcherRG**.
176+
177+
```azurepowershell-interactive
178+
# Create a version 1 NSG flow log.
179+
New-AzNetworkWatcherFlowLog -Name 'myFlowLog' -Location 'eastus' -TargetResourceId $nsg.Id -StorageId $sa.Id -Enabled $true
180+
```
181+
182+
183+
# [**Azure CLI**](#tab/cli)
184+
185+
Create a flow log using [az network watcher flow-log create](/cli/azure/network/watcher/flow-log#az-network-watcher-flow-log-create). The flow log is created in the Network Watcher default resource group **NetworkWatcherRG**.
186+
187+
```azurecli-interactive
188+
# Create a version 1 NSG flow log.
189+
az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account 'myStorageAccount'
190+
```
191+
192+
```azurecli-interactive
193+
# Create a version 1 NSG flow log (the storage account is in a different resource group from the network security group).
194+
az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/StorageRG/providers/Microsoft.Storage/storageAccounts/myStorageAccount'
195+
```
196+
197+
> [!NOTE]
198+
> If the storage account is in a different subscription, the network security group and storage account must be associated with the same Azure Active Directory tenant. The account you use for each subscription must have the [necessary permissions](required-rbac-permissions.md).
199+
200+
## Create a flow log and traffic analytics workspace
201+
202+
1. Create a Log Analytics workspace using [az monitor log-analytics workspace create](/cli/azure/monitor/log-analytics/workspace#az-monitor-log-analytics-workspace-create).
203+
204+
```azurecli-interactive
205+
# Create a Log Analytics workspace.
206+
az monitor log-analytics workspace create --name 'myWorkspace' --resource-group 'myResourceGroup'
207+
```
208+
209+
1. Create a flow log using [az network watcher flow-log create](/cli/azure/network/watcher/flow-log#az-network-watcher-flow-log-create). The flow log is created in the Network Watcher default resource group **NetworkWatcherRG**.
210+
211+
```azurecli-interactive
212+
# Create a version 1 NSG flow log and enable traffic analytics for it.
213+
az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account 'myStorageAccount' --traffic-analytics 'true' --workspace 'myWorkspace'
214+
```
215+
216+
```azurecli-interactive
217+
# Create a version 1 NSG flow log and enable traffic analytics for it (storage account and traffic analytics workspace are in different resource groups from the network security group).
218+
az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/StorageRG/providers/Microsoft.Storage/storageAccounts/myStorageAccount' --traffic-analytics 'true' --workspace '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/WorkspaceRG/providers/Microsoft.OperationalInsights/workspaces/myWorkspace'
219+
```
220+
221+
> [!NOTE]
222+
> - The storage account can't have network rules that restrict network access to only Microsoft services or specific virtual networks.
223+
> - If the storage account is in a different subscription, the network security group and storage account must be associated with the same Azure Active Directory tenant. The account you use for each subscription must have the [necessary permissions](required-rbac-permissions.md).
224+
225+
226+
---
227+
228+
229+
108230
## Related content
109231
110232
- [Audit and deploy NSG flow logs using Azure Policy](nsg-flow-logs-policy-portal.md)

0 commit comments

Comments
 (0)