全部產品
Search
文件中心

Elastic Compute Service:ModifySecurityGroupRule

更新時間:Jun 29, 2026

本介面用於修改指定安全性群組中的一條入方向安全性群組規則。

介面說明

指定安全性群組規則 ID 修改安全性群組規則時,您需要注意以下使用限制:

  • 安全性群組規則的授權對象分為 IPv4 的 CIDR 位址區塊(或 IP 位址)、IPv6 的 CIDR 位址區塊(或 IP 位址)、安全性群組、前綴列表,您不能透過該介面修改已有安全性群組規則的授權對象類型。如原來授權對象類型為 IPv4 的 CIDR 位址區塊,您可以更改為另一個 IPv4 的 CIDR 位址區塊(或 IP 位址),但不能修改為 IPv6 的 CIDR 位址區塊(或 IP 位址)、安全性群組或前綴列表。

  • 欄位不支援從非空修改為空,如果需要修改建議先增加一條新規則,再刪除當前規則。

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

下表是API對應的授權資訊,可以在RAM權限原則語句的Action元素中使用,用來給RAM使用者或RAM角色授予調用此API的許可權。具體說明如下:

  • 操作:是指具體的許可權點。

  • 存取層級:是指每個操作的存取層級,取值為寫入(Write)、讀取(Read)或列出(List)。

  • 資源類型:是指操作中支援授權的資源類型。具體說明如下:

    • 對於必選的資源類型,用前面加 * 表示。

    • 對於不支援資源級授權的操作,用全部資源表示。

  • 條件關鍵字:是指雲產品自身定義的條件關鍵字。

  • 關聯操作:是指成功執行操作所需要的其他許可權。操作者必須同時具備關聯操作的許可權,操作才能成功。

操作

存取層級

資源類型

條件關鍵字

關聯操作

ecs:ModifySecurityGroupRule

update

*All Resource

*

  • ecs:SecurityGroupIpProtocols
  • ecs:SecurityGroupSourceCidrIps

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

目標安全性群組所屬地域 ID。您可以呼叫 DescribeRegions 查看最新的阿里雲地域列表。

cn-hangzhou

RegionId

string

目標安全性群組所屬地域 ID。您可以呼叫 DescribeRegions 查看最新的阿里雲地域列表。

cn-hangzhou

ClientToken

string

保證請求冪等性。從您的用戶端產生一個參數值,確保不同請求間該參數值唯一。ClientToken 只支援 ASCII 字元,且不能超過 64 個字元。更多資訊,請參見如何保證冪等性

123e4567-e89b-12d3-a456-426655440000

SecurityGroupId

string

安全性群組 ID。

sg-bp67acfmxazb4p****

SecurityGroupRuleId

string

安全性群組規則 ID。您可以透過 DescribeSecurityGroupAttribute 查詢安全性群組規則 ID。

sgr-bp67acfmxa123b***

Policy

string

存取權限。取值範圍:

  • accept:接受存取。

  • drop:拒絕存取,不返回拒絕資訊。

預設值:accept。

accept

Priority

string

安全性群組規則優先順序。取值範圍:1~100。

預設值:1。

1

IpProtocol

string

網路層/傳輸層協議。支援兩類賦值:

  1. 不區分大小寫的協議名。取值範圍:

  • ICMP

  • GRE

  • TCP

  • UDP

  • ALL:支援所有協議。

  1. 符合 IANA 規範的協議號取值,即 0 到 255 的整數。目前開放的地域列表:

  • 菲律賓

  • 英國

  • 馬來西亞

  • 呼和浩特

  • 青島

  • 美西

  • 新加坡

ALL

SourceCidrIp

string

設定存取權限的來源端 IPv4 CIDR 位址區塊。支援 CIDR 格式和 IPv4 格式的 IP 位址範圍。

預設值:無。

10.0.0.0/8

Ipv6SourceCidrIp

string

設定存取權限的來源端 IPv6 CIDR 位址區塊。支援 CIDR 格式和 IPv6 格式的 IP 位址範圍。

說明

僅支援 VPC 類型的 IP 位址,且該參數與SourceCidrIp參數不可同時設定。

預設值:無。

2001:db8:1233:1a00::***

SourceGroupId

string

