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

az network nsg rule

管理网络安全组规则。

命令

名称 说明 类型 状态
az network nsg rule create

创建网络安全组规则。

核心 GA
az network nsg rule delete

删除网络安全组规则。

核心 GA
az network nsg rule list

列出网络安全组中的所有规则。

核心 GA
az network nsg rule show

获取网络安全组规则的详细信息。

核心 GA
az network nsg rule update

更新网络安全组规则。

核心 GA
az network nsg rule wait

将 CLI 置于等待状态,直到满足条件。

核心 GA

az network nsg rule create

创建网络安全组规则。

az network nsg rule create --name
                           --nsg-name
                           --priority
                           --resource-group
                           [--access {Allow, Deny}]
                           [--description]
                           [--destination-address-prefixes]
                           [--destination-asgs]
                           [--destination-port-ranges]
                           [--direction {Inbound, Outbound}]
                           [--no-wait {0, 1, f, false, n, no, t, true, y, yes}]
                           [--protocol {*, Ah, Esp, Icmp, Tcp, Udp}]
                           [--source-address-prefixes]
                           [--source-asgs]
                           [--source-port-ranges]

示例

创建优先级最高的基本“允许”NSG 规则。

az network nsg rule create -g MyResourceGroup --nsg-name MyNsg -n MyNsgRule --priority 100

为优先级最低的特定 IP 地址范围创建基于 TCP 的“拒绝”规则。

az network nsg rule create -g MyResourceGroup --nsg-name MyNsg -n MyNsgRule --priority 4096 --source-address-prefixes 208.130.28.0/24 --source-port-ranges 80 --destination-address-prefixes '*' --destination-port-ranges 80 8080 --access Deny --protocol Tcp --description "Deny from specific IP address ranges on 80 and 8080."

