Azure Lei Zhang的博客

weibo: LeiZhang的微博/QQ: 185165016/QQ群:319036205/邮箱:leizhang1984@outlook.com/TeL:139-161-22926

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  489 随笔 :: 0 文章 :: 417 评论 :: 70万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

  《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
复制代码

 

posted on   Lei Zhang的博客  阅读(652)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示