你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Manage packet captures with Azure Network Watcher

In this article, you learn how to use the Azure Network Watcher packet capture feature to remotely configure, start, stop, download, and delete virtual machine packet captures.

Prerequisites

  • An Azure account with an active subscription. Create an account for free.

  • A virtual machine (VM) or virtual machine scale set with outbound TCP connectivity to: 169.254.169.254 over port 80 and 168.63.129.16 over port 8037. The Network Watcher agent VM extension uses these IP addresses to communicate with the Azure platform.

  • Network Watcher Agent VM extension installed on the target virtual machine. Whenever you use Network Watcher packet capture in the Azure portal, the agent is automatically installed on the target VM or scale set if it wasn't previously installed. To update an already installed agent, see Update Azure Network Watcher extension to the latest version.

  • An Azure storage account with VM outbound TCP connectivity to it over port 443. If you don't have a storage account, see Create a storage account using the Azure portal. The storage account must be accessible from the subnet of the target virtual machine or scale set. For more information, see Configure Azure Storage firewalls and virtual networks.

  • Sign in to the Azure portal with your Azure account.

Note

Azure creates a Network Watcher instance in the virtual machine's region if Network Watcher wasn't enabled for that region. For more information, see Enable or disable Azure Network Watcher.

If a network security group is associated to the network interface, or subnet that the network interface is in, ensure that rules exist to allow outbound connectivity over the previous ports. Similarly, ensure outbound connectivity over the previous ports when adding user-defined routes to your network.

Start a packet capture

To start a capture session, use the following steps:

  1. In the search box at the top of the portal, enter Network Watcher. Select Network Watcher from the search results.

    Screenshot shows how to search for Network Watcher in the Azure portal.

  2. Select Packet capture under Network diagnostic tools, then select + Add to create a packet capture.

    Screenshot that shows Network Watcher packet capture in the Azure portal.

  3. In Add packet capture, enter or select values for the following settings:

    Setting Value
    Basic Details
    Subscription Select the Azure subscription of the virtual machine.
    Resource group Select the resource group of the virtual machine.
    Target type Select Virtual machine or Virtual machine scale set.
    Target virtual machine scale set Select the virtual machine scale set.
    This option is available if you select Virtual machine scale set as the target type.
    Target instance Select the virtual machine or scale set instance.
    Packet capture name Enter a name or leave the default name.
    Packet capture configuration
    Capture location Select Storage account (default option), File, or Both.
    Storage account Select your Standard storage account1.
    This option is available if you select Storage account or Both as a capture location.
    The storage account must be in the same region as the target instance.
    Local file path Enter a valid local file path where you want the capture to be saved in the target virtual machine.
    If you're using a Linux machine, the path can start with /var/captures.
    If you're using a Windows machine, the path can start with C:\Captures.
    This option is available if you select File or Both as a capture location.
    Maximum bytes per packet Enter the maximum number of bytes to be captured per each packet. All bytes are captured if left blank or 0 entered.
    Maximum bytes per session Enter the total number of bytes that are captured. Once the value is reached the packet capture stops. Up to 1 GB is captured if left blank.
    Time limit (seconds) Enter the time limit of the packet capture session in seconds. Once the value is reached the packet capture stops. Up to 5 hours (18,000 seconds) is captured if left blank.
    Filtering (optional)
    Add filter criteria Select Add filter criteria to add a new filter. You can define as many filters as you need.
    Protocol Filters the packet capture based on the selected protocol. Available values are TCP, UDP, or Any.
    Local IP address2 Filters the packet capture for packets where the local IP address matches this value.
    Local port2 Filters the packet capture for packets where the local port matches this value.
    Remote IP address2 Filters the packet capture for packets where the remote IP address matches this value.
    Remote port2 Filters the packet capture for packets where the remote port matches this value.

    1 Premium storage accounts are currently not supported for storing packet captures.

    2 Port and IP address values can be a single value, a range such as 80-1024, or multiple values such as 80, 443.

  4. Select Start packet capture.

    Screenshot of Add packet capture in the Azure portal showing available options.

  5. The packet capture stops once the time limit or the file size (maximum bytes per session) is reached.

Stop a packet capture

To manually stop a packet capture session before it reaches its time or file size limits, select the ellipsis ... on the right-side of the packet capture, or right-click it, then select Stop.

Screenshot that shows how to stop a packet capture in the Azure portal.

View packet capture status

Go to the Packet capture page of Network Watcher to list existing packet captures regardless of their status.

Screenshot that shows how to list and see packet captures in the Azure portal.

Download a packet capture

After concluding your packet capture session, the resulting capture file is saved to Azure storage, a local file on the target virtual machine or both. The storage destination for the packet capture is specified during its creation. For more information, see Start a packet capture section.

To download a packet capture file saved to Azure storage, follow these steps:

  1. In the Packet capture page, select the packet capture that you want to download its file.

  2. In the Details section, select the packet capture file link.

    Screenshot that shows how to select the packet capture file in the Azure portal.

  3. In the blob page, select Download.

Note

You can also download capture files from the storage account container using the Azure portal or Storage Explorer1 at the following path:

https://{storageAccountName}.blob.core.windows.net/network-watcher-logs/subscriptions/{subscriptionId}/resourcegroups/{storageAccountResourceGroup}/providers/microsoft.compute/virtualmachines/{virtualMachineName}/{year}/{month}/{day}/packetcapture_{UTCcreationTime}.cap

1 Storage Explorer is a standalone app that you can conveniently use to access and work with Azure Storage data. For more information, see Get started with Storage Explorer.

To download a packet capture file saved to the virtual machine (VM), connect to the VM and download the file from the local path specified during the packet capture creation.

Delete a packet capture

  1. In the Packet capture page, select ... on the right-side of the packet capture that you want to delete, or right-click it, then select Delete.

    Screenshot that shows how to delete a packet capture from Network Watcher in Azure portal.

  2. Select Yes.

Important

Deleting the packet capture resource in Network Watcher doesn't delete the capture file from the storage account or the virtual machine. If you don't need the capture file anymore, you must manually delete it from the storage account or virtual machine.