Azure CLI를 사용하여 NSG 흐름 로그 관리

네트워크 보안 그룹 흐름 로깅은 네트워크 보안 그룹을 통과하는 IP 트래픽에 대한 정보를 로그할 수 있는 Azure Network Watcher의 기능입니다. 네트워크 보안 그룹 흐름 로깅에 대한 자세한 내용은 NSG 흐름 로그 개요를 참조하세요.

이 문서에서는 Azure CLI를 사용하여 NSG 흐름 로그를 생성, 변경, 비활성화 또는 삭제하는 방법을 알아봅니다. Azure Portal, PowerShell, REST API 또는 ARM 템플릿을 사용하여 NSG 흐름 로그를 관리하는 방법을 알아볼 수 있습니다.

필수 조건

Insights 공급자 등록

네트워크 보안 그룹을 통해 흐르는 트래픽을 성공적으로 기록하려면 Microsoft.Insights 공급자를 등록해야 합니다. Microsoft.Insights 공급자가 등록되었는지 확실하지 않은 경우 az provider register를 사용하여 등록합니다.

# Register Microsoft.Insights provider.
az provider register --namespace 'Microsoft.Insights'

흐름 로그 만들기

az network watcher flow-log create를 사용하여 흐름 로그를 만듭니다. 흐름 로그는 Network Watcher 기본 리소스 그룹 NetworkWatcherRG에 만들어집니다.

# Create a version 1 NSG flow log.
az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account 'myStorageAccount'

참고 항목

  • 스토리지 계정이 다른 구독에 있는 경우 네트워크 보안 그룹 및 스토리지 계정은 동일한 Azure Active Directory 테넌트와 연결되어야 합니다. 각 구독에 대해 사용하는 계정에 필요한 권한이 있어야 합니다.
  • 스토리지 계정이 다른 리소스 그룹 또는 구독에 있는 경우 해당 이름 대신 스토리지 계정의 전체 ID를 지정해야 합니다. 예를 들어 myStorageAccount 스토리지 계정이 StorageRG라는 리소스 그룹에 있고 네트워크 보안 그룹이 myResourceGroup 리소스 그룹에 있는 경우 myStorageAccount 대신 --storage-account 매개 변수에 /subscriptions/{SubscriptionID}/resourceGroups/RG-Storage/providers/Microsoft.Storage/storageAccounts/myStorageAccount를 사용해야 합니다.
# Place the storage account resource ID into a variable.
sa=$(az storage account show --name 'myStorageAccount' --query 'id' --output 'tsv')

# Create a version 1 NSG flow log (the storage account is in a different resource group).
az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account $sa

흐름 로그 및 트래픽 분석 작업 영역 만들기

  1. az monitor log-analytics workspace create를 사용하여 Log Analytics 작업 영역을 만듭니다.

    # Create a Log Analytics workspace.
    az monitor log-analytics workspace create --name 'myWorkspace' --resource-group 'myResourceGroup'
    
  2. az network watcher flow-log create를 사용하여 흐름 로그를 만듭니다. 흐름 로그는 Network Watcher 기본 리소스 그룹 NetworkWatcherRG에 만들어집니다.

    # Create a version 1 NSG flow log and enable traffic analytics for it.
    az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account 'myStorageAccount' --traffic-analytics 'true' --workspace 'myWorkspace'
    

참고 항목

  • 스토리지 계정에는 Microsoft 서비스 또는 특정 가상 네트워크에 대한 네트워크 액세스를 제한하는 네트워크 규칙이 있을 수 없습니다.
  • 스토리지 계정이 다른 구독에 있는 경우 네트워크 보안 그룹 및 스토리지 계정은 동일한 Azure Active Directory 테넌트와 연결되어야 합니다. 각 구독에 대해 사용하는 계정에 필요한 권한이 있어야 합니다.
  • 스토리지 계정이 다른 리소스 그룹 또는 구독에 있는 경우 스토리지 계정의 전체 ID를 사용해야 합니다. 예를 들어 myStorageAccount 스토리지 계정이 StorageRG라는 리소스 그룹에 있고 네트워크 보안 그룹이 myResourceGroup 리소스 그룹에 있는 경우 myStorageAccount 대신 --storage-account 매개 변수에 /subscriptions/{SubscriptionID}/resourceGroups/RG-Storage/providers/Microsoft.Storage/storageAccounts/myStorageAccount를 사용해야 합니다.
