Set-AzFirewallPolicyRuleCollectionGroup 保存多个Rule Collection

使用Azure Powershell 设置 Rule Collection Group, 首先需要创建 Firewall policy。

在创建完firewall policy后,通过Azure Portal页面添加 Rule Collection Group。

然后就可以使用 Set-AzFirewallPolicyRuleCollectionGroup命令在Firewall policy中添加Rule Collection Group了。

以下是一个简单例子,通过Azure Powershell在Rule Collection Group中添加Rule Collection和Rules。

$resourceGroup = "test_rg"

fprg = resourceGroup

targetfp = Get-AzFirewallPolicy -Name "testFWpolicy" -ResourceGroupName fprg //获取Firewall Policy对象

targetrcg = Get-AzFirewallPolicyRuleCollectionGroup -AzureFirewallPolicyName "vincentFWpolicy" -Name "network-segmentation-local" -ResourceGroupName resourceGroup //获取Rule Collection Group对象

$rules = @()

$RuleParameter = @{

Name = "net-pde-to-external-prod-allowasdfajsdlflklkajlkfd"

Protocol = "Any"

sourceAddress = "*"

DestinationAddress = "*"

DestinationPort = "*"

}

$rule = New-AzFirewallPolicyNetworkRule @RuleParameter

$NetworkRuleCollection = @{

Name = "src-azure-network-rules-segmentation-allow"

Priority = "666"

ActionType = "Allow"

Rule = rules += rule

} //在第一个Rule Collection中添加Rule

$NetworkRuleCategoryCollection = New-AzFirewallPolicyFilterRuleCollection @NetworkRuleCollection

$rules = @()

$RuleParameter = @{

Name = "net-pde-to-external-prod-allow-all2"

Protocol = "Any"

sourceAddress = "*"

DestinationAddress = "*"

DestinationPort = "*"

}

$rule = New-AzFirewallPolicyNetworkRule @RuleParameter

$NetworkRuleCollection2 = @{

Name = "src-azure-network-rules-segmentation-allowasdfasdf2"

Priority = "888"

ActionType = "Allow"

Rule = rules += rule

} //在第二个Rule Collection中添加Rule

$NetworkRuleCategoryCollection2 = New-AzFirewallPolicyFilterRuleCollection @NetworkRuleCollection2

//将以上创建的两个Rule Collection加入Rule Collection Group对象

targetrcg.Properties.RuleCollection.Add(NetworkRuleCategoryCollection)

targetrcg.Properties.RuleCollection.Add(NetworkRuleCategoryCollection2)

//设置保存Rule Collection Group并使其生效

Set-AzFirewallPolicyRuleCollectionGroup -FirewallPolicyName testFWpolicy -Name targetrcg.Name -Priority 112 -ResourceGroupName test_rg -RuleCollection targetrcg.Properties.RuleCollection

需要注意的问题:

Set-AzFirewallPolicyRuleCollectionGroup这个命令执行的是Overwrite操作,它会保存命令中的多个Rule Collection。同时会覆盖掉之前的配置,如果保存之前在Rule Collection Group中存在其他的Rule Collection,那么这些没有在命令中被写入的Rule Collection就会被擦除。所以如果想一次在Rule Collection Group中设置多个Rule Collection。需要在参数中指定多个Rule Collection的数组。

参考文档:

Set-AzFirewallPolicyRuleCollectionGroup (Az.Network) | Microsoft Learn

相关推荐
EllenShen1235 小时前
(Azure)PGSQL和redis 连通性测试 --code 备份
redis·postgresql·azure
HelloRevit2 天前
快速入门 - Azure 数字孪生的 3D 场景工作室(预览版)入门
3d·flask·azure
HelloRevit3 天前
快速入门 - 开始使用 Azure Digital Twins Explorer 中的示例场景
microsoft·flask·azure
城南花开时4 天前
DevOps工具链对比,Azure 和 TikLab哪款更好用?
azure·devops·tiklab
宝桥南山4 天前
Microsoft Fabric - 试一下在前端应用中使用 GraphQL API去连接Lakehouse
microsoft·reactjs·azure·fabric·graphql·db
Leinwin9 天前
微软发布Azure Kubernetes Service Automatic国际版
microsoft·kubernetes·azure
Elastic 中国社区官方博客10 天前
如何在 Azure 虚拟机上部署 Elasticsearch
大数据·人工智能·elasticsearch·microsoft·搜索引擎·全文检索·azure
FreeBuf_10 天前
微软全球服务中断:Azure、365、Xbox及Minecraft等多平台受影响
microsoft·azure·xbox
weixin_3077791311 天前
C#程序实现将Teradata的存储过程转换为Azure Synapse Dedicated SQL pool的存储过程
数据库·数据分析·c#·云计算·azure
ManageEngine卓豪11 天前
Azure 监控工具怎么选?从原生局限到第三方解决方案的效率跃升
microsoft·azure·apm·azure监控