- Documentation
Elastic Compute Service
Elastic Compute Service
User Guide
Network
Security group
Security group overview
Security group
Security group overview
Security group overview
Description
Security groups are designed based on the allowlist principle to control the outbound and inbound traffic for network interfaces of ECS instances. You can add security group rules to allow the required traffic for network interfaces based on your business requirements.
For example, if an ECS instance provides services externally over port 80, its associated security group must include an inbound rule allowing traffic over port 80. This ensures that external traffic can access the services provided by that ECS instance as expected.
tip
- For the security of ECS instances, we recommend that you follow the principle of least privilege and cautiously and precisely allow IP addresses and ports for security groups associated with ECS instances.
- For ease of use, the system adds some rules to security groups by default to allow traffic. For details, refer to security group classification.
Category
Security groups are classified based on creation method, as shown in the following table:
Security group rules
- Security groups are stateful. Therefore, response traffic is automatically allowed (TCP connections time out after 900 seconds, and ICMP connections time out after 30 seconds). Specifically, when a network interface initiates access, only outbound rules need to allow the traffic; when a network interface is accessed, only inbound rules need to allow the traffic.
- Changes to security group rules take effect immediately. The changed rules can control both established long-lived connections and new connections.
- A rule with the source address set to the security group itself (such as default) allows network interfaces within the group to be accessed by other interfaces in the same security group. If you delete such rule, network interfaces within the security group will fail to communicate over the private network.
Composition
When you add rules to security groups to allow traffic, the rules include the key parameters as described below:
The following table shows an example: Allow resources in the 12.156.XX.XX/28 range to access network interfaces within the security group via TCP on port 80.
Matching description
When you associate one or more security groups with a network interface:
- If no rule exists in any security group, all inbound and outbound traffic of the network interface is denied.
- If the security group contains one or more rules, the traffic matching process for the network interface is as follows: (inbound traffic of the network interface is used as an example here; the same applies to outbound traffic).
- Priority-based sorting: All inbound rules from all associated security groups are aggregated and sorted by priority from highest to lowest.
tip
- The smaller the priority value, the higher its priority.
- For rules with equal priority, deny policies take precedence over allow policies.
- Matching: Traffic checks against rules from top to bottom. If matched with a rule, the traffic then is allowed or denied based on the rule policy, and the matching process stops. If not matched, the traffic is denied.
Limits
For more information on security group limits, refer to Limits. Use procedure
Usage suggestions
- We recommend that you operate with caution when allowing access to commonly used service ports, such as SSH (22), Redis (6379), MemCache (11211), MySQL (3306), SMB (445), RDP (3389), and SQL Server (1433). For more information on commonly used ports of ECS instances, refer to Commonly used ports of ECS instances.
Last updated: 2026.06.18 17:49:50