ものともしれない日々

参考にできるかかもしれない備忘録

Azure PowerShellを使ってNSGの設定をする

powershellインストール https://docs.microsoft.com/ja-jp/powershell/azure/install-az-ps?view=azps-5.0.0

仮想マシン作成 https://docs.microsoft.com/ja-jp/azure/virtual-machines/windows/quick-create-powershell

NSG作成 https://docs.microsoft.com/ja-jp/azure/virtual-network/manage-network-security-group https://docs.microsoft.com/en-us/powershell/module/az.network/new-aznetworksecurityruleconfig?view=azps-5.0.0

■受信ポート追加

$rule1 = New-AzNetworkSecurityRuleConfig -Name rdp-rule -Description "Allow RDP" `
    -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix `
    Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389

$rule2 = New-AzNetworkSecurityRuleConfig -Name web-rule -Description "Allow HTTP" `
    -Access Allow -Protocol Tcp -Direction Inbound -Priority 101 -SourceAddressPrefix `
    Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 80

$nsg = New-AzNetworkSecurityGroup -ResourceGroupName TestRG -Location westus -Name `
    "NSG-FrontEnd" -SecurityRules $rule1,$rule2

■送信ポート設定追加

Get-AzNetworkSecurityGroup -Name "NSG-FrontEnd" -ResourceGroupName "myResourceGroup" | Add-AzNetworkSecurityRuleConfig -Name sendmail-rule -Description "Allow SMTP" -Access Allow -Protocol Tcp -Direction Outbound -Priority 101 -SourceAddressPrefix * -SourcePortRange 25 -DestinationAddressPrefix * -DestinationPortRange * | Set-AzNetworkSecurityGroup