使用服务标记创建安全规则(https://aka.ms/servicetags).

az network nsg rule create -g MyResourceGroup --nsg-name MyNsg -n MyNsgRuleWithTags --priority 400 --source-address-prefixes VirtualNetwork --destination-address-prefixes Storage --destination-port-ranges '*' --direction Outbound --access Allow --protocol Tcp --description "Allow VirtualNetwork to Storage."

使用应用程序安全组创建安全规则(https://aka.ms/applicationsecuritygroups).

az network nsg rule create -g MyResourceGroup --nsg-name MyNsg -n MyNsgRuleWithAsg --priority 500 --source-address-prefixes Internet --destination-port-ranges 80 8080 --destination-asgs Web --access Allow --protocol Tcp --description "Allow Internet to Web ASG on ports 80,8080."

必需参数

--name -n

网络安全组规则的名称。

--nsg-name

网络安全组的名称。

--priority

规则的优先级。 该值可以介于 100 和 4096 之间。 对于集合中的每个规则,优先级编号必须是唯一的。 优先级编号越低,规则优先级越高。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

可选参数

--access

允许或拒绝网络流量。

接受的值: Allow, Deny
默认值: Allow
--description

此规则的说明。 限制为 140 个字符。

--destination-address-prefixes

CIDR 前缀或 IP 范围的空格分隔列表。 或者,指定“VirtualNetwork”、“AzureLoadBalancer”、“Internet”或“*”之一以匹配所有 IP。 此外,它还支持所有可用的服务标记,例如“ApiManagement”、“SqlManagement”、“AzureMonitor”等。支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

默认值: ['*']
--destination-asgs

应用程序安全组名称或 ID 的空间分隔列表。 受后端服务器限制,暂时此参数仅支持一个应用程序安全组名称或 ID。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--destination-port-ranges

端口或端口范围的空格分隔列表介于 0-65535 之间。 使用“*”匹配所有端口。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

默认值: ['80']
--direction

规则的方向。 该方向指定在传入或传出流量上是否评估规则。

接受的值: Inbound, Outbound
默认值: Inbound
--no-wait

不等待长时间运行的操作完成。

接受的值: 0, 1, f, false, n, no, t, true, y, yes
--protocol

此规则适用于的网络协议。

接受的值: *, Ah, Esp, Icmp, Tcp, Udp
默认值: *
--source-address-prefixes

CIDR 前缀或 IP 范围的空格分隔列表。 或者,指定“VirtualNetwork”、“AzureLoadBalancer”、“Internet”或“*”之一以匹配所有 IP。 此外,它还支持所有可用的服务标记,例如“ApiManagement”、“SqlManagement”、“AzureMonitor”等。支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

默认值: ['*']
--source-asgs

应用程序安全组名称或 ID 的空间分隔列表。 受后端服务器限制,暂时此参数仅支持一个应用程序安全组名称或 ID。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--source-port-ranges

端口或端口范围的空格分隔列表介于 0-65535 之间。 使用“*”匹配所有端口。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

默认值: ['*']
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az network nsg rule delete

删除网络安全组规则。

az network nsg rule delete [--ids]
                           [--name]
                           [--no-wait {0, 1, f, false, n, no, t, true, y, yes}]
                           [--nsg-name]
                           [--resource-group]
                           [--subscription]

示例

删除网络安全组规则。

az network nsg rule delete -g MyResourceGroup --nsg-name MyNsg -n MyNsgRule

可选参数

--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

网络安全组规则的名称。

--no-wait

不等待长时间运行的操作完成。

接受的值: 0, 1, f, false, n, no, t, true, y, yes
--nsg-name

网络安全组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az network nsg rule list

列出网络安全组中的所有规则。

az network nsg rule list --nsg-name
                         --resource-group
                         [--include-default]

示例

列出网络安全组中的所有规则。

az network nsg rule list -g MyResourceGroup --nsg-name MyNsg

必需参数

--nsg-name

网络安全组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

可选参数

--include-default

在输出中包含默认安全规则。

默认值: False
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az network nsg rule show

获取网络安全组规则的详细信息。

az network nsg rule show [--ids]
                         [--name]
                         [--nsg-name]
                         [--resource-group]
                         [--subscription]

示例

获取网络安全组规则的详细信息。

az network nsg rule show -g MyResourceGroup --nsg-name MyNsg -n MyNsgRule

可选参数

--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

网络安全组规则的名称。

--nsg-name

网络安全组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az network nsg rule update

更新网络安全组规则。

az network nsg rule update [--access {Allow, Deny}]
                           [--add]
                           [--description]
                           [--destination-address-prefixes]
                           [--destination-asgs]
                           [--destination-port-ranges]
                           [--direction {Inbound, Outbound}]
                           [--force-string {0, 1, f, false, n, no, t, true, y, yes}]
                           [--ids]
                           [--name]
                           [--no-wait {0, 1, f, false, n, no, t, true, y, yes}]
                           [--nsg-name]
                           [--priority]
                           [--protocol {*, Ah, Esp, Icmp, Tcp, Udp}]
                           [--remove]
                           [--resource-group]
                           [--set]
                           [--source-address-prefixes]
                           [--source-asgs]
                           [--source-port-ranges]
                           [--subscription]

示例

使用新的 wild卡 目标地址前缀更新 NSG 规则。

az network nsg rule update -g MyResourceGroup --nsg-name MyNsg -n MyNsgRule --destination-address-prefix '*'

更新网络安全组规则。

az network nsg rule update --name MyNsgRule --nsg-name MyNsg --resource-group MyResourceGroup --source-address-prefixes 208.130.28/24

可选参数

--access

允许或拒绝网络流量。

接受的值: Allow, Deny
--add

通过指定路径和键值对将对象添加到对象列表。 示例:--add property.listProperty <key=value、string 或 JSON 字符串>。

--description

此规则的说明。 限制为 140 个字符。

--destination-address-prefixes

CIDR 前缀或 IP 范围的空格分隔列表。 或者,指定“VirtualNetwork”、“AzureLoadBalancer”、“Internet”或“*”之一以匹配所有 IP。 此外,它还支持所有可用的服务标记,例如“ApiManagement”、“SqlManagement”、“AzureMonitor”等。支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--destination-asgs

应用程序安全组名称或 ID 的空间分隔列表。 受后端服务器限制,暂时此参数仅支持一个应用程序安全组名称或 ID。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--destination-port-ranges

端口或端口范围的空格分隔列表介于 0-65535 之间。 使用“*”匹配所有端口。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--direction

规则的方向。 该方向指定在传入或传出流量上是否评估规则。

接受的值: Inbound, Outbound
--force-string

使用“set”或“add”时,保留字符串文本,而不是尝试转换为 JSON。

接受的值: 0, 1, f, false, n, no, t, true, y, yes
--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--name -n

网络安全组规则的名称。

--no-wait

不等待长时间运行的操作完成。

接受的值: 0, 1, f, false, n, no, t, true, y, yes
--nsg-name

网络安全组的名称。

--priority

规则的优先级。 该值可以介于 100 和 4096 之间。 对于集合中的每个规则,优先级编号必须是唯一的。 优先级编号越低,规则优先级越高。

--protocol

此规则适用于的网络协议。

接受的值: *, Ah, Esp, Icmp, Tcp, Udp
--remove

从列表中删除属性或元素。 示例:--remove property.list OR --remove propertyToRemove。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--set

通过指定要设置的属性路径和值来更新对象。 示例:--set property1.property2=。

--source-address-prefixes

CIDR 前缀或 IP 范围的空格分隔列表。 或者,指定“VirtualNetwork”、“AzureLoadBalancer”、“Internet”或“*”之一以匹配所有 IP。 此外,它还支持所有可用的服务标记,例如“ApiManagement”、“SqlManagement”、“AzureMonitor”等。支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--source-asgs

应用程序安全组名称或 ID 的空间分隔列表。 受后端服务器限制,暂时此参数仅支持一个应用程序安全组名称或 ID。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--source-port-ranges

端口或端口范围的空格分隔列表介于 0-65535 之间。 使用“*”匹配所有端口。 支持速记语法、json-file 和 yaml-file。 请尝试“??” 以显示更多内容。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az network nsg rule wait

将 CLI 置于等待状态,直到满足条件。

az network nsg rule wait [--created]
                         [--custom]
                         [--deleted]
                         [--exists]
                         [--ids]
                         [--interval]
                         [--name]
                         [--nsg-name]
                         [--resource-group]
                         [--subscription]
                         [--timeout]
                         [--updated]

可选参数

--created

等待在“Succeeded”中使用“provisioningState”创建。

默认值: False
--custom

等待条件满足自定义 JMESPath 查询。 例如 provisioningState!='InProgress', instanceView.statuses[?code=='PowerState/running']。

--deleted

等到删除为止。

默认值: False
--exists

等待资源存在。

默认值: False
--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--interval

轮询间隔(以秒为单位)。

默认值: 30
--name -n

网络安全组规则的名称。

--nsg-name

网络安全组的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--timeout

最大等待(以秒为单位)。

默认值: 3600
--updated

等到 provisioningState 更新为“Succeeded”。

默认值: False
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。