Adding a Security Group Rule
Scenarios
After a security group is created, you can add rules to the security group. A rule applies either to inbound traffic or outbound traffic. After ECSs are added to the security group, they are protected by the rules of that group.
- Inbound rules control incoming traffic to ECSs associated with the security group.
- Outbound rules control outgoing traffic from ECSs associated with the security group.
For details about the default security group rules, see Default Security Groups and Security Group Rules. For details about security group rule configuration examples, see Security Group Configuration Examples.
Prerequisites
- A security group has been created. For details about how to create a security group, see Creating a Security Group.
- You have planned the public or private networks that can or cannot access instances, such as ECSs. For more examples of security group rules, see Security Group Configuration Examples.
Procedure
- Log in to the management console.
- Click
in the upper left corner and select the desired region and project. - On the console homepage, under Network, click Virtual Private Cloud.
- In the navigation pane on the left, choose Access Control > Security Groups.
- On the Security Groups page, locate the target security group and click Manage Rule in the Operation column to switch to the page for managing inbound and outbound rules.
- On the Inbound Rules tab, click Add Rule. In the displayed dialog box, set required parameters to add an inbound rule. You can click + to add more inbound rules.Figure 1 Add Inbound Rule
Table 1 Inbound rule parameter description Parameter
Description
Example Value
Protocol & Port
Protocol: The network protocol. Currently, the value can be All, TCP, UDP, ICMP, GRE, or others.
TCP
Port: The port or port range over which the traffic can reach your ECS. The value ranges from 1 to 65535. For common ports, see Common Ports Used by ECSs.
22, or 22-30
Type
The IP address type. This parameter is available after the IPv6 function is enabled.- IPv4
- IPv6
IPv4
Source
The source of the security group rule. The value can be a single IP address, an IP address group, or a security group to allow access from the IP address or instances in the security group. For example:- xxx.xxx.xxx.xxx/32 (IPv4 address)
- xxx.xxx.xxx.0/24 (IP address range)
- 0.0.0.0/0 (all IP addresses)
- sg-abc (security group)
For more information about IP address groups, see IP Address Group Overview.
0.0.0.0/0
Description
Supplementary information about the security group rule. This parameter is optional.
The security group rule description can contain a maximum of 255 characters and cannot contain angle brackets (< or >).
N/A
- On the Outbound Rules tab, click Add Rule. In the displayed dialog box, set required parameters to add an outbound rule. You can click + to add more outbound rules.Figure 2 Add Outbound Rule
Table 2 Outbound rule parameter description Parameter
Description
Example Value
Protocol & Port
Protocol: The network protocol. Currently, the value can be All, TCP, UDP, ICMP, GRE, or others.
TCP
Port: The port or port range over which the traffic can leave your ECS. The value ranges from 1 to 65535. For common ports, see Common Ports Used by ECSs.
22, or 22-30
Type
The IP address type. This parameter is available after the IPv6 function is enabled.- IPv4
- IPv6
IPv4
Destination
The destination of the security group rule. The value can be a single IP address, an IP address group, or a security group to allow access to the IP address or instances in the security group. For example:- xxx.xxx.xxx.xxx/32 (IPv4 address)
- xxx.xxx.xxx.0/24 (IP address range)
- 0.0.0.0/0 (all IP addresses)
- sg-abc (security group)
For more information about IP address groups, see IP Address Group Overview.
0.0.0.0/0
Description
Supplementary information about the security group rule. This parameter is optional.
The security group rule description can contain a maximum of 255 characters and cannot contain angle brackets (< or >).
N/A
- Click OK.
Verification
After required security group rules are added, you can verify that the rules take effect. For example, you have deployed a website on ECSs. Users need to access your website over TCP (port 80), and you have added the security group rule shown in Table 3.
Linux ECS
To verify the security group rule on a Linux ECS:
- Log in to the ECS.
- Run the following command to check whether TCP port 80 is listened:
netstat -an | grep 80
If command output shown in Figure 3 is displayed, TCP port 80 is listened.
- Enter http://ECS EIP in the address box of the browser and press Enter.
If the requested page can be accessed, then the security group rule has taken effect.
Windows ECS
To verify the security group rule on a Windows ECS:
- Log in to the ECS.
- Choose Start > Accessories > Command Prompt.
- Run the following command to check whether TCP port 80 is listened:
netstat -an | findstr 80
If command output shown in Figure 4 is displayed, TCP port 80 is listened.
- Enter http://ECS EIP in the address box of the browser and press Enter.
If the requested page can be accessed, then the security group rule has taken effect.
Related Operations
Allow Common Ports
You can click Allow Common Ports to allow traffic on some common ports, such as port 21, 22, 3389, 80, 443, and 20.
Helpful Links
Last Article: Creating a Security Group
Next Article: Fast-Adding Security Group Rules


Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.