虛擬網路流量記錄是 Azure 網路監看員的一項功能,可讓您記錄流經 Azure 虛擬網路的 IP 流量資訊。 如需虛擬網路流量記錄的詳細資訊,請參閱虛擬網路流量記錄概觀。
在本文中,您將了解虛擬網路流量日誌過濾的功能。 過濾功能讓使用者可以選擇在虛擬網路內(VNet 內部流量)或與兩個或以上虛擬網路(VNet 間流量)內記錄流量。 它也協助使用者辨識基於 CIDR 範圍的流量、入站出站流量、網際網路流量,以及允許/拒絕流量。
這很重要
虛擬網路流量日誌的過濾目前處於預覽階段。 請參閱 Microsoft Azure 預覽版增補使用規定,以了解適用於 Azure 功能 (搶鮮版 (Beta)、預覽版,或尚未正式發行的版本) 的法律條款。
支援的欄位
| 領域 | 依據篩選條件 | 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 指令檔。
# 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 with the following filtering criteria: dstip=20.252.145.59 || DstPort=443
New-AzNetworkWatcherFlowLog -Enabled $true -Name 'myVNetFlowLog' -NetworkWatcherName 'NetworkWatcher_eastus' `
-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 指令檔修改虛擬網路流量日誌的現有過濾條件,且條件已更新,無需重新建立流量日誌。
# 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 -EnabledFilteringCriteria 'dstip=20.252.145.59 || DstPort=443' `
-EnableTrafficAnalytics -TrafficAnalyticsWorkspaceId $workspace.ResourceId `
-EnableRetention $true -RetentionPolicyDays 15
基於 RecordTypes 的篩選
你可以根據網路流的狀態來篩選虛擬網路流量日誌。 流狀態代表網路監控者觀察到的連線生命週期階段,例如流開始、持續、結束或被拒絕。
使用 RecordTypes 參數來指定你想記錄哪些流程狀態。 參數接受一個或多個逗號分隔值。
支援的 RecordType 值
| 價值 | 說明 |
|---|---|
| B | 開始:當一個流程被創建時。 未提供任何統計資料。 |
| C | 持續:持續的流動。 統計資料是以五分鐘的間隔提供。 |
| E | 結束:當一個流程被終止時。 提供統計資料。 |
| D | 拒絕:當流程遭拒絕時。 |
使用 RecordTypes 的範例情境
| Scenario | RecordTypes 的值 |
|---|---|
| 只擷取遭拒絕的流量 | “D” |
| 擷取流程建立與終止事件 | 「B,E」 |
| 僅擷取活躍流量統計 | "C" |
| 擷取完整流程生命週期 | 「B,C,E」 |
管理 RecordTypes 篩選條件
你可以在建立流程日誌時啟用 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>"
# 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>"
# 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 ""