設定存取權限的來源端安全性群組 ID。至少設定一項SourceGroupId或者SourceCidrIp參數。

  • 如果指定了SourceGroupId沒有指定參數SourceCidrIp,則參數NicType取值只能為 intranet。

  • 如果同時指定了SourceGroupIdSourceCidrIp,則預設以SourceCidrIp為準。

sg-bp67acfmxa123b****

SourcePrefixListId

string

設定存取權限的來源端前綴列表 ID。您可以呼叫 DescribePrefixLists 查詢可以使用的前綴列表 ID。

當您指定了SourceCidrIpIpv6SourceCidrIpSourceGroupId參數中的一個時,將忽略該參數。

pl-x1j1k5ykzqlixdcy****

PortRange

string

目的端安全性群組開放的傳輸層協議相關的連接埠範圍。取值範圍:

  • TCP/UDP 協議:取值範圍為 1~65535。使用斜線(/)隔開起始連接埠和終止連接埠。例如:1/200。

  • ICMP 協議:-1/-1。

  • GRE 協議:-1/-1。

  • ALL:-1/-1。

80/80

DestCidrIp

string

目的端 IPv4 CIDR 位址區塊。支援 CIDR 格式和 IPv4 格式的 IP 位址範圍。

預設值:無。

10.0.0.0/8

Ipv6DestCidrIp

string

目的端 IPv6 CIDR 位址段。支援 CIDR 格式和 IPv6 格式的 IP 位址範圍。

說明

僅支援 VPC 類型的 IP 位址,且該參數與DestCidrIp參數不可同時設定。

預設值:無。

2001:db8:1234:1a00::***

SourcePortRange

string

來源端安全性群組開放的傳輸層協議相關的連接埠範圍。取值範圍:

  • TCP/UDP 協議:取值範圍為 1~65535。使用斜線(/)隔開起始連接埠和終止連接埠。例如:1/200

  • ICMP 協議:-1/-1。

  • GRE 協議:-1/-1。

  • ALL:-1/-1。

80/80

SourceGroupOwnerAccount

string

跨帳號設定安全性群組規則時,來源端安全性群組所屬的阿里雲帳號。

  • 如果SourceGroupOwnerAccountSourceGroupOwnerID均未設定,則認為是設定您其他安全性群組的存取權限。

  • 如果已經設定參數SourceCidrIp,則參數SourceGroupOwnerAccount無效。

EcsforCloud@Alibaba.com

SourceGroupOwnerId

integer

跨帳號設定安全性群組規則時,來源端安全性群組所屬的阿里雲帳號。

  • 如果SourceGroupOwnerIdSourceGroupOwnerAccount均未設定,則認為是設定您其他安全性群組的存取權限。

  • 如果您已經設定參數SourceCidrIp,則參數SourceGroupOwnerId無效。

12345678910

NicType

string

網路卡類型。

說明

根據安全性群組規則 ID 修改規則時,不支援修改該參數。如果需要修改,建議先增加一條新規則,再刪除當前規則。

intranet

Description

string

安全性群組規則的描述資訊。長度為 1~512 個字元。

This is a new security group rule.

PortRangeListId

string

連接埠列表 ID。

您可以呼叫DescribePortRangeLists查詢可以使用的連接埠列表 ID。

當您指定了 PortRange 參數時,將忽略該參數。

更多資訊,請參見安全性群組使用限制

prl-2ze9743****

返回參數

名稱

類型

描述

樣本值

object

RequestId

string

請求 ID。

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

樣本

正常返回樣本

JSON格式