# Place the storage account resource ID into a variable.
sa=$(az storage account show --name 'myStorageAccount' --query 'id' --output 'tsv')

# Create a Log Analytics workspace.
az monitor log-analytics workspace create --name 'myWorkspace' --resource-group 'myResourceGroup'

# Create a version 1 NSG flow log and enable traffic analytics for it (the storage account is in a different resource group).
az network watcher flow-log create --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account $sa --traffic-analytics 'true' --workspace 'myWorkspace'

흐름 로그 변경

az network watcher flow-log update를 사용하여 흐름 로그의 속성을 변경할 수 있습니다. 예를 들어 흐름 로그 버전을 변경하거나 트래픽 분석을 사용하지 않도록 설정할 수 있습니다.

# Update the flow log.
az network watcher flow-log update --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account 'myStorageAccount' --traffic-analytics 'false' --log-version '2'

지역의 모든 흐름 로그 나열

az network watcher flow-log list를 사용하여 구독의 특정 지역에 있는 모든 NSG 흐름 로그 리소스를 나열합니다.

# Get all NSG flow logs in East US region.
az network watcher flow-log list --location 'eastus' --out table

흐름 로그 리소스의 세부 정보 보기

az network watcher flow-log show를 사용하여 흐름 로그 리소스의 세부 정보를 확인합니다.

# Get the details of a flow log.
az network watcher flow-log show --name 'myFlowLog' --resource-group 'NetworkWatcherRG' --location 'eastus'

흐름 로그 다운로드

흐름 로그의 스토리지 위치를 만들 때 정의합니다. 스토리지 계정에서 흐름 로그에 액세스하고 다운로드하려면 Azure Storage Explorer를 사용할 수 있습니다. 자세한 내용은 Storage Explorer 시작을 참조하세요.

스토리지 계정에 저장된 NSG 흐름 로그 파일은 다음 경로를 따릅니다.

https://{storageAccountName}.blob.core.windows.net/insights-logs-networksecuritygroupflowevent/resourceId=/SUBSCRIPTIONS/{subscriptionID}/RESOURCEGROUPS/{resourceGroupName}/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/{NetworkSecurityGroupName}/y={year}/m={month}/d={day}/h={hour}/m=00/macAddress={macAddress}/PT1H.json

흐름 로그의 구조에 대한 자세한 내용은 NSG 흐름 로그의 로그 형식을 참조하세요.

흐름 로그 사용 안 함

흐름 로그를 삭제하지 않고 일시적으로 사용하지 않도록 설정하려면 az network watcher flow-log update 명령을 사용합니다. 흐름 로그를 사용하지 않도록 설정하면 연결된 네트워크 보안 그룹에 대한 흐름 로깅이 중지됩니다. 그러나 흐름 로그 리소스는 모든 설정 및 연결과 함께 유지됩니다. 언제든지 다시 사용하도록 설정하여 구성된 네트워크 보안 그룹에 대한 흐름 로깅을 다시 시작할 수 있습니다.

참고 항목

흐름 로그에 대해 트래픽 분석을 사용하도록 설정한 경우 흐름 로그를 사용하지 않도록 설정하려면 먼저 트래빅 분석을 사용하지 않도록 설정해야 합니다.

# Disable traffic analytics log if it's enabled.
az network watcher flow-log update --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account 'myStorageAccount' --traffic-analytics 'false' --workspace 'myWorkspace'

# Disable the flow log.
az network watcher flow-log update --name 'myFlowLog' --nsg 'myNSG' --resource-group 'myResourceGroup' --storage-account 'myStorageAccount' --enabled 'false'

흐름 로그 삭제

흐름 로그를 영구적으로 삭제하려면 az network watcher flow-log delete 명령을 사용합니다. 흐름 로그를 삭제하면 모든 설정 및 연결이 삭제됩니다. 동일한 네트워크 보안 그룹에 대해 흐름 로깅을 다시 시작하려면 해당 그룹에 대한 새 흐름 로그를 만들어야 합니다.

# Delete the flow log.
az network watcher flow-log delete --name 'myFlowLog' --location 'eastus' --no-wait 'true'

참고 항목

흐름 로그를 삭제해도 스토리지 계정에서 흐름 로그 데이터가 삭제되지는 않습니다. 스토리지 계정에 저장된 흐름 로그 데이터는 구성된 보존 정책을 따릅니다.

다음 단계