azure - 向 Azure NSG 规则添加多个 IP
问题描述
我有 Azure NSG。在里面我有一个名为“Blocked_IP”的规则,我需要每天使用数千个新 ip 自动更新此规则的过程(每个规则的 Azure 最大 ip 为 4k)
查看文档我有 2 个可能的命令:
$ipsarry = Get-Content .\file.txt
az network nsg rule update -g $groupName --nsg-name $NSGName -n $ruleName --source-address-prefix $ipsarry
file.txt 将保存 ips。这将起作用,只要 file.txt 保持 aprox 小于 500 ips,就好像我添加更多命令将是一个非常长的字符串并且会有异常。我无法部分添加它,因为我找不到附加数据的方法,每次调用时都会删除旧数据。
使用其他命令
$NSG = Get-AzNetworkSecurityGroup -Name 'test' -ResourceGroupName 'Testik'
$Params = @{
'Name' = 'auto_farm_protection4'
'NetworkSecurityGroup' = $NSG
'Protocol' = 'TCP'
'Direction' = 'Inbound'
'Priority' = 500
'SourceAddressPrefix' = "1.1.1.1, 2.2.2.2"
'SourcePortRange' = '*'
'DestinationAddressPrefix' = '*'
'DestinationPortRange' = 3389
'Access' = 'Deny'
}
Add-AzNetworkSecurityRuleConfig @Params | Set-AzNetworkSecurityGroup
会给我同样的问题。
看起来谷歌对我帮助不大。任何帮助都会很棒。
解决方案
您可以使用Set-AzNetworkSecurityRuleConfig -Name <String> -NetworkSecurityGroup <PSNetworkSecurityGroup> -SourceAddressPrefix String[]
. 将文本文件中的 ip 地址加载到字符串数组中(我猜你有一个分隔 ip 地址的分隔符)。最后,将其传递给SourceAddressPrefix的参数。
推荐阅读
- python - 我是否必须在同一范围内调用 py::initialize_interpreter() 和 py::finalize_interpreter() ?
- c# - SignalR 在服务器上获取不记名令牌
- icc - 安装 Intel oneAPI 后找不到 icc 编译器,在 Ubuntu 20 上从 bash 调用
- php - PHP Slim v3 post 方法 405(使用 POSTMAN 测试!)
- oracle - 防止 FAST_PCT mview 刷新
- google-cloud-build - PROJECT_ID env 和 Secret Manager 访问
- sql - 聚合函数(MAX 等)返回 NULL 而不是没有行
- sql - 什么是正确的查询?
- css - 为什么 Sass 使用嵌套媒体查询不尊重 CSS 属性的顺序?
- python - python / plotly(express)中的堆积条形图:条形的分组/排序