Virtual private clouds (VPCs) provide flow logs to record inbound and outbound traffic of an elastic network interface (ENI). Use this feature to monitor network performance, troubleshoot network errors, reduce traffic costs, and conduct security analysis.
Overview

You can create flow logs for specific ENIs, VPCs, or vSwitches. Flow logs for a VPC or vSwitch capture all the traffic of ENIs, including ENIs added after flow logs have been enabled.
Traffic information captured by flow logs is stored in Simple Log Service as flow log entries. Each log records the 5-tuples of the traffic flow within a specific window, called a capture window. The traffic information of a flow is captured and aggregated into a flow log entry.
Based on your scenario, you can opt to collect traffic for specific paths to reduce flow log costs. The available options include:
All Scenarios
Traffic Through IPv4 Gateway
Traffic Through NAT Gateway
Traffic Through VPN Gateway
Traffic Through Transit Router
Traffic That Accesses Cloud Service Through Gateway Endpoint
Traffic That Accesses Express Connect Circuit Through VBR
Traffic Through an Express Connect Router (ECR)
Traffic Through a Gateway Load Balancer Endpoint
Scenarios
Network monitoring | Cost reduction | Security analysis |
By querying flow logs, you can: monitor VPC throughput and performance monitor traffic information and trends troubleshoot network issues check access control rules
| By analyzing network transmission through flow logs, you can get the following information to reduce traffic costs: traffic from the VPC to other regions traffic from the VPC to specific public IP addresses traffic from the VPC to local IDC and other cloud networks ECS instances with traffic surges
| When an unexpected event occurs, you can get the following information by querying VPC flow logs: |
Billing

Flow log generation is billed on a tiered pricing basis by the volume of logs generated monthly in each region. Every Alibaba Cloud account receives a free quota of 5 GB per month for each region. Log charges follow the billing policy of the Simple Log Service. For more information, see Billing of flow logs.
Manage flow logs
Log on to the VPC console.
In the left-side navigation pane, select . From the top menu bar, set the region where you want to create a flow log.
Proceed with the following operations based on your requirements:
Create or delete flow logs
Create flow logs
Note Ensure the following prerequisites have been met before creating a flow log:
If you have not used this feature before, click Authorize Now and Confirm Authorization Policy. Authorization is required to import the flow log into Simple Log Service.
Simple Log Service has been activated on the Simple Log Service product page.
Resources for log collection have been created, such as ENIs, VPCs, and vSwitches.
On the Flow Log page, click Create a flow log. In the Create a flow log dialog box, configure the following parameters:
Resource Type: Choose the resource type for which you want to collect traffic. Valid values: VPC, vSwitch, and ENI.
Note When the resource type is VPC or vSwitch, you can go to the Flow Log page, and view the collected data by clicking View ENI Collection Scope in the Actions column.
Resource Instance: Choose the resource instance for which you want to collect traffic.
Data Transfer Type: Choose the type of traffic that you want to collect. Valid values: All Traffic, Allowed Traffic, and Denied Traffic.
IP Version: Currently, only IPv4 is supported.
Project: You can choose either Create Project or Select Project to store the collected traffic.
Note If a Project or Logstore is deleted after creating a flow log, this may cause a failure in log delivery. The flow log will automatically stop in the backend but will continue to show as Delivery Succeeded. To restore data delivery, recreate a Project or Logstore with the same name and restart the flow log.
Logstore: You can choose either Create Logstore or Select Logstore to store the collected traffic.
Enable Log Analysis Report: Enables indexing and creates a dashboard for a logstore. This lets you perform SQL statements and visualize data analysis.
Indexing in Log Service is billed by data usage, while dashboards are provided at no additional cost. For more information, see Billable items.
Sampling Interval (Minutes): Specify the sampling interval. Available intervals are 1, 5, and 10 minutes, with the default set to 10 minutes. A shorter sampling interval results in more frequent and timely flow log generation, but also increases the number of log entries and overall cost of flow logs.
Note After a flow log is created, go to the Flow Log page and select Edit under the Sampling Interval (Minutes) column to modify the sampling interval.
When multiple flow logw in a VPC are collecting traffic of the same ENI, the sampling interval will be set to the shortest sampling interval among all flow log instances.
Sampling Path: Select the sampling path for the flow log. Available paths include All Scenarios, Traffic Through IPv4 Gateway, Traffic Through NAT Gateway, Traffic Through VPN Gateway, Traffic Through Transit Router, Traffic That Accesses Cloud Service Through Gateway Endpoint, and Traffic That Accesses Express Connect Circuit Through VBR. All Scenarios is selected by default.
Note By default, sampling paths do not record traffic categorized as Denied Traffic. To record the rejected traffic, when creating a flow log, select Traffic Type as Denied Traffic and choose Sampling Path as All Scenarios.
Delete flow logs
Flow logs in the Started or Not Started states can be deleted. The collected traffic remains accessible on the console even after a flow log is deleted.
Analyze flow logs
By analyzing flow logs, you can check access control rules, monitor network traffic, and troubleshoot network issues.
Use Logstore
On the Flow Log page, click the Logstore link in the Simple Log Service column.
Use Simple Log Service features in the console to query and analyze flow logs.
Use Flow Log Center
Log on to the Log Service Console.
In the Log Application section, click View More Log Applications. In the Log Application dialog box, click Flow Log Center.
On the Flow Log Management page, click Add. In the Create Instance panel, select the project and Logstore you configured when creating the flow log.
After the instance is created, click the instance ID in the Flow Log Center. On the Flow Log Details page, you can view and analyze the data.

