Virtual network flow logging is a feature of Azure Network Watcher that allows you to log information about IP traffic flowing through an Azure virtual network. For more information about virtual network flow logging, see Virtual network flow logs overview.
In this article, you learn how to create, change, enable, disable, or delete a virtual network flow log using the Azure portal, PowerShell, and Azure CLI.
Prerequisites
Register Insights provider
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:
In the search box at the top of the portal, enter subscriptions. Select Subscriptions from the search results.
Select the Azure subscription that you want to enable the provider for in Subscriptions.
Under Settings, select Resource providers.
Enter insight in the filter box.
Confirm the status of the provider displayed is Registered. If the status is NotRegistered, select the Microsoft.Insights provider then select Register.
Microsoft.Insights provider must be registered to successfully log traffic in a virtual network. If you aren't sure if the Microsoft.Insights provider is registered, use Register-AzResourceProvider to register it.
# Register Microsoft.Insights provider.
Register-AzResourceProvider -ProviderNamespace Microsoft.Insights
Microsoft.Insights provider must be registered to successfully log traffic in a virtual network. If you aren't sure if the Microsoft.Insights provider is registered, use az provider register to register it.
# Register Microsoft.Insights provider.
az provider register --namespace Microsoft.Insights
Create a flow log
Create a flow log for your virtual network, subnet, or network interface. This flow log is saved in an Azure storage account.
In the search box at the top of the portal, enter network watcher. Select Network Watcher from the search results.
Under Logs, select Flow logs.
In Network Watcher | Flow logs, select + Create or Create flow log blue button.
On the Basics tab of Create a flow log, enter or select the following values:
Setting |
Value |
Project details |
|
Subscription |
Select the Azure subscription of your virtual network that you want to log. |
Flow log type |
Select Virtual network then select + Select target resource (available options are: Virtual network, Subnet, and Network interface). Select the resources that you want to flow log, then select Confirm selection. |
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. |
Instance details |
|
Subscription |
Select the Azure subscription of the storage account. |
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. |
Retention (days) |
Enter a retention time for the logs (this option is only available with Standard general-purpose v2 storage accounts). Enter 0 if you want to retain the flow logs data in the storage account forever (until you manually delete it from the storage account). For information about pricing, see Azure Storage pricing. |
Note
If the storage account is in a different subscription, the resource that you're logging (virtual network, subnet, or network interface) and the storage account must be associated with the same Microsoft Entra tenant. The account you use for each subscription must have the necessary permissions.
To enable traffic analytics, select Next: Analytics button, or select the Analytics tab. Enter or select the following values:
Setting |
Value |
Enable traffic analytics |
Select the checkbox to enable traffic analytics for your flow log. |
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. |
Subscription |
Select the Azure subscription of your Log Analytics workspace. |
Log Analytics Workspace |
Select your Log Analytics workspace. By default, Azure portal creates DefaultWorkspace-{SubscriptionID}-{Region} Log Analytics workspace in defaultresourcegroup-{Region} resource group. |
Caution
Traffic analytics creates and manages data collection rule and data collection endpoint resources in the same resource group as the workspace, prefixed with NWTA
. If you perform any operation on these resources, traffic analytics might not function as expected.
Select Review + create.
Review the settings, and then select Create.
Use New-AzNetworkWatcherFlowLog cmdlet to create a virtual network flow log.
Enable virtual network flow logs without traffic analytics
# Place the virtual network configuration into a variable.
$vnet = Get-AzVirtualNetwork -Name 'myVNet' -ResourceGroupName 'myResourceGroup'
# Place the storage account configuration into a variable.
$storageAccount = Get-AzStorageAccount -Name 'myStorageAccount' -ResourceGroupName 'myResourceGroup'
# Create a VNet flow log.
New-AzNetworkWatcherFlowLog -Enabled $true -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_eastus' -ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id -FormatVersion 2
Enable virtual network flow logs and traffic analytics
# Place the virtual network configuration into a variable.
$vnet = Get-AzVirtualNetwork -Name 'myVNet' -ResourceGroupName 'myResourceGroup'
# Place the storage account configuration into a variable.
$storageAccount = Get-AzStorageAccount -Name 'myStorageAccount' -ResourceGroupName 'myResourceGroup'
# Create a traffic analytics workspace and place its configuration into a variable.
$workspace = New-AzOperationalInsightsWorkspace -Name 'myWorkspace' -ResourceGroupName 'myResourceGroup' -Location 'EastUS'
# Create a VNet flow log.
New-AzNetworkWatcherFlowLog -Enabled $true -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_eastus' -ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id -FormatVersion 2 -EnableTrafficAnalytics -TrafficAnalyticsWorkspaceId $workspace.ResourceId -TrafficAnalyticsInterval 10
Caution
Traffic analytics creates and manages data collection rule and data collection endpoint resources in the same resource group as the workspace, prefixed with NWTA
. If you perform any operation on these resources, traffic analytics might not function as expected.
Use az network watcher flow-log create command to create a virtual network flow log.
Enable virtual network flow logs without traffic analytics
# Create a VNet flow log.
az network watcher flow-log create --location 'eastus' --resource-group 'myResourceGroup' --name 'myVNetFlowLog' --vnet 'myVNet' --storage-account 'myStorageAccount'
# Create a VNet flow log (storage account is in a different resource group from the virtual network).
az network watcher flow-log create --location 'eastus' --resource-group 'myResourceGroup' --name 'myVNetFlowLog' --vnet 'myVNet' --storage-account '/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/StorageRG/providers/Microsoft.Storage/storageAccounts/myStorageAccount'
Enable virtual network flow logs and traffic analytics
# Create a traffic analytics workspace.
az monitor log-analytics workspace create --name 'myWorkspace' --resource-group 'myResourceGroup' --location 'eastus'
# Create a VNet flow log.
az network watcher flow-log create --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --storage-account 'myStorageAccount' --traffic-analytics true --workspace 'myWorkspace' --interval 10
# Create a traffic analytics workspace.
az monitor log-analytics workspace create --name 'myWorkspace' --resource-group 'myResourceGroup' --location 'eastus'
# Create a VNet flow log (storage account and traffic analytics workspace are in different resource groups from the virtual network).
az network watcher flow-log create --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --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' --interval 10
Caution
Traffic analytics creates and manages data collection rule and data collection endpoint resources in the same resource group as the workspace, prefixed with NWTA
. If you perform any operation on these resources, traffic analytics might not function as expected.
Enable or disable traffic analytics
Enable traffic analytics for a flow log to analyze the flow log data. Traffic analytics provides insights into the traffic patterns of your virtual network. You can enable or disable traffic analytics for a flow log at any time.
Note
In addition to enabling or disabling traffic analytics, you can also change other flow log settings.
To enable traffic analytics for a flow log, follow these steps:
In the search box at the top of the portal, enter network watcher. Select Network Watcher from the search results.
Under Logs, select Flow logs.
In Network Watcher | Flow logs, select the flow log that you want to enable traffic analytics for.
In Flow logs settings, under Traffic analytics, check the Enable traffic analytics checkbox.
Enter or select the following values:
Setting |
Value |
Subscription |
Select the Azure subscription of your Log Analytics workspace. |
Log Analytics workspace |
Select your Log Analytics workspace. By default, Azure portal creates DefaultWorkspace-{SubscriptionID}-{Region} Log Analytics workspace in defaultresourcegroup-{Region} resource group. |
Traffic logging 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. |
Select Save to apply the changes.
To disable traffic analytics for a flow log, take the previous steps 1-3, then uncheck the Enable traffic analytics checkbox and select Save.
To enable traffic analytics on a flow log resource, use Set-AzNetworkWatcherFlowLog cmdlet.
# Place the virtual network configuration into a variable.
$vnet = Get-AzVirtualNetwork -Name 'myVNet' -ResourceGroupName 'myResourceGroup'
# Place the storage account configuration into a variable.
$storageAccount = Get-AzStorageAccount -Name 'myStorageAccount' -ResourceGroupName 'myResourceGroup'
# Place the workspace configuration into a variable.
$workspace = Get-AzOperationalInsightsWorkspace -Name 'myWorkspace' -ResourceGroupName 'myResourceGroup'
# Update the VNet flow log.
Set-AzNetworkWatcherFlowLog -Enabled $true -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_eastus' -ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id -FormatVersion 2 -EnableTrafficAnalytics -TrafficAnalyticsWorkspaceId $workspace.ResourceId -TrafficAnalyticsInterval 10
To disable traffic analytics on the flow log resource and continue to generate and save virtual network flow logs to storage account, use Set-AzNetworkWatcherFlowLog cmdlet.
# Place the virtual network configuration into a variable.
$vnet = Get-AzVirtualNetwork -Name 'myVNet' -ResourceGroupName 'myResourceGroup'
# Place the storage account configuration into a variable.
$storageAccount = Get-AzStorageAccount -Name 'myStorageAccount' -ResourceGroupName 'myResourceGroup'
# Update the VNet flow log.
Set-AzNetworkWatcherFlowLog -Enabled $true -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_eastus' -ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id -FormatVersion 2
To enable traffic analytics on a flow log resource, use az network watcher flow-log update command.
# Update the VNet flow log.
az network watcher flow-log update --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --storage-account 'myStorageAccount' --traffic-analytics true --workspace 'myWorkspace' --interval 10
To disable traffic analytics on the flow log resource and continue to generate and save virtual network flow logs to a storage account, use az network watcher flow-log update command.
# Update the VNet flow log.
az network watcher flow-log update --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --storage-account 'myStorageAccount' --traffic-analytics false
Caution
Traffic analytics creates and manages data collection rule and data collection endpoint resources in the same resource group as the workspace, prefixed with NWTA
. If you perform any operation on these resources, traffic analytics might not function as expected.
List all flow logs
You can list all flow logs in a subscription or a group of subscriptions (Azure portal). You can also list all flow logs in a region.
In the search box at the top of the portal, enter network watcher. Select Network Watcher from the search results.
Under Logs, select Flow logs.
Select Subscription equals filter to choose one or more of your subscriptions. You can apply other filters like Location equals to list all the flow logs in a region.
Use Get-AzNetworkWatcherFlowLog cmdlet to list all flow log resources in a particular region in your subscription.
# Get all flow logs in East US region.
Get-AzNetworkWatcherFlowLog -Location 'eastus' | format-table
Use az network watcher flow-log list command to list all flow log resources in a particular region in your subscription.
# Get all flow logs in East US region.
az network watcher flow-log list --location 'eastus' --out table
View details of a flow log resource
You can view the details of a flow log.
In the search box at the top of the portal, enter network watcher. Select Network Watcher from the search results.
Under Logs, select Flow logs.
In Network Watcher | Flow logs, select the flow log that you want to see.
In Flow logs settings, you can view the settings of the flow log resource.
Select Cancel to close the settings page without making changes.
Use Get-AzNetworkWatcherFlowLog cmdlet to see details of a flow log resource.
# Get the flow log details.
Get-AzNetworkWatcherFlowLog -NetworkWatcherName 'NetworkWatcher_eastus' -ResourceGroupName 'NetworkWatcherRG' -Name 'myVNetFlowLog'
Use az network watcher flow-log show to see details of a flow log resource.
# Get the flow log details.
az network watcher flow-log show --name 'myVNetFlowLog' --resource-group 'NetworkWatcherRG' --location 'eastus'
Download a flow log
You can download the flow logs data from the storage account that you saved the flow log to.
In the search box at the top of the portal, enter storage accounts. Select Storage accounts from the search results.
Select the storage account you used to store the logs.
Under Data storage, select Containers.
Select the insights-logs-flowlogflowevent container.
In insights-logs-flowlogflowevent, navigate the folder hierarchy until you get to the PT1H.json
file that you want to download. Virtual network flow log files follow the following path:
https://{storageAccountName}.blob.core.windows.net/insights-logs-flowlogflowevent/flowLogResourceID=/{subscriptionID}_NETWORKWATCHERRG/NETWORKWATCHER_{Region}_{ResourceName}-{ResourceGroupName}-FLOWLOGS/y={year}/m={month}/d={day}/h={hour}/m=00/macAddress={macAddress}/PT1H.json
Select the ellipsis ... to the right of the PT1H.json
file, then select Download.
To download virtual network flow logs from your storage account, use Get-AzStorageBlobContent cmdlet. For more information, see Download a blob.
Virtual network flow log files are saved to the storage account at the following path:
https://{storageAccountName}.blob.core.windows.net/insights-logs-flowlogflowevent/flowLogResourceID=/SUBSCRIPTIONS/{subscriptionID}/RESOURCEGROUPS/NETWORKWATCHERRG/PROVIDERS/MICROSOFT.NETWORK/NETWORKWATCHERS/NETWORKWATCHER_{Region}/FLOWLOGS/{FlowlogResourceName}/y={year}/m={month}/d={day}/h={hour}/m=00/macAddress={macAddress}/PT1H.json
To download virtual network flow logs from your storage account, use the az storage blob download command. For more information, see Download a blob.
Virtual network flow log files are saved to the storage account at the following path:
https://{storageAccountName}.blob.core.windows.net/insights-logs-flowlogflowevent/flowLogResourceID=/SUBSCRIPTIONS/{subscriptionID}/RESOURCEGROUPS/NETWORKWATCHERRG/PROVIDERS/MICROSOFT.NETWORK/NETWORKWATCHERS/NETWORKWATCHER_{Region}/FLOWLOGS/{FlowlogResourceName}/y={year}/m={month}/d={day}/h={hour}/m=00/macAddress={macAddress}/PT1H.json
For information about the structure of a flow log, see Log format of virtual network flow logs.
Disable a flow log
You can temporarily disable a virtual network flow log without deleting it. Disabling a flow log stops flow logging for the associated virtual network. However, the flow log resource remains with all its settings and associations. You can re-enable it at any time to resume flow logging for the configured virtual network.
In the search box at the top of the portal, enter network watcher. Select Network Watcher from the search results.
Under Logs, select Flow logs.
In Network Watcher | Flow logs, select the checkbox of the flow log that you want to disable.
Select Disable.
Note
If traffic analytics is enabled for a flow log, you must disable it before you can disable the flow log. To disable traffic analytics, see Enable or disable traffic analytics.
Use Set-AzNetworkWatcherFlowLog cmdlet to disable a flow log.
# Place the virtual network configuration into a variable.
$vnet = Get-AzVirtualNetwork -Name 'myVNet' -ResourceGroupName 'myResourceGroup'
# Place the storage account configuration into a variable.
$storageAccount = Get-AzStorageAccount -Name 'myStorageAccount' -ResourceGroupName 'myResourceGroup'
# Disable the VNet flow log.
Set-AzNetworkWatcherFlowLog -Enabled $false -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_eastus' -ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id
Note
If you disable a flow log with traffic analytics enabled, you must either disable traffic analytics in the same command or disable it first before disabling the flow log.
Use az network watcher flow-log update command to disable a flow log.
# Update the VNet flow log.
az network watcher flow-log update --enabled false --location 'eastus' --name 'myVNetFlowLog' --resource-group 'myResourceGroup' --vnet 'myVNet' --storage-account 'myStorageAccount'
Note
If you disable a flow log with traffic analytics enabled, you must either disable traffic analytics in the same command or disable it first before disabling the flow log.
Delete a flow log
You can permanently delete a virtual network flow log. Deleting a flow log deletes all its settings and associations. To begin flow logging again for the same resource, you must create a new flow log for it.
In the search box at the top of the portal, enter network watcher. Select Network Watcher from the search results.
Under Logs, select Flow logs.
In Network Watcher | Flow logs, select the checkbox of the flow log that you want to delete.
Select Delete.
To delete a virtual network flow log resource, use Remove-AzNetworkWatcherFlowLog cmdlet.
# Delete the VNet flow log.
Remove-AzNetworkWatcherFlowLog -Name 'myVNetFlowLog' -Location 'eastus'
To delete a virtual network flow log resource, use az network watcher flow-log delete command.
# Delete the VNet flow log.
az network watcher flow-log delete --name 'myVNetFlowLog' --location 'eastus'
Note
Deleting a flow log doesn't delete the flow log data from the storage account. Flow logs data stored in the storage account follows the configured retention policy or stays stored in the storage account until manually deleted.
Related content