虚拟网络安全组流日志记录是 Azure 网络观察程序的一项功能,可用于记录有关流经 Azure 虚拟网络的 IP 流量的信息。 有关虚拟网络流日志记录的详细信息,请参阅虚拟网络流日志概述。
本文介绍虚拟网络流日志筛选功能。 筛选功能为用户提供了用于记录虚拟网络(VNet 内流量)或两个或多个虚拟网络(VNet 间流量)中的流量的选项。 它还可帮助用户识别基于 CIDR 范围的流量、入站出站流量、Internet 流量以及允许/拒绝流量。
重要
虚拟网络流日志筛选目前以预览版提供。 有关适用于 Beta 版、预览版或尚未正式发布的 Azure 功能的法律条款,请参阅 Azure 预览版补充使用条款 。
支持的字段
| 领域 | 根据过滤条件 | Example |
|---|---|---|
| 方向 | 流量方向 | 入站、出站 |
| SrcIP | 源 IP 地址/CIDR 范围 | 192.168.1.1, 2001:db8::1/64 |
| SrcPort | 源端口范围和值 | 1024-65535, 80, 443 |
| DstIP | 目标 IP 地址/CIDR 范围 | 192.168.2.1, 2001:db8::2/64 |
| DstPort | 目标端口范围和值 | 22, 8080-8090 |
| 协议 | 协议类型 | TCP、UDP |
| Encryption | 加密状态 | 所有支持的加密值和 NX_ALL (出于任何原因未加密) |
所有字段都可以采用逗号分隔值作为输入。 所有内容都不区分大小写。
支持的操作
虚拟网络流日志支持每个字段中的 = 和 != 。
支持的操作数
虚拟网络流日志支持在任何两个字段之间使用逻辑操作符&&和||。
支持的格式
- 字段可以以任意组合方式提供。
- 目前不支持括号。
- 字段按照从左到右的逻辑运算符优先级进行评估(AND 优先于 OR)。
- 筛选字符串的最大长度可以为 1000 个字符。
启用筛选
若要创建包含筛选的虚拟网络流日志,请使用 New-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'
# Create a traffic analytics workspace and place its configuration into a variable.
$workspace = New-AzOperationalInsightsWorkspace -Name 'myWorkspace' -ResourceGroupName 'myResourceGroup' -Location 'ChinaEast'
# Create a VNet flow log with the following filtering criteria: dstip=20.252.145.59 || DstPort=443
New-AzNetworkWatcherFlowLog -Enabled $true -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_chinaeast' `
-ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id `
-FormatVersion 2 -EnabledFilteringCriteria 'dstip=20.252.145.59 || DstPort=54300-54400' `
-EnableTrafficAnalytics -TrafficAnalyticsWorkspaceId $workspace.ResourceId `
-EnableRetention $true -RetentionPolicyDays 15
更新现有筛选
可以使用具有更新条件的 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_chinaeast' `
-ResourceGroupName 'NetworkWatcherRG' -StorageId $storageAccount.Id -TargetResourceId $vnet.Id `
-FormatVersion 2 -EnabledFilteringCriteria 'dstip=20.252.145.59 || DstPort=443' `
-EnableTrafficAnalytics -TrafficAnalyticsWorkspaceId $workspace.ResourceId `
-EnableRetention $true -RetentionPolicyDays 15
更新 RecordTypes 筛选条件
可以通过选择要收集的流记录格式来在流日志创建期间启用 RecordTypes 筛选,以便定制日志记录输出,而无需生成不必要的数据。
# Enable RecordTypes filtering while creating flowlog
New-AzNetworkWatcherFlowLog `
-Enabled $true -Name <FlowLog Name> `
-NetworkWatcherName <Network Watcher Name> `
-ResourceGroupName NetworkWatcherRG `
-StorageId <Storage Account ID> `
-TargetResourceId <Target Resource/VNet ID> `
-RecordTypes "<Record Types>"
# Update RecordTypes filtering condition on existing flow log
Set-AzNetworkWatcherFlowLog `
-Enabled $true -Name <FlowLog Name> `
-NetworkWatcherName <Network Watcher Name> `
-ResourceGroupName <Resource Group Name> `
-StorageId <Storage Account ID> `
-TargetResourceId <Target Resource/VNet ID> `
-RecordTypes "<Record Types>"
# Remove RecordTypes filtering condition from existing flow log
Set-AzNetworkWatcherFlowLog `
-Enabled $true -Name <FlowLog Name> `
-NetworkWatcherName <Network Watcher Name> `
-ResourceGroupName <Resource Group Name> `
-StorageId <Storage Account ID> `
-TargetResourceId <Target Resource/VNet ID> `
-RecordTypes ""
# Enable RecordTypes and EnabledFilteringCriteria filtering while creating flow log
New-AzNetworkWatcherFlowLog `
-Enabled $true -Name <FlowLog Name> `
-NetworkWatcherName <Network Watcher Name> `
-ResourceGroupName <Resource Group Name> `
-StorageId <Storage Account ID> `
-TargetResourceId <Target Resource/VNet ID> `
-EnabledFilteringCriteria "<Filtering Criteria Expression>" `
-RecordTypes "<Record Types>"