Azure PowerShell (13) 批量设置Azure ARM Network Security Group (NSG)

简介:

 《Windows Azure Platform 系列文章目录

 

  刚刚在帮助一个合作伙伴研究需求,他们的虚拟机全面的网络安全组(Network Security Group, NSG)会经常变动,如果手动修改非常麻烦。

  看看是否有批量设置的方法。我仔细研究了一下,记一下笔记。

 

  注意:这里介绍的是Azure ARM模式下的,虚拟机的Azure NSG网络安全组。

 

  前提需求:

  1.安装Azure PowerShell

  2.Azure ARM模式下的资源

 

  具体运行的Azure PowerShell

复制代码
Add-AzureRmAccount -EnvironmentName AzureChinaCloud
#在弹出的界面中,输入用户名和密码,则登陆通过
#不过关闭PowerShell以后,下次要重新进行身份验证

#选择相应的订阅名称:
Select-AzureRmSubscription -SubscriptionName 'Training'| Select-AzureRmSubscription

#请注意下面的NSG必须之前是已经存在的
$resourceGroupName='LeiLinuxRG'
$nsgName= 'LeiCentOS68-nsg'

#创建允许外部对3306端口访问,源IP必须是192.168.1.0/24
$ruleName1= 'Inbound3306-rule'
$sourceIP= '192.168.1.0/24'
$destinationPort = 3306

$nsg = Get-AzureRmNetworkSecurityGroup -Name $nsgName -ResourceGroupName $resourceGroupName

$nsg | Add-AzureRmNetworkSecurityRuleConfig -Name $ruleName1 -Description "Allow 3306" -Access `
    Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix $sourceIP `
    -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange $destinationPort

#创建允许外部对3389端口访问,源IP必须是192.168.1.0/24
$ruleName2= 'Inbound3389-rule'
$destinationPort = 3389

$nsg | Add-AzureRmNetworkSecurityRuleConfig -Name $ruleName2 -Description "Allow RDP" -Access `
    Allow -Protocol Tcp -Direction Inbound -Priority 110 -SourceAddressPrefix $sourceIP `
    -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange $destinationPort

$nsg | Set-AzureRmNetworkSecurityGroup
复制代码

 


本文转自Azure Lei Zhang博客园博客,原文链接:http://www.cnblogs.com/threestone/p/6869513.html,如需转载请自行联系原作者


目录
相关文章
|
6月前
|
JavaScript 前端开发 API
【Azure Developer】use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential authentication failed.(status code 500)
【Azure Developer】use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential authentication failed.(status code 500)
|
3月前
【Azure App Service】PowerShell脚本批量添加IP地址到Web App允许访问IP列表中
Web App取消公网访问后,只允许特定IP能访问Web App。需要写一下段PowerShell脚本,批量添加IP到Web App的允许访问IP列表里!
|
4月前
|
数据安全/隐私保护
【Azure Entra ID】使用PowerShell脚本导出Entra ID中指定应用下的所有用户信息
在Azure Entra ID中,需要导出一个Application 下的用户信息, 包含User的创建时间。
|
6月前
|
存储 Windows
在 PowerShell 中获取代理设置
【8月更文挑战第27天】
202 6
|
6月前
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
|
6月前
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
|
6月前
|
存储 C# Python
【Azure Storage Account】Azure 存储服务计算Blob的数量和大小的PowerShell代码
【Azure Storage Account】Azure 存储服务计算Blob的数量和大小的PowerShell代码
|
6月前
|
Ubuntu Linux 测试技术
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
|
1月前
|
机器学习/深度学习 弹性计算 人工智能
阿里云服务器ECS架构区别及选择参考:X86计算、ARM计算等架构介绍
在我们选购阿里云服务器的时候,云服务器架构有X86计算、ARM计算、GPU/FPGA/ASIC、弹性裸金属服务器、高性能计算可选,有的用户并不清楚他们之间有何区别,本文主要简单介绍下这些架构各自的主要性能及适用场景,以便大家了解不同类型的架构有何不同,主要特点及适用场景有哪些。
113 10
|
2月前
|
人工智能 芯片 Windows
ARM架构PC退货率与CEO策略透视
ARM架构PC退货率与CEO策略透视