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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Azure Networking Cookbook

You're reading from   Azure Networking Cookbook Practical recipes to manage network traffic in Azure, optimize performance, and secure Azure resources

Arrow left icon
Product type Paperback
Published in Mar 2019
Publisher Packt
ISBN-13 9781789800227
Length 234 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Mustafa Toroman Mustafa Toroman
Author Profile Icon Mustafa Toroman
Mustafa Toroman
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Azure Virtual Network 2. Virtual Machine Networking FREE CHAPTER 3. Network Security Groups 4. Managing IP Addresses 5. Local and Virtual Network Gateways 6. Creating Hybrid Connections 7. DNS and Routing 8. Load Balancers 9. Traffic Manager 10. Azure Application Gateway 11. Azure Firewall 12. Other Books You May Enjoy

Adding a subnet with PowerShell

When creating Azure Virtual Network with PowerShell, a subnet is not created in the same step and requires an additional command to be executed separately.

Getting ready

Before creating a subnet, we need to collect information about the virtual network that the new subnet will be associated with. The parameters that need to be provided are the name of the virtual network and the resource group that the virtual network is located in:

$VirtualNetwork = Get-AzureRmVirtualNetwork -Name 'Packt-Script' -ResourceGroupName 'Packt-Networking-Script'

How to do it...

  1. To add a subnet to the virtual network, we need to execute a command and provide the name and address prefix. The address prefix is again in CIDR format:
Add-AzureRmVirtualNetworkSubnetConfig -Name FrontEnd -AddressPrefix 10.11.0.0/24 -VirtualNetwork $VirtualNetwork
  1. We need to confirm these changes by executing the following:
$VirtualNetwork | Set-AzureRmVirtualNetwork
  1. We can add an additional subnet by running all commands in a single step, as follows:
$VirtualNetwork = Get-AzureRmVirtualNetwork -Name 'Packt-Script' -ResourceGroupName 'Packt-Networking-Script'
Add-AzureRmVirtualNetworkSubnetConfig -Name BackEnd -AddressPrefix 10.11.1.0/24 -VirtualNetwork $VirtualNetwork
$VirtualNetwork | Set-AzureRmVirtualNetwork

How it works...

The subnet is created and added to the virtual network, but we need to confirm the changes before they can become effective. All the rules when creating or adding subnet size using the Azure portal apply here as well; the subnet must be within the virtual network's address space and cannot overlap with other subnets in the virtual network. The smallest subnet allowed is /29, and the largest is /8.

There's more...

We can create and add multiple subnets in a single script, as follows:

$VirtualNetwork = Get-AzureRmVirtualNetwork -Name 'Packt-Script' -ResourceGroupName 'Packt-Networking-Script'
$FrontEnd = Add-AzureRmVirtualNetworkSubnetConfig -Name FrontEnd -AddressPrefix 10.11.0.0/24 -VirtualNetwork $VirtualNetwork
$BackEnd = Add-AzureRmVirtualNetworkSubnetConfig -Name BackEnd -AddressPrefix 10.11.1.0/24 -VirtualNetwork $VirtualNetwork
$VirtualNetwork | Set-AzureRmVirtualNetwork
lock icon The rest of the chapter is locked
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