可以通过 az postgres flexible-server firewall-rule create 命令将防火墙规则添加到服务器。
az postgres flexible-server firewall-rule create --resource-group <resource_group> --name <server> --rule-name <rule> --start-ip-address <start_ip_address> --end-ip-address <end_ip_address>
如果尝试在未处于 Ready
状态的服务器上添加防火墙规则,则会收到如下所示的错误:
Code: InternalServerError
Message: An unexpected error occured while processing the request. Tracking ID: '<tracking_id>'
备注
防火墙规则名称只能包含 0
-9
、a
-z
、A
-Z
、-
和 _
。 此外,防火墙规则的名称长度必须至少为 3 个字符,且不超过 128 个字符。
如果尝试添加名称无效的防火墙规则,则将收到如下所示的错误:
The firewall rule name can only contain 0-9, a-z, A-Z, '-' and '_'. Additionally, the name of the firewall rule must be at least 3 characters and no more than 128 characters in length.
如果尝试添加一个名称与另一个现有防火墙规则名称匹配的防火墙规则,则不会收到错误,但该规则会使用为 --start-ip-address
和 --end-ip-address
提供的值进行更新。
如果为 --start-ip-address
和 --end-ip-address
参数传递无效的 IP 地址,则会收到如下所示的错误:
Incorrect value for ip address. Ip address should be IPv4 format. Example: 12.12.12.12.
如果为 --start-ip-address
传递的值大于为 --end-ip-address
传递的值,则会收到如下所示的错误:
The end IP address is smaller than the start IP address.
如果尝试将防火墙规则添加到未启用公共访问权限的服务器,则会收到如下所示的错误:
Firewall rule operations cannot be requested for a private access enabled server.
备注
虽然不建议这样做,但可以创建具有不同名称和重叠 IP 范围(甚至起始和结束 IP 地址完全相同)的多个防火墙规则。
若要允许从 Azure 中的任何 Azure 服务公开访问服务器,必须创建一个防火墙规则,并将其起始和结束 IP 地址都设置为 0.0.0.0
。
重要
在防火墙中配置一条规则并将起始和结束 IP 地址设置为 0.0.0.0
时,会将防火墙配置为允许来自分配给任何 Azure 服务或资产的 IP 地址的连接,包括来自其他客户的订阅的连接。