zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    VC++对话框笔记
    STL中用erase()方法遍历删除元素
    VC++中不小心选错工程类型的解决办法
    directX中常用的数学计算
    VC++中string、char* 转换为LPCSTR
    判断空间上点是否在直线上
    vc6.0插件
    VC++常用定义(如SAFE_DELETE等)
    关于控件的AutoSize属性影响界面布局的问题解决
    C#判断日期是否正确(1900~今年,月份,天数)
  • 原文地址:https://www.cnblogs.com/threestone/p/6869513.html
Copyright © 2011-2022 走看看