Öncelikle PowerShell ile Azure RM Account’ımıza Login olup çalışacağımız Subscription seçiyoruz.
Login-AzureRMAccount
Select-AzurermSubscription -SubscriptionId “XXXXXXX-1354886-123459876”
# Değişkenler:
$RGname= “RG_EmreMartin”
$Nsgname= “TestNSG”
$Location= “WestEurope”
# Network Security Group Oluşturma
New-AzureRmNetworkSecurityGroup -ResourceGroupNAme $RGName -Location $Location -Name $NSGName
# Değişkenlerin Atanması
$resource = Get-AzureRmResource | Where {$_.ResourceGroupName –eq
$RGname -and $_.ResourceType -eq "Microsoft.Network/networkSecurityGroups"}
$nsg = Get-AzureRmNetworkSecurityGroup -Name $nsgname -ResourceGroupName $Rgname
# Network Security Group’a Rule Ekleme
*Allow RDP isimli bir rule oluşturup 85.25.11.111 IP’si için 3398 TCP portu üzerinden RDP yetkisi tanımlayacağız.
$nsg | Set-AzureRmNetworkSecurityRuleConfig -Name “AllowRDP”
-Description "AllowRDP" -Access Allow -Protocol "TCP" -Direction Inbound
-Priority 100 -SourceAddressPrefix “85.25.11.111” -SourcePortRange “*”
-DestinationAddressPrefix * -DestinationPortRange "3389"
# Netowork Security Group Rule Update
$nsg | Set-AzureRmNetworkSecurityRuleConfig -Name "AllowRDP"
-Description “AllowRDP” -Access Deny -Protocol “TCP” -Direction Inbound
-Priority 100 -SourceAddressPrefix "85.25.11.111" -SourcePortRange "*"
-DestinationAddressPrefix * -DestinationPortRange “3389”
# Network Security Group Rule Silme
$nsg | remove-AzureRmNetworkSecurityRuleConfig -Name “AllowRDP”
# Network Security Group Güncellemelerinin Uygulanması (Rule Ekleme,Silme)
NSG üzerinde rule ekleme, silme ve update işlemlerinden sonra bu satırı çalıştırıyoruz.
$nsg | Set-AzureRmNetworkSecurityGroup
# Network Security Group’un Silinmesi
$nsg = remove-AzureRmNetworkSecurityGroup -Name $nsgname -ResourceGroupName $RGname
# Network Security Group’un VM Atanması
$NICName = “cloudapp114 ”
$NIC = Get-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $RGname
$NIC.NetworkSecurityGroup = $NSG
Set-AzureRmNetworkInterface -NetworkInterface $NIC
# Network Security Group’un VM’den Kaldırılması
$NIC.NetworkSecurityGroup = $null
Set-AzureRmNetworkInterface -NetworkInterface $NIC
Aynı işlemleri dilerseniz Azure CLI ile gerçekleştirebilirsiniz.
“Azure CLI ile NSG Yönetimi.”
Faydalı olması dilegiyle.