Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Networking with Azure

You're reading from   Hands-On Networking with Azure Build large-scale, real-world apps using Azure networking solutions

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher
ISBN-13 9781788998222
Length 276 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Mohamed Waly Mohamed Waly
Author Profile Icon Mohamed Waly
Mohamed Waly
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Azure Virtual Networks 101 FREE CHAPTER 2. Delving into Azure Virtual Networks 3. Azure Network for VMs 4. Network Connectivity Scenarios in Azure 5. Azure DNS 6. Azure Load Balancers 7. Azure Traffic Manager 8. Azure Application Gateway 9. Other Books You May Enjoy

Automating your tasks

It is no surprise that we commonly face repetitive and time-consuming tasks. For example, you might want to create multiple storage accounts. You would have to follow the previous guide multiple times to get your job done. This is why Microsoft supports its Azure services with multiple ways of automating most of the tasks that can be implemented in Azure. Throughout this book, two of the automation methods that Azure supports will be used.

Azure PowerShell

PowerShell is commonly used with most Microsoft products, and Azure is not less important than any of these products.

Mainly, you can use Azure PowerShell cmdlets to manage Azure Networking tasks, however, you should be aware that Microsoft Azure has two types of cmdlets, one for the ASM model, and another for the ARM model, which we will be using throughout this book.

The main difference between cmdlets of the ASM model and the ARM model is, there will be an RM added to the cmdlet of the current portal.

For example, if you want to create an ASM virtual network, you would use the following cmdlet:

New-AzureVirtualNetwork

But for the ARM model, you would use the following:

New-AzureRMVirtualNetwork
Most of the time this would be the case. But a few Cmdlets are totally different and some others don't even exist in the ASM model and do exist in the ARM model.

By default, you can use Azure PowerShell cmdlets in Windows PowerShell, but you will have to install its module first.

Installing the Azure PowerShell module

Installing the Azure PowerShell module from PowerShell Gallery

The following are the required steps to get Azure PowerShell installed:

  1. Open PowerShell in an elevated mode.
  2. To install the Azure PowerShell module for the current portal run the following cmdlet Install-Module AzureRM. If your PowerShell requires a NuGet provider you will be asked to agree to install it, and you will have to agree for the installation policy modification, as the repository is not available on your environment, as shown in the following screenshot:
Figure 1.14 Installing the AzureRM PowerShell module

Creating a virtual network in Azure portal using PowerShell

To be able to run your PowerShell cmdlets against Azure successfully, you need to log in first to Azure using the following cmdlet:

Login-AzureRMAccount

Then, you will be prompted to enter the credentials of your Azure account. Voila! You are logged in and you can run Azure PowerShell cmdlets successfully.

To create an Azure VNet, you first need to create the subnets that will be attached to this virtual network. Therefore, let's get started by creating the subnets:

$NSubnet = New-AzureRMVirtualNetworkSubnetConfig –Name NSubnet -AddressPrefix 192.168.1.0/24
$GWSubnet = New-AzureRMVirtualNetworkSubnetConfig –Name GatewaySubnet -AddressPrefix 192.168.2.0/27

Now you are ready to create a virtual network by triggering the following cmdlet:

New-AzureRMVirtualNetwork -ResourceGroupName PacktPub -Location WestEurope -Name PSVNet -AddressPrefix 192.168.0.0/16 -Subnet $NSubnet,$GWSubnet

Congratulations! You have your virtual network up and running with two subnets associated to it, one of them is a gateway subnet.

Adding address space to a virtual network using PowerShell

To add an address space to a virtual network, you need retrieve the virtual network first and store it in a variable by running the following cmdlet:

$VNet = Get-AzureRMVirtualNetwork -ResourceGroupName PacktPub -Name PSVNet

Then, you can add the address space by running the following cmdlet:

$VNet.AddressSpace.AddressPrefixes.Add("10.1.0.0/16")

Finally, you need to save the changes you have made by running the following cmdlet:

Set-AzureRmVirtualNetwork -VirtualNetwork $VNet

Azure CLI

Azure CLI is an open source, cross platform that supports implementing all the tasks you can do in Azure portal, with commands.

Azure CLI comes in two flavors:

  • Azure CLI 2.0: Which supports only the current Azure portal
  • Azure CLI 1.0: Which supports both portals

Throughout this book, we will be using Azure CLI 2.0, so let's get started with its installation.

Installing Azure CLI 2.0

Perform the following steps to install Azure CLI 2.0:

  1. Download Azure CLI 2.0, from the following link: https://azurecliprod.blob.core.windows.net/msi/azure-cli-2.0.22.msi
  1. Once downloaded, you can start the installation:
Figure 1.15: Installing Azure CLI 2.0
  1. Once you click on Install, it will start to validate your environment to
    check whether it is compatible with it or not, then it starts the
    installation:
Figure 1.16: Installing Azure CLI 2.0
  1. Once the installation completes, you can click on Finish, and you are good to go:
Figure 1.17: Installing Azure CLI 2.0
  1. Once done, you can open cmd, and write az to access Azure CLI commands:
Figure 1.18: Opening the Azure CLI using CMD

Creating a virtual network using Azure CLI 2.0

To create a virtual network using Azure CLI 2.0, you have to follow these steps:

  1. Log in to your Azure account using the following command az login, you have to open the URL that pops up on the CLI, and then enter the following code:
Figure 1.19: Logging in to Azure via Azure CLI 2.0
  1. To create a new virtual network, you need to run the following command:
az network vnet create --name CLIVNet --resource-group PacktPub --location westeurope --address-prefix 192.168.0.0/16 --subnet-name s1 --subnet-prefix 192.168.1.0/24

Adding a gateway subnet to a virtual network using Azure CLI 2.0

To add a gateway subnet to a virtual network, you need to run the following command:

az network vnet subnet create --address-prefix 192.168.7.0/27 --name GatewaySubnet --resource-group PacktPub --vnet-name CLIVNet

Adding an address space to a virtual network using Azure CLI 2.0

To add an address space to a virtual network, you can run the following command:

az network vnet update address-prefixes –add <Add JSON String>

Remember that you will need to add a JSON string that describes the address space.

You have been reading a chapter from
Hands-On Networking with Azure
Published in: Mar 2018
Publisher:
ISBN-13: 9781788998222
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image