{
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 OperationDenied The specified IpProtocol does not exist or IpProtocol and PortRange do not match.
400 InvalidIpProtocol.Malformed The specified parameter PortRange is not valid.
400 InvalidSourceCidrIp.Malformed The specified parameter SourceCidrIp is not valid.
400 InvalidPolicy.Malformed The specified parameter Policy is not valid.
400 InvalidNicType.ValueNotSupported The specified NicType does not exist.
400 InvalidNicType.Mismatch The specified NicType conflicts with the authorization record.
400 InvalidSourceGroupId.Mismatch Specified security group and source group are not in the same VPC.
400 InvalidSourceGroup.NotFound Specified source security group does not exist.
400 InvalidPriority.Malformed The parameter Priority is invalid.
400 InvalidPriority.ValueNotSupported The parameter Priority is invalid.
400 InvalidSecurityGroupDiscription.Malformed The specified security group rule description is not valid.
400 MissingParameter.Source One of the parameters SourceCidrIp, SourceGroupId or SourcePrefixListId must be specified.
400 InvalidParam.PortRange The specified parameter %s is not valid. It should be two integers less than 65535 in ?/? format.
400 InvalidIpProtocol.ValueNotSupported The parameter IpProtocol must be specified with case insensitive TCP, UDP, ICMP, GRE or All.
400 InvalidParam.SourceIp The Parameters SourceCidrIp and Ipv6SourceCidrIp in %s cannot be set at the same time.
400 InvalidParam.DestIp The Parameters DestCidrIp and Ipv6DestCidrIp in %s cannot be set at the same time.
400 InvalidParam.Ipv6DestCidrIp The specified parameter %s is not valid.
400 InvalidParam.Ipv6SourceCidrIp The specified parameter %s is not valid.
400 InvalidParam.Ipv4ProtocolConflictWithIpv6Address IPv6 address cannot be specified for IPv4-specific protocol.
400 InvalidParam.Ipv6ProtocolConflictWithIpv4Address IPv4 address cannot be specified for IPv6-specific protocol.
400 InvalidParameter.Ipv6CidrIp The specified Ipv6CidrIp is not valid.
400 InvalidParam.DestCidrIp The specified parameter %s is not valid.
400 InvalidSourcePortRange.Malformed The specified parameter SourcePortRange is not valid.
400 InvalidSecurityGroupId.Malformed The specified parameter SecurityGroupId is not valid.
400 InvalidParam.SourceCidrIp The specified param SourceCidrIp is not valid.
400 InvalidParameter.Conflict IPv6 and IPv4 addresses cannot exist at the same time.
400 InvalidParam.SecurityGroupRuleId The specified parameter SecurityGroupRuleId is not valid.
400 InvalidOperation.ModifySgRuleEntityType The source or destination type of the rules cannot be modified.
400 AuthorizationLimitExceed The limit of authorization records in the security group reaches.
400 InvalidParam.ProtocolAndPortRangeMismatch The specified Protocol and PortRange do not match.
400 InvalidParam.ProtocolAndAddressFamilyMismatch The specified Protocol and address family do not match.
400 InvalidParam.PrefixListAddressFamilyMismatch The address family of the prefix list does not match the rule.
400 InvalidParam.InvalidModifyRuleRequest The request parameters are illegal.
400 InvalidOperation.ModifyNicType NicType is not allowed to modify.
400 InvalidParamter.Conflict The specified SourceCidrIp should be different from the DestCidrIp.
400 InvalidOperation.RuleDuplicate %s.
400 InvalidParam.ProtocolNotSupportPortRangeList The specified protocol does not support the port range list.
400 InvalidSourceOrDestGroupId.DirectionMissmatch The specified SourceGroupId or DestGroupId does not match the direction of the rule.
400 InvalidOperation.ModifyPortRangeType The PortRange type is not allowed to be modified. You cannot modify a rule from using the port list to not using it, and vice versa.
400 InvalidPortRangeListId.NotFound The specified port range list was not found.
500 InternalError The request processing has failed due to some unknown error.
403 InvalidSourceGroupId.Mismatch NicType is required or NicType expects intrnet.
403 MissingParameter The input parameter SourceGroupId or SourceCidrIp cannot be both blank.
403 AuthorizationLimitExceed The limit of authorization records in the security group reaches.
403 InvalidParamter.Conflict The specified SecurityGroupId should be different from the SourceGroupId.
403 InvalidNetworkType.Mismatch The specified SecurityGroup network type should be same with SourceGroup network type (vpc or classic).
403 InvalidOperation.ResourceManagedByCloudProduct %s
404 InvalidSecurityGroupId.NotFound The specified SecurityGroupId does not exist.
404 InvalidSourceGroupId.NotFound The SourceGroupId provided does not exist in our records.
404 SecurityGroupRule.NotFound The target security group rule not exist.
404 InvalidPrefixListId.NotFound The specified prefix list was not found.
404 InvalidSecurityGroupRuleId.NotFound The specified SecurityGroupRuleId is not exists.

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情