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
  • 相关阅读:
    一个cs架构的在线考试系统
    TreeComboBox控件范例
    new和override修饰符的区别
    Hello cnblogs
    MapInfo图层坐标系统转换
    C#调用新浪微博API生成RSS资源文件
    MapInfo图层格式转ArcGIS图层格式
    用ArcGIS的ArcToolbox进行地图切割
    VS2008智能提示消失的解决方法
    【学习笔记】零基础C#窗口程序开发入门
  • 原文地址:https://www.cnblogs.com/threestone/p/6869513.html
Copyright © 2011-2022 走看看