You can find various dashboards and customize queries in the Monitoring Center.
Overview: Displays the status of flow logs.
Policy Statistics: Shows trends for accepted and rejected traffic and 5-tuple details of accepts and rejects, which include the source CIDR block, source port, protocol type, destination CIDR block, and destination port.
ENI Traffic: Displays inbound and outbound traffic details for ENIs.
Inter-ECS Traffic: Illustrates the traffic flow between ECS instances.
Custom Query: Lets you query and analyze flow logs.
On the Flow Log Details page, click CIDR Block Settings and enable the Inter-Domain Analysis.
When you enable the inter-domain analysis feature, the system automatically creates data transformation tasks, and generates VPC flow logs with CIDR blocks for you to analyze the traffic between CIDR blocks. Note that the data transformation feature incurs additional charges.
With the following CIDR blocks predefined by Simple Log Service, you can enable the inter-domain analysis feature when necessary. If the predefined CIDR blocks do not meet your needs, add custom ones.

Inter-Domain Analysis provides the following dashboards and custom query capabilities:
Inter-domain Traffic: Shows traffic patterns between different CIDR blocks.
ECS-to-Domain Traffic: Displays traffic from ECS instances to various destination CIDR blocks.
Threat Intelligence: Provides threat intelligence information for source and destination IP addresses.
Custom Query: Lets you query and analyze VPC flow logs.
Start or stop flow logs
Start flow logs
You can start flow logs that are currently in the Not Started state to start gathering traffic data from ENIs.
Stop flow logs
To stop collecting the traffic information from an ENI, you can turn off a flow log. This does not delete the flow log. To resume traffic data collection, restart the flow log that is in the Not Started state. Upon stopping a flow log, log generation fees will cease.
FAQs
How long can VPC flow logs be retained?
VPC flow logs are automatically delivered to the Simple Log Service and are subject to its retention policy.
If you select Enable Log Analysis Report, the data retention period will automatically be set to 7 days.
Otherwise, when creating VPC flow logs, the default data retention period for the newly created Logstore is 300 days. Check the data retention period for existing Logstores in the Simple Log Service Console.
Adjust the data retention period based on your needs.
Where can I query network logs for Classified Protection of Information Security?
VPCs do not have logging enabled by default. To record logs, you must turn on the VPC flow log, which records inbound and outbound traffic information for ENIs and helps you monitor the network.
If I only want to collect logs of a few ECS instances in a VPC, how do I create flow logs?
When creating a flow log, select Resource Type as ENI and create a separate flow log for each ENI associated with your ECS instances.
Additional actions
After flow logs are created, you can set up alerts to monitor them. These log-based alerts are instrumental in promptly detecting unusual traffic, enhancing the security and stability of your network. For more information, see Configure an alert rule.
Flow logs can be managed through API calls using Alibaba Cloud SDKs (recommended), Terraform, and ROS among others. For more information about API operations, see: