Virtual Network Azure
Virtual Network Azure
Virtual Network Azure
Overview
Virtual networks
User-defined routes and IP forwarding
Virtual network peering
Business continuity
FAQ
IP addressing
Classic
IP addressing
Access control lists
Get Started
Create your first virtual network
How To
Plan and design
Virtual networks
Network security groups
Deploy
Virtual networks
Network security groups
User-defined routes
Virtual network peering
Virtual machines
Connectivity scenarios
Security scenarios
Classic
Configure
Virtual machines
Classic
Manage
Virtual networks
Network security groups
Network interfaces (NICs)
Virtual machines
Public IP addresses
Troubleshoot
Network security groups
Routes
Throughput testing
Cannot delete virtual networks
VM to VM connectivity problems
Reference
Code samples
PowerShell (Resource Manager)
PowerShell (Classic)
Azure CLI
Java
REST (Resource Manager)
REST (Classic)
Related
Virtual Machines
Application Gateway
Azure DNS
Traffic Manager
Load Balancer
VPN Gateway
ExpressRoute
Resources
Azure roadmap
Networking blog
Networking forum
Pricing
Pricing calculator
Stack Overflow
Azure Virtual Network
7/25/2017 6 min to read Edit Online
The Azure Virtual Network service enables you to securely connect Azure resources to each other with virtual
networks (VNets). A VNet is a representation of your own network in the cloud. A VNet is a logical isolation of the
Azure cloud dedicated to your subscription. You can also connect VNets to your on-premises network. The
following picture shows some of the capabilities of the Azure Virtual Network service:
To learn more about the following Azure Virtual Network capabilities, click the capability:
Isolation: VNets are isolated from one another. You can create separate VNets for development, testing, and
production that use the same CIDR address blocks. Conversely, you can create multiple VNets that use
different CIDR address blocks and connect networks together. You can segment a VNet into multiple subnets.
Azure provides internal name resolution for VMs and Cloud Services role instances connected to a VNet. You
can optionally configure a VNet to use your own DNS servers, instead of using Azure internal name
resolution.
Internet connectivity: All Azure Virtual Machines (VM) and Cloud Services role instances connected to a
VNet have access to the Internet, by default. You can also enable inbound access to specific resources, as
needed.
Azure resource connectivity: Azure resources such as Cloud Services and VMs can be connected to the
same VNet. The resources can connect to each other using private IP addresses, even if they are in different
subnets. Azure provides default routing between subnets, VNets, and on-premises networks, so you don't
have to configure and manage routes.
VNet connectivity: VNets can be connected to each other, enabling resources connected to any VNet to
communicate with any resource on any other VNet.
On-premises connectivity: VNets can be connected to on-premises networks through private network
connections between your network and Azure, or through a site-to-site VPN connection over the Internet.
Traffic filtering: VM and Cloud Services role instances network traffic can be filtered inbound and outbound
by source IP address and port, destination IP address and port, and protocol.
Routing: You can optionally override Azure's default routing by configuring your own routes, or using BGP
routes through a network gateway.
Pricing
There is no charge for virtual networks, subnets, route tables, or network security groups. Outbound Internet
bandwidth usage, public IP addresses, virtual network peering, VPN Gateways, and ExpressRoute each have their
own pricing structures. View the Virtual network, VPN Gateway, and ExpressRoute pricing pages for more
information.
FAQ
To review frequently asked questions about Virtual Network, see the Virtual Network FAQ article.
Next steps
Create your first VNet, and connect a few VMs to it, by completing the steps in the Create your first virtual
network article.
Create a point-to-site connection to a VNet by completing the steps in the Configure a point-to-site
connection article.
Learn about some of the other key network capabilities of Azure.
User-defined routes and IP forwarding
6/27/2017 7 min to read Edit Online
When you add virtual machines (VMs) to a virtual network (VNet) in Azure, you will notice that the VMs are able
to communicate with each other over the network, automatically. You do not need to specify a gateway, even
though the VMs are in different subnets. The same is true for communication from the VMs to the public Internet,
and even to your on-premises network when a hybrid connection from Azure to your own datacenter is present.
This flow of communication is possible because Azure uses a series of system routes to define how IP traffic flows.
System routes control the flow of communication in the following scenarios:
From within the same subnet.
From a subnet to another within a VNet.
From VMs to the Internet.
From a VNet to another VNet through a VPN gateway.
From a VNet to another VNet through VNet Peering (Service Chaining).
From a VNet to your on-premises network through a VPN gateway.
The figure below shows a simple setup with a VNet, two subnets, and a few VMs, along with the system routes
that allow IP traffic to flow.
Although the use of system routes facilitates traffic automatically for your deployment, there are cases in which
you want to control the routing of packets through a virtual appliance. You can do so by creating user defined
routes that specify the next hop for packets flowing to a specific subnet to go to your virtual appliance instead, and
enabling IP forwarding for the VM running as the virtual appliance.
The figure below shows an example of user defined routes and IP forwarding to force packets sent to one subnet
from another to go through a virtual appliance on a third subnet.
IMPORTANT
User-defined routes are applied to traffic leaving a subnet from any resource (such as network interfaces attached to VMs)
in the subnet. You cannot create routes to specify how traffic enters a subnet from the Internet, for instance. The appliance
you are forwarding traffic to cannot be in the same subnet where the traffic originates. Always create a separate subnet for
your appliances.
Route resource
Packets are routed over a TCP/IP network based on a route table defined at each node on the physical network. A
route table is a collection of individual routes used to decide where to forward packets based on the destination IP
address. A route consists of the following:
Address Prefix The destination CIDR to Must be a valid CIDR range Make sure the Address
which the route applies, representing addresses on prefix does not contain the
such as 10.1.0.0/16. the public Internet, Azure address for the Next hop
virtual network, or on- address, otherwise your
premises datacenter. packets will enter in a loop
going from the source to
the next hop without ever
reaching the destination.
Next hop type The type of Azure hop the Must be one of the Consider using Virtual
packet should be sent to. following values: Appliance to direct traffic
Virtual Network. to a VM or Azure Load
Represents the local virtual Balancer internal IP address.
network. For instance, if you This type allows the
have two subnets, specification of an IP address
10.1.0.0/16 and 10.2.0.0/16 as described below. Consider
in the same virtual network, using a None type to stop
the route for each subnet in packets from flowing to a
the route table will have a given destination.
next hop value of Virtual
Network.
Virtual Network Gateway.
Represents an Azure S2S
VPN Gateway.
Internet. Represents the
default Internet gateway
provided by the Azure
Infrastructure.
Virtual Appliance.
Represents a virtual
appliance you added to your
Azure virtual network.
None. Represents a black
hole. Packets forwarded to a
black hole will not be
forwarded at all.
PROPERTY DESCRIPTION CONSTRAINTS CONSIDERATIONS
Next hop address The next hop address Must be an IP address that If the IP address represents
contains the IP address is reachable within the a VM, make sure you enable
packets should be Virtual Network where the IP forwarding in Azure for
forwarded to. Next hop User Defined Route is the VM. If the IP address
values are only allowed in applied, without going represents the internal IP
routes where the next hop through a Virtual Network address of Azure Load
type is Virtual Appliance. Gateway. The IP address Balancer, make sure you
has to be on the same have a matching load
Virtual Network where it is balancing rule for each port
applied, or on a peered you wish to load balance.
Virtual Network.
BGP routes
If you have an ExpressRoute connection between your on-premises network and Azure, you can enable BGP to
propagate routes from your on-premises network to Azure. These BGP routes are used in the same way as system
routes and user defined routes in each Azure subnet. For more information see ExpressRoute Introduction.
IMPORTANT
You can configure your Azure environment to use force tunneling through your on-premises network by creating a user
defined route for subnet 0.0.0.0/0 that uses the VPN gateway as the next hop. However, this only works if you are using a
VPN gateway, not ExpressRoute. For ExpressRoute, forced tunneling is configured through BGP.
IP forwarding
As described above, one of the main reasons to create a user defined route is to forward traffic to a virtual
appliance. A virtual appliance is nothing more than a VM that runs an application used to handle network traffic in
some way, such as a firewall or a NAT device.
This virtual appliance VM must be able to receive incoming traffic that is not addressed to itself. To allow a VM to
receive traffic addressed to other destinations, you must enable IP Forwarding for the VM. This is an Azure setting,
not a setting in the guest operating system.
Next steps
Learn how to create routes in the Resource Manager deployment model and associate them to subnets.
Learn how to create routes in the classic deployment model and associate them to subnets.
Virtual network peering
7/19/2017 6 min to read Edit Online
Virtual network peering enables you to connect two virtual networks in the same region through the Azure
backbone network. Once peered, the two virtual networks appear as one, for connectivity purposes. The two
virtual networks are still managed as separate resources, but virtual machines in the peered virtual networks can
communicate with each other directly, by using private IP addresses.
The traffic between virtual machines in the peered virtual networks is routed through the Azure infrastructure,
much like traffic is routed between virtual machines in the same virtual network. Some of the benefits of using
virtual network peering include:
A low-latency, high-bandwidth connection between resources in different virtual networks.
The ability to use resources such as network appliances and VPN gateways as transit points in a peered virtual
network.
The ability to peer two virtual networks created through the Azure Resource Manager deployment model or to
peer one virtual network created through Resource Manager to a virtual network created through the classic
deployment model. Read the Understand Azure deployment models article to learn more about the differences
between the two Azure deployment models.
Service chaining
You can configure user-defined routes that point to virtual machines in peered virtual networks as the "next hop"
IP address to enable service chaining. Service chaining enables you to direct traffic from one virtual network to a
virtual appliance in a peered virtual network through user-defined routes.
You can also effectively build hub-and-spoke type environments, where the hub can host infrastructure
components such as a network virtual appliance. All the spoke virtual networks can then peer with the hub virtual
network. Traffic can flow through network virtual appliances that are running in the hub virtual network. In short,
virtual network peering enables the next hop IP address on the user-defined route to be the IP address of a virtual
machine in the peered virtual network. To learn more about user-defined routes, read the user-defined routes
overview article.
Gateway transit is not supported in the peering relationship between virtual networks created through different
deployment models. Both virtual networks in the peering relationship must have been created through Resource
Manager for a gateway transit to work.
When the virtual networks that are sharing a single Azure ExpressRoute connection are peered, the traffic
between them goes through the peering relationship (that is, through the Azure backbone network). You can still
use local gateways in each virtual network to connect to the on-premises circuit. Alternatively, you can use a
shared gateway and configure transit for on-premises connectivity.
Provisioning
Virtual network peering is a privileged operation. Its a separate function under the VirtualNetworks namespace. A
user can be given specific rights to authorize peering. A user who has read-write access to the virtual network
inherits these rights automatically.
A user who is either an admin or a privileged user of the peering ability can initiate a peering operation on
another virtual network. If there is a matching request for peering on the other side, and if other requirements are
met, the peering is established.
Limits
There are limits on the number of peerings that are allowed for a single virtual network. For more information,
review the Azure networking limits.
Pricing
There is a nominal charge for ingress and egress traffic that utilizes a virtual network peering. For more
information, see the pricing page.
Next steps
Complete a virtual network peering tutorial. A virtual network peering is created between virtual networks
created through the same, or different deployment models that exist in the same, or different subscriptions.
Complete a tutorial for one of the following scenarios:
Different
Different
Overview
A Virtual Network (VNet) is a logical representation of your network in the cloud. It allows you to define your own
private IP address space and segment the network into subnets. VNets serves as a trust boundary to host your
compute resources such as Azure Virtual Machines and Cloud Services (web/worker roles). A VNet allows direct
private IP communication between the resources hosted in it. A Virtual Network can also be linked to an on-
premises network through one of the hybrid options such as a VPN Gateway or ExpressRoute.
A VNet is created within the scope of a region. You can create VNets with same address space in two different
regions (i.e. US East and US West but cannot connect them to one another directly).
Business Continuity
There could be several different ways that your application could be disrupted. A given region could be completely
cut off due to a natural disaster or a partial disaster due to a failure of multiple devices/services. The impact on the
VNet service is different in each of these situations.
Q: What do you do in the event of an outage to an entire region? i.e. if a region is completely cutoff due
to a natural disaster? What happens to the Virtual Networks hosted in the region?
A: The Virtual Network and the resources in the affected region remains inaccessible during the time of the service
disruption.
Configuration
What tools do I use to create a VNet?
You can use the following tools to create or configure a VNet:
Azure Portal (for classic and Resource Manager VNets).
A network configuration file (netcfg - for classic VNets only). See the Configure a VNet using a network
configuration file article.
PowerShell (for classic and Resource Manager VNets).
Azure CLI (for classic and Resource Manager VNets).
What address ranges can I use in my VNets?
Any IP address range defined in RFC 1918. For example, 10.0.0.0/16.
Can I have public IP addresses in my VNets?
Yes. For more information about public IP address ranges, see the Public IP address space in a virtual network
article. Your public IP addresses will not be directly accessible from the Internet.
Is there a limit to the number of subnets in my VNet?
Yes. Read the Azure limits article for details. Subnet address spaces cannot overlap one another.
Are there any restrictions on using IP addresses within these subnets?
Yes. Azure reserves some IP addresses within each subnet. The first and last IP addresses of the subnets are
reserved for protocol conformance, along with 3 more addresses used for Azure services.
How small and how large can VNets and subnets be?
The smallest subnet we support is a /29 and the largest is a /8 (using CIDR subnet definitions).
Can I bring my VLANs to Azure using VNets?
No. VNets are Layer-3 overlays. Azure does not support any Layer-2 semantics.
Can I specify custom routing policies on my VNets and subnets?
Yes. You can use User Defined Routing (UDR). For more information about UDR, visit User Defined Routes and IP
Forwarding.
Do VNets support multicast or broadcast?
No. We do not support multicast or broadcast.
What protocols can I use within VNets?
You can use TCP, UDP, and ICMP TCP/IP protocols within VNets. Multicast, broadcast, IP-in-IP encapsulated
packets, and Generic Routing Encapsulation (GRE) packets are blocked within VNets.
Can I ping my default routers within a VNet?
No.
Can I use tracert to diagnose connectivity?
No.
Can I add subnets after the VNet is created?
Yes. Subnets can be added to VNets at any time as long as the subnet address is not part of another subnet in the
VNet.
Can I modify the size of my subnet after I create it?
Yes. You can add, remove, expand, or shrink a subnet if there are no VMs or services deployed within it.
Can I modify subnets after I created them?
Yes. You can add, remove, and modify the CIDR blocks used by a VNet.
Can I connect to the internet if I am running my services in a VNet?
Yes. All services deployed within a VNet can connect to the internet. Every cloud service deployed in Azure has a
publicly addressable VIP assigned to it. You will have to define input endpoints for PaaS roles and endpoints for
virtual machines to enable these services to accept connections from the internet.
Do VNets support IPv6?
No. You cannot use IPv6 with VNets at this time.
Can a VNet span regions?
No. A VNet is limited to a single region.
Can I connect a VNet to another VNet in Azure?
Yes. You can connect one VNet to another VNet using:
An Azure VPN Gateway. Read the Configure a VNet-to-VNet connection article for details.
VNet peering. Read the VNet peering overview article for details.
NOTE
There is a limitation at this time to the first 100 cloud services in a VNet for cross-tenant name resolution using Azure-
provided DNS. If you are using your own DNS server, this limitation does not apply.
Security
What is the security model for VNets?
VNets are completely isolated from one another, and other services hosted in the Azure infrastructure. A VNet is a
trust boundary.
Can I restrict inbound or outbound traffic flow to VNet-connected resources?
Yes. You can apply Network Security Groups to individual subnets within a VNet, NICs attached to a VNet, or both.
Can I implement a firewall between VNet-connected resources?
Yes. You can deploy a firewall network virtual appliance from several vendors through the Azure Marketplace.
Is there information available about securing VNets?
Yes. See the Azure Network Security Overview article for details.
You can assign IP addresses to Azure resources to communicate with other Azure resources, your on-premises
network, and the Internet. There are two types of IP addresses you can use in Azure:
Public IP addresses: Used for communication with the Internet, including Azure public-facing services
Private IP addresses: Used for communication within an Azure virtual network (VNet), and your on-premises
network when you use a VPN gateway or ExpressRoute circuit to extend your network to Azure.
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the Resource Manager deployment model, which Microsoft recommends for most new deployments
instead of the classic deployment model.
If you are familiar with the classic deployment model, check the differences in IP addressing between classic and
Resource Manager.
Public IP addresses
Public IP addresses allow Azure resources to communicate with Internet and Azure public-facing services such as
Azure Redis Cache, Azure Event Hubs, SQL databases, and Azure storage.
In Azure Resource Manager, a public IP address is a resource that has its own properties. You can associate a
public IP address resource with any of the following resources:
Virtual machines (VM)
Internet-facing load balancers
VPN gateways
Application gateways
Allocation method
There are two methods in which an IP address is allocated to a public IP resource - dynamic or static. The default
allocation method is dynamic, where an IP address is not allocated at the time of its creation. Instead, the public IP
address is allocated when you start (or create) the associated resource (like a VM or load balancer). The IP address
is released when you stop (or delete) the resource. This causes the IP address to change when you stop and start a
resource.
To ensure the IP address for the associated resource remains the same, you can set the allocation method
explicitly to static. In this case an IP address is assigned immediately. It is released only when you delete the
resource or change its allocation method to dynamic.
NOTE
Even when you set the allocation method to static, you cannot specify the actual IP address assigned to the public IP
resource. Instead, it gets allocated from a pool of available IP addresses in the Azure location the resource is created in.
NOTE
The list of IP ranges from which public IP addresses (dynamic/static) are allocated to Azure resources is published at Azure
Datacenter IP ranges.
IMPORTANT
Each domain name label created must be unique within its Azure location.
Virtual machines
You can associate a public IP address with a Windows or Linux VM by assigning it to its network interface. In the
case of a VM with multiple network interfaces, you can assign it to the primary network interface only. You can
assign either a dynamic or a static public IP address to a VM.
Internet-facing load balancers
You can associate a public IP address with an Azure Load Balancer, by assigning it to the load balancer frontend
configuration. This public IP address serves as a load-balanced virtual IP address (VIP). You can assign either a
dynamic or a static public IP address to a load balancer front-end. You can also assign multiple public IP addresses
to a load balancer front-end, which enables multi-VIP scenarios like a multi-tenant environment with SSL-based
websites.
VPN gateways
Azure VPN Gateway is used to connect an Azure virtual network (VNet) to other Azure VNets or to an on-premises
network. You need to assign a public IP address to its IP configuration to enable it to communicate with the
remote network. Currently, you can only assign a dynamic public IP address to a VPN gateway.
Application gateways
You can associate a public IP address with an Azure Application Gateway, by assigning it to the gateway's
frontend configuration. This public IP address serves as a load-balanced VIP. Currently, you can only assign a
dynamic public IP address to an application gateway frontend configuration.
At-a-glance
The table below shows the specific property through which a public IP address can be associated to a top-level
resource, and the possible allocation methods (dynamic or static) that can be used.
Private IP addresses
Private IP addresses allow Azure resources to communicate with other resources in a virtual network or an on-
premises network through a VPN gateway or ExpressRoute circuit, without using an Internet-reachable IP address.
In the Azure Resource Manager deployment model, a private IP address is associated to the following types of
Azure resources:
VMs
Internal load balancers (ILBs)
Application gateways
Allocation method
A private IP address is allocated from the address range of the subnet to which the resource is attached. The
address range of the subnet itself is a part of the VNet's address range.
There are two methods in which a private IP address is allocated: dynamic or static. The default allocation method
is dynamic, where the IP address is automatically allocated from the resource's subnet (using DHCP). This IP
address can change when you stop and start the resource.
You can set the allocation method to static to ensure the IP address remains the same. In this case, you also need
to provide a valid IP address that is part of the resource's subnet.
Static private IP addresses are commonly used for:
VMs that act as domain controllers or DNS servers.
Resources that require firewall rules using IP addresses.
Resources accessed by other apps/resources through an IP address.
Virtual machines
A private IP address is assigned to the network interface of a Windows or Linux VM. In case of a multi-network
interface VM, each interface gets a private IP address assigned. You can specify the allocation method as either
dynamic or static for a network interface.
Internal DNS hostname resolution (for VMs )
All Azure VMs are configured with Azure-managed DNS servers by default, unless you explicitly configure custom
DNS servers. These DNS servers provide internal name resolution for VMs that reside within the same VNet.
When you create a VM, a mapping for the hostname to its private IP address is added to the Azure-managed DNS
servers. In case of a multi-network interface VM, the hostname is mapped to the private IP address of the primary
network interface.
VMs configured with Azure-managed DNS servers will be able to resolve the hostnames of all VMs within their
VNet to their private IP addresses.
Internal load balancers (ILB ) & Application gateways
You can assign a private IP address to the front end configuration of an Azure Internal Load Balancer (ILB) or an
Azure Application Gateway. This private IP address serves as an internal endpoint, accessible only to the resources
within its virtual network (VNet) and the remote networks connected to the VNet. You can assign either a dynamic
or static private IP address to the front end configuration.
At-a-glance
The table below shows the specific property through which a private IP address can be associated to a top-level
resource, and the possible allocation methods (dynamic or static) that can be used.
Limits
The limits imposed on IP addressing are indicated in the full set of limits for networking in Azure. These limits are
per region and per subscription. You can contact support to increase the default limits up to the maximum limits
based on your business needs.
Pricing
Public IP addresses may have a nominal charge. To learn more about IP address pricing in Azure, review the IP
address pricing page.
Next steps
Deploy a VM with a static public IP using the Azure portal
Deploy a VM with a static public IP using a template
Deploy a VM with a static private IP address using the Azure portal
IP address types and allocation methods (classic) in
Azure
8/21/2017 9 min to read Edit Online
You can assign IP addresses to Azure resources to communicate with other Azure resources, your on-premises
network, and the Internet. There are two types of IP addresses you can use in Azure: public and private.
Public IP addresses are used for communication with the Internet, including Azure public-facing services.
Private IP addresses are used for communication within an Azure virtual network (VNet), a cloud service, and your
on-premises network when you use a VPN gateway or ExpressRoute circuit to extend your network to Azure.
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends that most new deployments use Resource
Manager. Learn about IP addresses in Resource Manager by reading the IP addresses article.
Public IP addresses
Public IP addresses allow Azure resources to communicate with Internet and Azure public-facing services such as
Azure Redis Cache, Azure Event Hubs, SQL databases, and Azure storage.
A public IP address is associated with the following resource types:
Cloud services
IaaS Virtual Machines (VMs)
PaaS role instances
VPN gateways
Application gateways
Allocation method
When a public IP address needs to be assigned to an Azure resource, it is dynamically allocated from a pool of
available public IP address within the location the resource is created. This IP address is released when the resource
is stopped. In case of a cloud service, this happens when all the role instances are stopped, which can be avoided by
using a static (reserved) IP address (see Cloud Services).
NOTE
The list of IP ranges from which public IP addresses are allocated to Azure resources is published at Azure Datacenter IP
ranges.
NOTE
When you create a classic VM, a container cloud service is created by Azure, which has a virtual IP address (VIP). When the
creation is done through portal, a default RDP or SSH endpoint is configured by the portal so you can connect to the VM
through the cloud service VIP. This cloud service VIP can be reserved, which effectively provides a reserved IP address to
connect to the VM. You can open additional ports by configuring more endpoints.
NOTE
This is different from the VIP of the cloud service, which is a container for IaaS VMs or PaaS role instances, since a cloud
service can contain multiple IaaS VMs, or PaaS role instances, all exposed through the same cloud service VIP.
VPN gateways
A VPN gateway can be used to connect an Azure VNet to other Azure VNets or on-premises networks. A VPN
gateway is assigned a public IP address dynamically, which enables communication with the remote network.
Application gateways
An Azure Application gateway can be used for Layer7 load-balancing to route network traffic based on HTTP.
Application gateway is assigned a public IP address dynamically, which serves as the load-balanced VIP.
At a glance
The table below shows each resource type with the possible allocation methods (dynamic/static), and ability to
assign multiple public IP addresses.
Private IP addresses
Private IP addresses allow Azure resources to communicate with other resources in a cloud service or a virtual
network(VNet), or to on-premises network (through a VPN gateway or ExpressRoute circuit), without using an
Internet-reachable IP address.
In Azure classic deployment model, a private IP address can be assigned to the following Azure resources:
IaaS VMs and PaaS role instances
Internal load balancer
Application gateway
IaaS VMs and PaaS role instances
Virtual machines (VMs) created with the classic deployment model are always placed in a cloud service, similar to
PaaS role instances. The behavior of private IP addresses are thus similar for these resources.
It is important to note that a cloud service can be deployed in two ways:
As a standalone cloud service, where it is not within a virtual network.
As part of a virtual network.
Allocation method
In case of a standalone cloud service, resources get a private IP address allocated dynamically from the Azure
datacenter private IP address range. It can be used only for communication with other VMs within the same cloud
service. This IP address can change when the resource is stopped and started.
In case of a cloud service deployed within a virtual network, resources get private IP address(es) allocated from the
address range of the associated subnet(s) (as specified in its network configuration). This private IP address(es) can
be used for communication between all VMs within the VNet.
Additionally, in case of cloud services within a VNet, a private IP address is allocated dynamically (using DHCP) by
default. It can change when the resource is stopped and started. To ensure the IP address remains the same, you
need to set the allocation method to static, and provide a valid IP address within the corresponding address range.
Static private IP addresses are commonly used for:
VMs that act as domain controllers or DNS servers.
VMs that require firewall rules using IP addresses.
VMs running services accessed by other apps through an IP address.
Internal DNS hostname resolution
All Azure VMs and PaaS role instances are configured with Azure-managed DNS servers by default, unless you
explicitly configure custom DNS servers. These DNS servers provide internal name resolution for VMs and role
instances that reside within the same VNet or cloud service.
When you create a VM, a mapping for the hostname to its private IP address is added to the Azure-managed DNS
servers. In case of a multi-NIC VM, the hostname is mapped to the private IP address of the primary NIC. However,
this mapping information is restricted to resources within the same cloud service or VNet.
In case of a standalone cloud service, you will be able to resolve hostnames of all VMs/role instances within the
same cloud service only. In case of a cloud service within a VNet, you will be able to resolve hostnames of all the
VMs/role instances within the VNet.
Internal load balancers (ILB ) & Application gateways
You can assign a private IP address to the front end configuration of an Azure Internal Load Balancer (ILB) or an
Azure Application Gateway. This private IP address serves as an internal endpoint, accessible only to the resources
within its virtual network (VNet) and the remote networks connected to the VNet. You can assign either a dynamic
or static private IP address to the front end configuration. You can also assign multiple private IP addresses to
enable multi-vip scenarios.
At a glance
The table below shows each resource type with the possible allocation methods (dynamic/static), and ability to
assign multiple private IP addresses.
Limits
The table below shows the limits imposed on IP addressing in Azure per subscription. You can contact support to
increase the default limits up to the maximum limits based on your business needs.
Make sure you read the full set of limits for Networking in Azure.
Pricing
In most cases, public IP addresses are free. There is a nominal charge to use additional and/or static public IP
addresses. Make sure you understand the pricing structure for public IPs.
Internal load balancer (ILB) Assigned to the ILB Assigned to the ILB's front
(dynamic or static) end configuration (dynamic
or static)
Next steps
Deploy a VM with a static private IP address using the Azure portal.
What is an endpoint access control list?
7/5/2017 5 min to read Edit Online
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager deployment model.
An endpoint access control list (ACL) is a security enhancement available for your Azure deployment. An ACL
provides the ability to selectively permit or deny traffic for a virtual machine endpoint. This packet filtering
capability provides an additional layer of security. You can specify network ACLs for endpoints only. You can't
specify an ACL for a virtual network or a specific subnet contained in a virtual network. It is recommended to use
network security groups (NSGs) instead of ACLs, whenever possible. To learn more about NSGs, see Network
security group overview
ACLs can be configured by using either PowerShell or the Azure portal. To configure a network ACL by using
PowerShell, see Managing access control lists for endpoints using PowerShell. To configure a network ACL by
using the Azure portal, see How to set up endpoints to a virtual machine.
Using Network ACLs, you can do the following:
Selectively permit or deny incoming traffic based on remote subnet IPv4 address range to a virtual machine
input endpoint.
Blacklist IP addresses
Create multiple rules per virtual machine endpoint
Use rule ordering to ensure the correct set of rules are applied on a given virtual machine endpoint (lowest to
highest)
Specify an ACL for a specific remote subnet IPv4 address.
See the Azure limits article for ACL limits.
Rule order
Because multiple rules can be specified for an endpoint, there must be a way to organize rules in order to
determine which rule takes precedence. The rule order specifies precedence. Network ACLs follow a lowest takes
precedence rule order. In the example below, the endpoint on port 80 is selectively granted access to only certain IP
address ranges. To configure this, we have a deny rule (Rule # 100) for addresses in the 175.1.0.1/24 space. A
second rule is then specified with precedence 200 that permits access to all other addresses under 175.0.0.0/8.
Example Rule precedence
Next Steps
Manage access control lists for endpoints using PowerShell
Create your first virtual network
8/21/2017 17 min to read Edit Online
Learn how to create a virtual network (VNet) with two subnets, create two virtual machines (VM), and connect each
VM to one of the subnets, as shown in the following picture:
An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure
network settings and define DHCP address blocks, DNS settings, security policies, and routing. To learn more about
VNet concepts, read the Virtual Network overview article. Complete the following steps to create the resources
shown in the picture:
1. Create a VNet with two subnets
2. Create two VMs, each with one network interface (NIC), and associate a network security group (NSG) to each
NIC
3. Connect to and from the VMs
4. Delete all resources. You incur charges for some of the resources created in this exercise while they're
provisioned. To minimize the charges, after you complete the exercise, be sure to complete the steps in this
section to delete the resources you create.
You will have a basic understanding of how you can use a VNet after completing the steps in this article. Next steps
are provided so you can learn more about how to use VNets at a deeper level.
Subnet address range 10.0.0.0/24 The range you specify must exist
within the address space you defined
for the virtual network.
The VNet takes a few seconds to create. Once its created, you see the Azure portal dashboard.
6. With the virtual network created, in the Azure portal Favorites pane, click All resources. Click the MyVNet
virtual network in the All resources blade. If the subscription you selected already has several resources in
it, you can enter MyVNet in the Filter by name box to easily access the VNet.
7. The MyVNet blade opens and displays information about the VNet, as shown in the following picture:
8. As shown in the previous picture, click Subnets to display a list of the subnets within the VNet. The only
subnet that exists is Front-end, the subnet you created in step 5.
9. In the MyVNet - Subnets blade, click + Subnet to create a subnet with the following information and click
OK to create the subnet:
Network security group and Route None (default) Network security groups (NSG)s are
table covered later in this article. To learn
more about user-defined routes,
read the User-defined routes article.
10. After the new subnet is added to the VNet, you can close the MyVNet Subnets blade, then close the All
resources blade.
Resource group Use existing: Select MyRG Though were using the same
resource group as we did for the
VNet, the resources dont have to
exist in the same resource group.
4. In the Choose a size blade, click DS1_V2 Standard, then click Select. Read the Windows VM sizes article for
a list of all Windows VM sizes supported by Azure.
5. In the Settings blade, enter or select the following values and click OK:
Virtual network Select MyVNet You can select any VNet that exists in
the same location as the VM youre
creating. To learn more about VNets
and subnets, read the Virtual
network article.
Subnet Select Front-end You can select any subnet that exists
within the VNet.
Network security group (firewall) Accept the default Click the (new) MyWebServer-nsg
default NSG the portal created to
view its settings. In the Create
network security group blade that
opens, notice that it has one inbound
rule that allows TCP/3389 (RDP)
traffic from any source IP address.
All other values Accept the defaults To learn more about the remaining
settings, read the About VMs article.
Network security groups (NSG) enable you to create inbound/outbound rules for the type of network traffic
that can flow to and from the VM. By default, all inbound traffic to the VM is denied. You might add
additional inbound rules for TCP/80 (HTTP) and TCP/443 (HTTPS) for a production web server. There is no
rule for outbound traffic because by default, all outbound traffic is allowed. You can add/remove rules to
control traffic per your policies. Read the Network security groups article to learn more about NSGs.
6. In the Summary blade, review the settings and click OK to create the VM. A status tile is displayed on the
portal dashboard as the VM creates. It may take a few minutes to create. You dont need to wait for it to
complete. You can continue to the next step while the VM is created.
Create the database server VM
To create the database server VM, complete the following steps:
1. In the Favorites pane, click New, Compute, then Windows Server 2016 Datacenter.
2. In the Windows Server 2016 Datacenter blade, click Create.
3. In the Basics blade, enter or select the following values, then click OK:
Resource group Use existing: Select MyRG Though were using the same
resource group as we did for the
VNet, the resources dont have to
exist in the same resource group.
Virtual network Select MyVNet You can select any VNet that exists in
the same location as the VM youre
creating.
Subnet Select Back-end by clicking the You can select any subnet that exists
Subnet box, then selecting Back- within the VNet.
end from the Choose a subnet
blade
Public IP address None Click the default address, Without a public IP address, you can
then click None from the Choose only connect to the VM from
public IP address blade another VM connected to the same
VNet. You cannot connect to it
directly from the Internet.
Network security group (firewall) Accept the default Like the default NSG created for the
MyWebServer VM, this NSG also has
the same default inbound rule. You
might add an additional inbound rule
for TCP/1433 (MS SQL) for a
database server. There is no rule for
outbound traffic because by default,
all outbound traffic is allowed. You
can add/remove rules to control
traffic per your policies.
6. In the Summary blade, review the settings and click OK to create the VM. A status tile is displayed on the
portal dashboard as the VM creates. It may take a few minutes to create. You dont need to wait for it to
complete. You can continue to the next step while the VM is created.
Review resources
Though you created one VNet and two VMs, the Azure portal created several additional resources for you in the
MyRG resource group. Review the contents of the MyRG resource group by completing the following steps:
1. In the Favorites pane, click More services.
2. In the More services pane, type Resource groups in the box that has the word Filter in it. Click Resource
groups when you see it in the filtered list.
3. In the Resource groups pane, click the MyRG resource group. If you have many existing resource groups in
your subscription, you can type MyRG in the box that contains the text Filter by name to quickly access the
MyRG resource group.
4. In the MyRG blade, you see that the resource group contains 12 resources, as shown in the following
picture:
To learn more about VMs, disks, and storage accounts, read the Virtual machine, Disk, and Storage account
overview articles. You can see the two default NSGs the portal created for you. You can also see that the portal
created two network interface (NIC) resources. A NIC enables a VM to connect to other resources over the VNet.
Read the NIC article to learn more about NICs. The portal also created one Public IP address resource. Public IP
addresses are one setting for a public IP address resource. To learn more about public IP addresses, read the IP
addresses article.
4. Allow your browser to download the MyWebServer.rdp file, then open it.
5. If you receive a dialog box informing you that the publisher of the remote connection cannot be verified, click
Connect.
6. When entering your credentials, ensure you login with the user name and password you specified in step 3 of
the Create the web server VM section of this article. If the Windows Security box that appears doesnt list the
correct credentials, you may need to click More choices, then Use a different account, so you can specify the
correct user name and password). Click OK to connect to the VM.
7. If you receive a Remote Desktop Connection box informing you that the identity of the remote computer
cannot be verified, click Yes.
8. You are now connected to the MyWebServer VM from the Internet. Leave the remote desktop connection open
to complete the steps in the next section.
The remote connection is to the public IP address assigned to the public IP address resource the portal created in
step 5 of the Create a virtual network with two subnets section of this article. The connection is allowed because
the default rule created in the MyWebServer-nsg NSG permitted TCP/3389 (RDP) inbound to the VM from any
source IP address. If you try to connect to the VM over any other port, the connection fails, unless you add
additional inbound rules to the NSG allowing the additional ports.
NOTE
If you add additional inbound rules to the NSG, ensure that the same ports are open on the Windows firewall, or the
connection fails.
5. Leave the remote desktop connection open to complete the steps in the next section.
You are able to connect to the Internet from the VM because all outbound connectivity from the VM is allowed by
default. You can limit outbound connectivity by adding addition rules to the NSG applied to the NIC, to the subnet
the NIC is connected to, or both.
If the VM is put in the stopped (deallocated) state using the portal, the public IP address can change. If you require
that the public IP address never change, you can use the static allocation method for the IP address, rather than the
dynamic allocation method (which is the default). To learn more about the differences between allocation methods,
read the IP address types and allocation methods article.
Connect to the database server VM from the web server VM
To connect to the database server VM from the web server VM, complete the following steps:
1. If you dont already have a remote connection to the MyWebServer VM open, make a remote connection to the
VM by completing the steps in the Connect to the web server VM from the Internet section of this article.
2. Click the Start button in the lower-left corner of the Windows desktop, then start typing remote desktop. When
the Start menu list displays Remote Desktop Connection, click it.
3. In the Remote Desktop Connection dialog box, enter MyDBServer for the computer name and click Connect.
4. Enter the user name and passwords you entered in step 3 of the Create the database server VM section of this
article, then click OK.
5. If you receive a dialog box informing you that the identity of the remote computer cannot be verified, click Yes.
6. Leave the remote desktop connection to both servers open to complete the steps in the next section.
You are able to make the connection to the database server VM from the web server VM for the following reasons:
TCP/3389 inbound connections are enabled for any source IP in the default NSG created in step 5 of the Create
the database server VM section of this article.
You initiated the connection from the web server VM, which is connected to the same VNet as the database
server VM. To connect to a VM that doesnt have a public IP address assigned to it, you must connect from
another VM connected to the same VNet, even if the VM is connected to a different subnet.
Even though the VMs are connected to different subnets, Azure creates default routes that enable connectivity
between subnets. You can override the default routes by creating your own however. Read the User-defined
routes article to learn more about routing in Azure.
If you try to initiate a remote connection to the database server VM from the Internet, as you did in the Connect to
the web server VM from the Internet section of this article, you see that the Connect option is grayed out. Connect
is grayed out because there is no public IP address assigned to the VM, so inbound connections to it from the
Internet are not possible.
Connect to the Internet from the database server VM
Connect outbound to the Internet from the database server VM by completing the following steps:
1. If you dont already have a remote connection to the MyDBServer VM open from the MyWebServer VM,
complete the steps in the Connect to the database server VM from the web server VM section of this article.
2. From the Windows desktop on the MyDBServer VM, open Internet Explorer and respond to the dialog boxes as
you did in steps 2 and 3 of the Connect to the Internet from the web server VM section of this article.
3. In the address bar, enter bing.com.
4. Click Add in the Internet Explorer dialog box that appears, then Add, then Close in the Trusted sites dialog box.
Complete these steps in any additional dialog boxes appear.
5. At the Bing search page, enter whatsmyipaddress, then click the magnifying glass button. Bing returns the
public IP address currently assigned to the VM by the Azure infrastructure. 6. Close the remote desktop to the
MyDBServer VM from the MyWebServer VM, then close the remote connection to the MyWebServer VM.
The outbound connection to the Internet is allowed because all outbound traffic is allowed by default, even though
a public IP address resource is not assigned to the MyDBServer VM. All VMs, by default, are able to connect
outbound to the Internet, with or without a public IP address resource assigned to the VM. You are not able to
connect to the public IP address from the Internet however, like you were able to for the MyWebServer VM that
has a public IP address resource assigned.
Next steps
In this exercise, you created a VNet and two VMs. You specified come custom settings during VM creation, and
accepted several default settings. We recommend that you read the following articles, before deploying production
VNets and VMs, to ensure you understand all available settings:
Virtual networks
Public IP addresses
Network interfaces
Network security groups
Virtual machines
Plan and design Azure Virtual Networks
8/16/2017 14 min to read Edit Online
Creating a VNet to experiment with is easy enough, but chances are, you will deploy multiple VNets over time to
support the production needs of your organization. With some planning and design, you will be able to deploy
VNets and connect the resources you need more effectively. If you are not familiar with VNets, it's recommended
that you learn about VNets and how to deploy one before proceeding.
Plan
A thorough understanding of Azure subscriptions, regions, and network resources is critical for success. You can
use the list of considerations below as a starting point. Once you understand those considerations, you can define
the requirements for your network design.
Considerations
Before answering the planning questions below, consider the following:
Everything you create in Azure is composed of one or more resources. A virtual machine (VM) is a resource, the
network adapter interface (NIC) used by a VM is a resource, the public IP address used by a NIC is a resource,
the VNet the NIC is connected to is a resource.
You create resources within an Azure region and subscription. Resources can only be connected to a virtual
network that exists in the same region and subscription the resource is in.
You can connect virtual networks to each other by using:
Virtual network peering: The virtual networks must exist in the same Azure region. Bandwidth between
resources in peered virtual networks is the same as if the resources were connected to the same virtual
network.
An Azure VPN Gateway: The virtual networks can exist in the same, or different Azure regions.
Bandwidth between resources in virtual networks connected through a VPN Gateway is limited by the
bandwidth of the VPN Gateway.
You can connect VNets to your on-premises network by using one of the connectivity options available in Azure.
Different resources can be grouped together in resource groups, making it easier to manage the resource as a
unit. A resource group can contain resources from multiple regions, as long as the resources belong to the same
subscription.
Define requirements
Use the questions below as a starting point for your Azure network design.
1. What Azure locations will you use to host VNets?
2. Do you need to provide communication between these Azure locations?
3. Do you need to provide communication between your Azure VNet(s) and your on-premises datacenter(s)?
4. How many Infrastructure as a Service (IaaS) VMs, cloud services roles, and web apps do you need for your
solution?
5. Do you need to isolate traffic based on groups of VMs (i.e. front end web servers and back end database
servers)?
6. Do you need to control traffic flow using virtual appliances?
7. Do users need different sets of permissions to different Azure resources?
Understand VNet and subnet properties
VNet and subnets resources help define a security boundary for workloads running in Azure. A VNet is
characterized by a collection of address spaces, defined as CIDR blocks.
NOTE
Network administrators are familiar with CIDR notation. If you are not familiar with CIDR, learn more about it.
location Azure location (also referred to as Must be one of the valid Azure
region). locations.
addressSpace Collection of address prefixes that make Must be an array of valid CIDR address
up the VNet in CIDR notation. blocks, including public IP address
ranges.
subnets Collection of subnets that make up the see the subnet properties table below.
VNet
dnsServers Array of DNS servers used by the VNet. Must be an array of up to 10 DNS
If no server is specified, Azure internal servers, by IP address.
name resolution is used.
A subnet is a child resource of a VNet, and helps define segments of address spaces within a CIDR block, using IP
address prefixes. NICs can be added to subnets, and connected to VMs, providing connectivity for various
workloads.
Subnets contain the following properties.
location Azure location (also referred to as Must be one of the valid Azure
region). locations.
addressPrefix Single address prefix that make up the Must be a single CIDR block that is part
subnet in CIDR notation of one of the VNet's address spaces.
Name resolution
By default, your VNet uses Azure-provided name resolution to resolve names inside the VNet, and on the public
Internet. However, if you connect your VNets to your on-premises data centers, you need to provide your own DNS
server to resolve names between your networks.
Limits
Review the networking limits in the Azure limits article to ensure that your design doesn't conflict with any of the
limits. Some limits can be increased by opening a support ticket.
Role -Based Access Control (RBAC )
You can use Azure RBAC to control the level of access different users may have to different resources in Azure. That
way you can segregate the work done by your team based on their needs.
As far as virtual networks are concerned, users in the Network Contributor role have full control over Azure
Resource Manager virtual network resources. Similarly, users in the Classic Network Contributor role have full
control over classic virtual network resources.
NOTE
You can also create your own roles to separate your administrative needs.
Design
Once you know the answers to the questions in the Plan section, review the following before defining your VNets.
Number of subscriptions and VNets
You should consider creating multiple VNets in the following scenarios:
VMs that need to be placed in different Azure locations. VNets in Azure are regional. They cannot span
locations. Therefore you need at least one VNet for each Azure location you want to host VMs in.
Workloads that need to be completely isolated from one another. You can create separate VNets, that
even use the same IP address spaces, to isolate different workloads from one another.
Keep in mind that the limits you see above are per region, per subscription. That means you can use multiple
subscriptions to increase the limit of resources you can maintain in Azure. You can use a site-to-site VPN, or an
ExpressRoute circuit, to connect VNets in different subscriptions.
Subscription and VNet design patterns
The table below shows some common design patterns for using subscriptions and VNets.
One subscription per app, Uses only two VNets per Harder to manage when
two VNets per app subscription. there are too many apps.
Number of subnets
You should consider multiple subnets in a VNet in the following scenarios:
Not enough private IP addresses for all NICs in a subnet. If your subnet address space does not contain
enough IP addresses for the number of NICs in the subnet, you need to create multiple subnets. Keep in mind
that Azure reserves 5 private IP addresses from each subnet that cannot be used: the first and last addresses of
the address space (for the subnet address, and multicast) and 3 addresses to be used internally (for DHCP and
DNS purposes).
Security. You can use subnets to separate groups of VMs from one another for workloads that have a multi-
layer structure, and apply different network security groups (NSGs) for those subnets.
Hybrid connectivity. You can use VPN gateways and ExpressRoute circuits to connect your VNets to one
another, and to your on-premises data center(s). VPN gateways and ExpressRoute circuits require a subnet of
their own to be created.
Virtual appliances. You can use a virtual appliance, such as a firewall, WAN accelerator, or VPN gateway in an
Azure VNet. When you do so, you need to route traffic to those appliances and isolate them in their own subnet.
Subnet and NSG design patterns
The table below shows some common design patterns for using subnets.
Single subnet, NSGs per Only one subnet to manage. Multiple NSGs necessary to
application layer, per app isolate each application.
One subnet per app, NSGs Fewer NSGs to manage. Multiple subnets to manage.
per application layer
One subnet per application Balance between number of Maximum number of NSGs
layer, NSGs per app. subnets and NSGs. per subscription. Review the
Azure limits article for details.
One subnet per application Possibly smaller number of Multiple subnets to manage.
layer, per app, NSGs per NSGs.
subnet
Sample design
To illustrate the application of the information in this article, consider the following scenario.
You work for a company that has 2 data centers in North America, and two data centers Europe. You identified 6
different customer facing applications maintained by 2 different business units that you want to migrate to Azure
as a pilot. The basic architecture for the applications are as follows:
App1, App2, App3, and App4 are web applications hosted on Linux servers running Ubuntu. Each application
connects to a separate application server that hosts RESTful services on Linux servers. The RESTful services
connect to a back end MySQL database.
App5 and App6 are web applications hosted on Windows servers running Windows Server 2012 R2. Each
application connects to a back end SQL Server database.
All apps are currently hosted in one of the company's data centers in North America.
The on-premises data centers use the 10.0.0.0/8 address space.
You need to design a virtual network solution that meets the following requirements:
Each business unit should not be affected by resource consumption of other business units.
You should minimize the amount of VNets and subnets to make management easier.
Each business unit should have a single test/development VNet used for all applications.
Each application is hosted in 2 different Azure data centers per continent (North America and Europe).
Each application is completely isolated from each other.
Each application can be accessed by customers over the Internet using HTTP.
Each application can be accessed by users connected to the on-premises data centers by using an encrypted
tunnel.
Connection to on-premises data centers should use existing VPN devices.
The company's networking group should have full control over the VNet configuration.
Developers in each business unit should only be able to deploy VMs to existing subnets.
All applications will be migrated as they are to Azure (lift-and-shift).
The databases in each location should replicate to other Azure locations once a day.
Each application should use 5 front end web servers, 2 application servers (when necessary), and 2 database
servers.
Plan
You should start your design planning by answering the question in the Define requirements section as shown
below.
1. What Azure locations will you use to host VNets?
2 locations in North America, and 2 locations in Europe. You should pick those based on the physical
location of your existing on-premises data centers. That way your connection from your physical locations to
Azure will have a better latency.
2. Do you need to provide communication between these Azure locations?
Yes. Since the databases must be replicated to all locations.
3. Do you need to provide communication between your Azure VNet(s) and your on-premises data center(s)?
Yes. Since users connected to the on-premises data centers must be able to access the applications through
an encrypted tunnel.
4. How many IaaS VMs do you need for your solution?
200 IaaS VMs. App1, App2, App3, and App4 require 5 web servers each, 2 applications servers each, and 2
database servers each. That's a total of 9 IaaS VMs per application, or 36 IaaS VMs. App5 and App6 require 5
web servers and 2 database servers each. That's a total of 7 IaaS VMs per application, or 14 IaaS VMs.
Therefore, you need 50 IaaS VMs for all applications in each Azure region. Since we need to use 4 regions,
there will be 200 IaaS VMs.
You will also need to provide DNS servers in each VNet, or in your on-premises data centers to resolve
name between your Azure IaaS VMs and your on-premises network.
5. Do you need to isolate traffic based on groups of VMs (i.e. front end web servers and back end database
servers)?
Yes. Each application should be completely isolated from each other, and each application layer should also
be isolated.
6. Do you need to control traffic flow using virtual appliances?
No. Virtual appliances can be used to provide more control over traffic flow, including more detailed data
plane logging.
7. Do users need different sets of permissions to different Azure resources?
Yes. The networking team needs full control on the virtual networking settings, while developers should only
be able to deploy their VMs to pre-existing subnets.
Design
You should follow the design specifying subscriptions, VNets, subnets, and NSGs. We will discuss NSGs here, but
you should learn more about NSGs before finishing your design.
Number of subscriptions and VNets
The following requirements are related to subscriptions and VNets:
Each business unit should not be affected by resource consumption of other business units.
You should minimize the amount of VNets and subnets.
Each business unit should have a single test/development VNet used for all applications.
Each application is hosted in 2 different Azure data centers per continent (North America and Europe).
Based on those requirements, you need a subscription for each business unit. That way, consumption of resources
from a business unit will not count towards limits for other business units. And since you want to minimize the
number of VNets, you should consider using the one subscription per business unit, two VNets per group of
apps pattern as seen below.
You also need to specify the address space for each VNet. Since you need connectivity between the on-premises
data centers and the Azure regions, the address space used for Azure VNets cannot clash with the on-premises
network, and the address space used by each VNet should not clash with other existing VNets. You could use the
address spaces in the table below to satisfy these requirements.
SUBSCRIPTION VNET AZURE REGION ADDRESS SPACE
However, you also need to create an extra subnet for the VPN connectivity between the VNets, and your on-
premises data centers. And you need to specify the address space for each subnet. The figure below shows a
sample solution for ProdBU1US1 VNet. You would replicate this scenario for each VNet. Each color represents a
different application.
Access Control
The following requirements are related to access control:
The company's networking group should have full control over the VNet configuration.
Developers in each business unit should only be able to deploy VMs to existing subnets.
Based on those requirements, you could add users from the networking team to the built-in Network Contributor
role in each subscription; and create a custom role for the application developers in each subscription giving them
rights to add VMs to existing subnets.
Next steps
Deploy a virtual network based on a scenario.
Understand how to load balance IaaS VMs and manage routing over multiple Azure regions.
Learn more about NSGs and how to plan and design an NSG solution.
Learn more about your cross-premises and VNet connectivity options.
Filter network traffic with network security groups
8/8/2017 14 min to read Edit Online
A network security group (NSG) contains a list of security rules that allow or deny network traffic to resources
connected to Azure Virtual Networks (VNet). NSGs can be associated to subnets, individual VMs (classic), or
individual network interfaces (NIC) attached to VMs (Resource Manager). When an NSG is associated to a
subnet, the rules apply to all resources connected to the subnet. Traffic can further be restricted by also
associating an NSG to a VM or NIC.
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic.
This article covers using both models, but Microsoft recommends that most new deployments use the Resource
Manager model.
NSG resource
NSGs contain the following properties:
Name Name for the NSG Must be unique within the Since you may need to
region. create several NSGs, make
Can contain letters, sure you have a naming
numbers, underscores, convention that makes it
periods, and hyphens. easy to identify the
Must start with a letter or function of your NSGs.
number.
Must end with a letter,
number, or underscore.
Cannot exceed 80
characters.
Region Azure region where the NSGs can only be To learn about how many
NSG is created. associated to resources NSGs you can have per
within the same region as region, read the Azure
the NSG. limits article.
Resource group The resource group the Although an NSG exists in Resource groups are used
NSG exists in. a resource group, it can be to manage multiple
associated to resources in resources together, as a
any resource group, as deployment unit.
long as the resource is part You may consider grouping
of the same Azure region the NSG with resources it is
as the NSG. associated to.
NSG rules
NSG rules contain the following properties:
Name Name for the rule. Must be unique within the You may have several rules
region. within an NSG, so make
Can contain letters, sure you follow a naming
numbers, underscores, convention that allows you
periods, and hyphens. to identify the function of
Must start with a letter or your rule.
number.
Must end with a letter,
number, or underscore.
Cannot exceed 80
characters.
Source port range Source port range to Single port number from 1 Source ports could be
match for the rule. to 65535, port range ephemeral. Unless your
(example: 1-65535), or * client program is using a
(for all ports). specific port, use * in most
cases.
Try to use port ranges as
much as possible to avoid
the need for multiple rules.
Multiple ports or port
ranges cannot be grouped
by a comma.
Destination port range Destination port range to Single port number from 1 Try to use port ranges as
match for the rule. to 65535, port range much as possible to avoid
(example: 1-65535), or * the need for multiple rules.
(for all ports). Multiple ports or port
ranges cannot be grouped
by a comma.
Source address prefix Source address prefix or Single IP address (example: Consider using ranges,
tag to match for the rule. 10.10.10.10), IP subnet default tags, and * to
(example: 192.168.1.0/24), reduce the number of rules.
default tag, or * (for all
addresses).
PROPERTY DESCRIPTION CONSTRAINTS CONSIDERATIONS
Destination address Destination address prefix Single IP address (example: Consider using ranges,
prefix or tag to match for the 10.10.10.10), IP subnet default tags, and * to
rule. (example: 192.168.1.0/24), reduce the number of rules.
default tag, or * (for all
addresses).
Priority Rules are checked in the Number between 100 and Consider creating rules
order of priority. Once a 4096. jumping priorities by 100
rule applies, no more rules for each rule to leave space
are tested for matching. for new rules you might
create in the future.
NSGs contain two sets of rules: Inbound and outbound. The priority for a rule must be unique within each set.
Associating NSGs
You can associate an NSG to VMs, NICs, and subnets, depending on the deployment model you are using, as
follows:
VM (classic only): Security rules are applied to all traffic to/from the VM.
NIC (Resource Manager only): Security rules are applied to all traffic to/from the NIC the NSG is
associated to. In a multi-NIC VM, you can apply different (or the same) NSG to each NIC individually.
Subnet (Resource Manager and classic): Security rules are applied to any traffic to/from any resources
connected to the VNet.
You can associate different NSGs to a VM (or NIC, depending on the deployment model) and the subnet that a
NIC or VM is connected to. Security rules are applied to the traffic, by priority, in each NSG, in the following
order:
Inbound traffic
1. NSG applied to subnet: If a subnet NSG has a matching rule to deny traffic, the packet is
dropped.
2. NSG applied to NIC (Resource Manager) or VM (classic): If VM\NIC NSG has a matching rule
that denies traffic, packets are dropped at the VM\NIC, even if a subnet NSG has a matching rule
that allows traffic.
Outbound traffic
1. NSG applied to NIC (Resource Manager) or VM (classic): If a VM\NIC NSG has a matching rule
that denies traffic, packets are dropped.
2. NSG applied to subnet: If a subnet NSG has a matching rule that denies traffic, packets are
dropped, even if a VM\NIC NSG has a matching rule that allows traffic.
NOTE
Although you can only associate a single NSG to a subnet, VM, or NIC; you can associate the same NSG to as many
resources as you want.
Implementation
You can implement NSGs in the Resource Manager or classic deployment models using the following tools:
Planning
Before implementing NSGs, you need to answer the following questions:
1. What types of resources do you want to filter traffic to or from? You can connect resources such as NICs
(Resource Manager), VMs (classic), Cloud Services, Application Service Environments, and VM Scale Sets.
2. Are the resources you want to filter traffic to/from connected to subnets in existing VNets?
For more information on planning for network security in Azure, read the Cloud services and network security
article.
Design considerations
Once you know the answers to the questions in the Planning section, review the following sections before
defining your NSGs:
Limits
There are limits to the number of NSGs you can have in a subscription and number of rules per NSG. To learn
more about the limits, read the Azure limits article.
VNet and subnet design
Since NSGs can be applied to subnets, you can minimize the number of NSGs by grouping your resources by
subnet, and applying NSGs to subnets. If you decide to apply NSGs to subnets, you may find that existing
VNets and subnets you have were not defined with NSGs in mind. You may need to define new VNets and
subnets to support your NSG design and deploy your new resources to your new subnets. You could then
define a migration strategy to move existing resources to the new subnets.
Special rules
If you block traffic allowed by the following rules, your infrastructure can't communicate with essential Azure
services:
Virtual IP of the host node: Basic infrastructure services such as DHCP, DNS, and health monitoring are
provided through the virtualized host IP address 168.63.129.16. This public IP address belongs to Microsoft
and is the only virtualized IP address used in all regions for this purpose. This IP address maps to the
physical IP address of the server machine (host node) hosting the VM. The host node acts as the DHCP
relay, the DNS recursive resolver, and the probe source for the load balancer health probe and the machine
health probe. Communication to this IP address is not an attack.
Licensing (Key Management Service): Windows images running in VMs must be licensed. To ensure
licensing, a request is sent to the Key Management Service host servers that handle such queries. The
request is made outbound through port 1688.
ICMP traffic
The current NSG rules only allow for protocols TCP or UDP. There is not a specific tag for ICMP. However,
ICMP traffic is allowed within a VNet by the AllowVNetInBound default rule, that allows traffic to and from any
port and protocol within the VNet.
Subnets
Consider the number of tiers your workload requires. Each tier can be isolated by using a subnet, with an
NSG applied to the subnet.
If you need to implement a subnet for a VPN gateway, or ExpressRoute circuit, do not apply an NSG to that
subnet. If you do so, cross-VNet or cross-premises connectivity may fail.
If you need to implement a network virtual appliance (NVA), connect the NVA to its own subnet and create
user-defined routes (UDR) to and from the NVA. You can implement a subnet level NSG to filter traffic in
and out of this subnet. To learn more about UDRs, read the User-defined routes article.
Load balancers
Consider the load balancing and network address translation (NAT) rules for each load balancer used by
each of your workloads. NAT rules are bound to a back-end pool that contains NICs (Resource Manager) or
VMs/Cloud Services role instances (classic). Consider creating an NSG for each back-end pool, allowing
only traffic mapped through the rules implemented in the load balancers. Creating an NSG for each back-
end pool guarantees that traffic coming to the back-end pool directly (rather than through the load
balancer), is also filtered.
In classic deployments, you create endpoints that map ports on a load balancer to ports on your VMs or
role instances. You can also create your own individual public-facing load balancer through Resource
Manager. The destination port for incoming traffic is the actual port in the VM or role instance, not the port
exposed by a load balancer. The source port and address for the connection to the VM is a port and
address on the remote computer in the Internet, not the port and address exposed by the load balancer.
When you create NSGs to filter traffic coming through an internal load balancer (ILB), the source port and
address range applied are from the originating computer, not the load balancer. The destination port and
address range are those of the destination computer, not the load balancer.
Other
Endpoint-based access control lists (ACL) and NSGs are not supported on the same VM instance. If you
want to use an NSG and have an endpoint ACL already in place, first remove the endpoint ACL. For
information about how to remove an endpoint ACL, see the Manage endpoint ACLs article.
In Resource Manager, you can use an NSG associated to a NIC for VMs with multiple NICs to enable
management (remote access) on a per NIC basis. Associating unique NSGs to each NIC enables separation
of traffic types across NICs.
Similar to the use of load balancers, when filtering traffic from other VNets, you must use the source
address range of the remote computer, not the gateway connecting the VNets.
Many Azure services cannot be connected to VNets. If an Azure resource is not connected to a VNet, you
cannot use an NSG to filter traffic to the resource. Read the documentation for the services you use to
determine whether the service can be connected to a VNet.
Sample deployment
To illustrate the application of the information in this article, consider a common scenario of a two tier
application shown in the following picture:
As shown in the diagram, the Web1 and Web2 VMs are connected to the FrontEnd subnet, and the DB1 and
DB2 VMs are connected to the BackEnd subnet. Both subnets are part of the TestVNet VNet. The application
components each run within an Azure VM connected to a VNet. The scenario has the following requirements:
1. Separation of traffic between the WEB and DB servers.
2. Load balancing rules forward traffic from the load balancer to all web servers on port 80.
3. Load balancer NAT rules forward traffic coming into the load balancer on port 50001 to port 3389 on the
WEB1 VM.
4. No access to the front-end or back-end VMs from the Internet, except requirements 2 and 3.
5. No outbound Internet access from the WEB or DB servers.
6. Access from the FrontEnd subnet is allowed to port 3389 of any web server.
7. Access from the FrontEnd subnet is allowed to port 3389 of any DB server.
8. Access from the FrontEnd subnet is allowed to port 1433 of all DB servers.
9. Separation of management traffic (port 3389) and database traffic (1433) on different NICs in DB servers.
Requirements 1-6 (except requirements 3 and 4) are all confined to subnet spaces. The following NSGs meet
the previous requirements, while minimizing the number of NSGs required:
FrontEnd
Inbound rules
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
Outbound rules
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
BackEnd
Inbound rules
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
Outbound rules
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
The following NSGs are created and associated to NICs in the following VMs:
WEB1
Inbound rules
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
NOTE
The source address range for the previous rules is Internet, not the virtual IP address of for the load balancer. The
source port is , not 500001. NAT rules for load balancers are not the same as NSG security rules. NSG security rules
are always related to the original source and final destination of traffic, **not* the load balancer between the two.
WEB2
Inbound rules
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
SOURCE DESTINATIO
ADDRESS SOURCE N ADDRESS DESTINATIO
RULE ACCESS PRIORITY RANGE PORT RANGE N PORT PROTOCOL
Since some of the NSGs are associated to individual NICs, the rules are for resources deployed through
Resource Manager. Rules are combined for subnet and NIC, depending on how they are associated.
Next steps
Deploy NSGs (Resource Manager).
Deploy NSGs (classic).
Manage NSG logs.
Troubleshoot NSGs
Create a virtual network with multiple subnets
9/6/2017 10 min to read Edit Online
In this tutorial, learn how to create a basic Azure virtual network that has separate public and private subnets.
Resources in virtual networks can communicate with each other, and with resources in other networks connected
to a virtual network. You can create Azure resources, like Virtual machines, App Service environments, Virtual
machine scale sets, Azure HDInsight, and Cloud services in the same, or different subnets within a virtual
network. Creating resources in different subnets enables you to filter network traffic in and out of subnets
independently with network security groups, and to route traffic between subnets through network virtual
appliances, such as a firewall, if you choose to.
The following sections include steps that you can take to create a virtual network by using the Azure portal, the
Azure command-line interface (Azure CLI), Azure PowerShell, and an Azure Resource Manager template. The
result is the same, regardless of which tool you use to create the virtual network. Click a tool link to go to that
section of the tutorial. Learn more about all virtual network and subnet settings.
This article provides steps to create a virtual network through the Resource Manager deployment model, which is
the deployment model we recommend using when creating new virtual networks. If you need to create a virtual
network (classic), see Create a virtual network (classic). If you're not familiar with Azure's deployment models,
see Understand Azure deployment models.
Azure portal
1. In an Internet browser, go to the Azure portal. Log in using your Azure account. If you don't have an Azure
account, you can sign up for a free trial.
2. In the portal, click +New > Networking > Virtual network.
3. On the Create virtual network blade, enter the following values, and then click Create:
SETTING VALUE
Name myVnet
If you're new to Azure, learn more about resource groups, subscriptions, and locations (also referred to as
regions).
4. In the portal, you can create only one subnet when you create a virtual network. In this tutorial, you create a
second subnet after you create the virtual network. You might later create Internet-accessible resources in the
Public subnet. You also might create resources that aren't accessible from the Internet in the Private subnet.
To create the second subnet, in the Search resources box at the top of the page, enter myVnet. In the search
results, click myVnet. If you have multiple virtual networks with the same name in your subscription, check
the resource groups that are listed under each virtual network. Ensure that you click the myVnet search result
that has the resource group myResourceGroup.
5. On the myVnet blade, under SETTINGS, click Subnets.
6. On the myVnet - Subnets blade, click +Subnet.
7. On the Add subnet blade, for Name, enter Private. For Address range, enter 10.0.1.0/24. Click OK.
8. On the myVnet - Subnets blade, review the subnets. You can see the Public and Private subnets that you
created.
9. Optional: Complete additional tutorials listed under Next steps to filter network traffic in and out of each
subnet with network security groups, to route traffic between subnets through a network virtual appliance, or
to connect the virtual network to other virtual networks or on-premises networks.
10. Optional: Delete the resources that you create in this tutorial by completing the steps in Delete resources.
Azure CLI
Azure CLI commands are the same, whether you execute the commands from Windows, Linux, or macOS.
However, there are scripting differences between operating system shells. The script in the following steps
executes in a Bash shell.
1. Install and configure the Azure CLI. Ensure you have the most recent version of the Azure CLI installed. To get
help for CLI commands, type az <command> --help . Rather than installing the CLI and its pre-requisites, you
can use the Azure Cloud Shell. The Azure Cloud Shell is a free Bash shell that you can run directly within the
Azure portal. The Cloud Shell has the Azure CLI preinstalled and configured to use with your account. To use
the Cloud Shell, click the Cloud Shell (>_) button at the top of the portal or just click the Try it button in the
steps that follow.
2. If running the CLI locally, log in to Azure with the az login command. If using the Cloud Shell, you're already
logged in.
3. Review the following script and its comments. In your browser, copy the script and paste it into your CLI
session:
#!/bin/bash
4. When the script is finished running, review the subnets for the virtual network. Copy the following
command, and then paste it into your CLI session:
az network vnet subnet list --resource-group myResourceGroup --vnet-name myVnet --output table
5. Optional: Complete additional tutorials listed under Next steps to filter network traffic in and out of each
subnet with network security groups, to route traffic between subnets through a network virtual appliance,
or to connect the virtual network to other virtual networks or on-premises networks.
6. Optional: Delete the resources that you create in this tutorial by completing the steps in Delete resources.
PowerShell
1. Install the latest version of the PowerShell AzureRm module. If you're new to Azure PowerShell, see Azure
PowerShell overview.
2. In a PowerShell session, log in to Azure with your Azure account using the login-azurermaccount
command.
3. Review the following script and its comments. In your browser, copy the script and paste it into your
PowerShell session:
4. To review the subnets for the virtual network, copy the following command, and then paste it into your
PowerShell session:
5. Optional: Complete additional tutorials listed under Next steps to filter network traffic in and out of each
subnet with network security groups, to route traffic between subnets through a network virtual appliance,
or to connect the virtual network to other virtual networks or on-premises networks.
6. Optional: Delete the resources that you create in this tutorial by completing the steps in Delete resources.
PARAMETER VALUE
Subnet1Prefix 10.0.0.0/24
Subnet1Name Public
Subnet2Prefix 10.0.1.0/24
Subnet2Name Private
5. Agree to the terms and conditions, and then click Purchase to deploy the virtual network.
Azure CLI
1. Install and configure the Azure CLI. Ensure you have the most recent version of the Azure CLI installed. To get
help for CLI commands, type az <command> --help . Rather than installing the CLI and its pre-requisites, you
can use the Azure Cloud Shell. The Azure Cloud Shell is a free Bash shell that you can run directly within the
Azure portal. The Cloud Shell has the Azure CLI preinstalled and configured to use with your account. To use
the Cloud Shell, click the Cloud Shell >_ button at the top of the portal, or just click the Try it button in the
steps that follow.
2. If running the CLI locally, log in to Azure with the az login command. If using the Cloud Shell, you're already
logged in.
3. To create a resource group for the virtual network, copy the following command and paste it into your CLI
session:
4. You can deploy the template by using one of the following parameters options:
Default parameter values. Enter the following command:
az group deployment create --resource-group myResourceGroup --name VnetTutorial --template-uri
https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-vnet-two-
subnets/azuredeploy.json`
Custom parameter values. Download and modify the template before you deploy the template.
You also can deploy the template by using parameters at the command line, or deploy the template
with a separate parameters file. To download the template and parameters files, click the Browse
on GitHub button on the Create a virtual network with two subnets template page. In GitHub, click
the azuredeploy.parameters.json or azuredeploy.json file. Then, click the Raw button to display
the file. In your browser, copy the contents of the file. Save the contents to a file on your computer.
You can modify the parameter values in the template, or deploy the template with a separate
parameters file.
To learn more about how to deploy templates by using these methods, type
az group deployment create --help .
PowerShell
1. Install the latest version of the PowerShell AzureRm module. If you're new to Azure PowerShell, see Azure
PowerShell overview.
2. In a PowerShell session, to sign in with your Azure account, enter login-azurermaccount .
3. To create a resource group for the virtual network, enter the following command:
4. You can deploy the template by using one of the following parameters options:
Default parameter values. Enter the following command:
Custom parameter values. Download and modify the template before you deploy it. You also can
deploy the template by using parameters at the command line, or deploy the template with a
separate parameters file. To download the template and parameters files, click the Browse on
GitHub button on the Create a virtual network with two subnets template page. In GitHub, click the
azuredeploy.parameters.json or azuredeploy.json file. Then, click the Raw button to display the
file. In your browser, copy the contents of the file. Save the contents to a file on your computer. You
can modify the parameter values in the template, or deploy the template with a separate
parameters file.
To learn more about how to deploy templates by using these methods, type
Get-Help New-AzureRmResourceGroupDeployment .
Delete resources
When you finish this tutorial, you might want to delete the resources that you created, so that you don't incur
usage charges. Deleting a resource group also deletes all resources that are in the resource group.
Azure portal
1. In the portal search box, enter myResourceGroup. In the search results, click myResourceGroup.
2. On the myResourceGroup blade, click the Delete icon.
3. To confirm the deletion, in the TYPE THE RESOURCE GROUP NAME box, enter myResourceGroup, and
then click Delete.
Azure CLI
In a CLI session, enter the following command:
PowerShell
In a PowerShell session, enter the following command:
Next steps
To learn about all virtual network and subnet settings, see Manage virtual networks and Manage virtual
network subnets. You have various options for using virtual networks and subnets in a production
environment to meet different requirements.
Filter inbound and outbound subnet traffic by creating and applying network security groups to subnets.
Route traffic between subnets through a network virtual appliance, by creating user-defined routes and apply
the routes to each subnet.
Create a Windows or a Linux virtual machine in an existing virtual network.
Connect two virtual networks by creating a virtual network peering between the virtual networks.
Connect the virtual network to an on-premises network by using a VPN Gateway or Azure ExpressRoute
circuit.
Create a virtual network using PowerShell
6/27/2017 3 min to read Edit Online
An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure
network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also further
segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in the
same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can
expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are
not familiar with VNets.
Azure has two deployment models: Azure Resource Manager and classic. Microsoft recommends creating
resources through the Resource Manager deployment model. To learn more about the differences between the
two models, read the Understand Azure deployment models article.
This article explains how to create a VNet through the Resource Manager deployment model using PowerShell.
You can also create a VNet through Resource Manager using other tools or create a VNet through the classic
deployment model by selecting a different option from the following list:
Scenario
To better illustrate how to create a VNet and subnets, this document will use the scenario below.
In this scenario you will create a VNet named TestVNet with a reserved CIDR block of 192.168.0.0./16. Your VNet
will contain the following subnets:
FrontEnd, using 192.168.1.0/24 as its CIDR block.
BackEnd, using 192.168.2.0/24 as its CIDR block.
Expected output:
ResourceGroupName : TestRG
Location : centralus
ProvisioningState : Succeeded
Tags :
ResourceId : /subscriptions/[Subscription Id]/resourceGroups/TestRG
Expected output:
Name : TestVNet
ResourceGroupName : TestRG
Location : centralus
Id : /subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
AddressSpace : {
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptions : {}
Subnets : []
VirtualNetworkPeerings : []
TIP
You can combine steps 3 and 4 by running
$vnet = New-AzureRmVirtualNetwork -ResourceGroupName TestRG -Name TestVNet -AddressPrefix
192.168.0.0/16 -Location centralus
.
Expected output:
Name : TestVNet
ResourceGroupName : TestRG
Location : centralus
Id : /subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
AddressSpace : {
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptions : {}
Subnets : [
{
"Name": "FrontEnd",
"AddressPrefix": "192.168.1.0/24"
}
]
VirtualNetworkPeerings : []
6. Repeat step 5 above for each subnet you want to create. The following command creates the BackEnd
subnet for the scenario:
7. Although you create subnets, they currently only exist in the local variable used to retrieve the VNet you
create in step 4 above. To save the changes to Azure, run the following command:
Expected output:
Name : TestVNet
ResourceGroupName : TestRG
Location : centralus
Id : /subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
AddressSpace : {
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptions : {
"DnsServers": []
}
Subnets : [
{
"Name": "FrontEnd",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontEnd",
"AddressPrefix": "192.168.1.0/24",
"IpConfigurations": [],
"ProvisioningState": "Succeeded"
},
{
"Name": "BackEnd",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/BackEnd",
"AddressPrefix": "192.168.2.0/24",
"IpConfigurations": [],
"ProvisioningState": "Succeeded"
}
]
VirtualNetworkPeerings : []
Next steps
Learn how to connect:
A virtual machine (VM) to a virtual network by reading the Create a Windows VM article. Instead of creating a
VNet and subnet in the steps of the articles, you can select an existing VNet and subnet to connect a VM to.
The virtual network to other virtual networks by reading the Connect VNets article.
The virtual network to an on-premises network using a site-to-site virtual private network (VPN) or
ExpressRoute circuit. Learn how by reading the Connect a VNet to an on-premises network using a site-to-site
VPN and Link a VNet to an ExpressRoute circuit articles.
Create a virtual network using the Azure CLI 2.0
6/27/2017 3 min to read Edit Online
An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure
network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also further
segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in the
same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can
expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are
not familiar with VNets.
Azure has two deployment models: Azure Resource Manager and classic. Microsoft recommends creating
resources through the Resource Manager deployment model. To learn more about the differences between the
two models, read the Understand Azure deployment models article.
Scenario
To better illustrate how to create a VNet and subnets, this document will use the scenario below.
In this scenario you will create a VNet named TestVNet with a reserved CIDR block of 192.168.0.0./16. Your VNet
will contain the following subnets:
FrontEnd, using 192.168.1.0/24 as its CIDR block.
BackEnd, using 192.168.2.0/24 as its CIDR block.
Expected output:
{
"newVNet": {
"addressSpace": {
"addressPrefixes": [
"192.168.0.0/16"
]
},
"dhcpOptions": {
"dnsServers": []
},
"provisioningState": "Succeeded",
"resourceGuid": "<guid>",
"subnets": [
{
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subne
ts/FrontEnd",
"name": "FrontEnd",
"properties": {
"addressPrefix": "192.168.1.0/24",
"provisioningState": "Succeeded"
},
"resourceGroup": "TestRG"
}
]
}
}
Parameters used:
--name TestVNet : Name of the VNet to be created.
--resource-group TestRG : # The resource group name that controls the resource.
--location centralus : The location into which to deploy.
--address-prefix 192.168.0.0/16 : The address prefix and block.
--subnet-name FrontEnd : The name of the subnet.
--subnet-prefix 192.168.1.0/24 : The address prefix and block.
To list the basic information to use in the next command, you can query the VNet using a query filter:
az network vnet list --query '[?name==`TestVNet`].
{Where:location,Name:name,Group:resourceGroup}' -o table
Expected output:
{
"addressPrefix": "192.168.2.0/24",
"etag": "W/\"<guid> \"",
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subne
ts/BackEnd",
"ipConfigurations": null,
"name": "BackEnd",
"networkSecurityGroup": null,
"provisioningState": "Succeeded",
"resourceGroup": "TestRG",
"resourceNavigationLinks": null,
"routeTable": null
}
Parameters used:
--address-prefix 192.168.2.0/24 : Subnet CIDR block.
--name BackEnd : Name of the new subnet.
--resource-group TestRG : The resource group.
--vnet-name TestVNet : The name of the owning VNet.
5. Query the properties of the new VNet:
Expected output:
Expected output:
Next steps
Learn how to connect:
A virtual machine (VM) to a virtual network by reading the Create a Linux VM article. Instead of creating a VNet
and subnet in the steps of the articles, you can select an existing VNet and subnet to connect a VM to.
The virtual network to other virtual networks by reading the Connect VNets article.
The virtual network to an on-premises network using a site-to-site virtual private network (VPN) or
ExpressRoute circuit. Learn how by reading the Connect a VNet to an on-premises network using a site-to-site
VPN and Link a VNet to an ExpressRoute circuit.
Create a virtual network using an Azure Resource
Manager template
6/27/2017 6 min to read Edit Online
An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure
network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also further
segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in the
same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can
expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are
not familiar with VNets.
Azure has two deployment models: Azure Resource Manager and classic. Microsoft recommends creating
resources through the Resource Manager deployment model. To learn more about the differences between the two
models, read the Understand Azure deployment models article.
This article explains how to create a VNet through the Resource Manager deployment model using an Azure
Resource Manager template. You can also create a VNet through Resource Manager using other tools or create a
VNet through the classic deployment model by selecting a different option from the following list:
You will learn how to download and modify and existing ARM template from GitHub, and deploy the template
from GitHub, PowerShell, and the Azure CLI.
If you are simply deploying the ARM template directly from GitHub, without any changes, skip to deploy a template
from github.
Scenario
To better illustrate how to create a VNet and subnets, this document will use the scenario below.
In this scenario you will create a VNet named TestVNet with a reserved CIDR block of 192.168.0.0./16. Your VNet
will contain the following subnets:
FrontEnd, using 192.168.1.0/24 as its CIDR block.
BackEnd, using 192.168.2.0/24 as its CIDR block.
PARAMETER DESCRIPTION
IMPORTANT
Azure Resource Manager templates maintained in GitHub can change over time. Make sure you check the template
before using it.
The command creates a resource group named TestRG in the Central US azure region. For more information
about resource groups, visit Azure Resource Manager Overview.
Expected output:
ResourceGroupName : TestRG
Location : centralus
ProvisioningState : Succeeded
Tags :
Permissions :
Actions NotActions
======= ==========
*
ResourceId : /subscriptions/[Id]/resourceGroups/TestRG
3. Run the following command to deploy the new VNet using the template and parameter files you
downloaded and modified above:
Expected output:
DeploymentName : TestVNetDeployment
ResourceGroupName : TestRG
ProvisioningState : Succeeded
Timestamp : [Date and time]
Mode : Incremental
TemplateLink :
Parameters :
Name Type Value
=============== ========================= ==========
location String Central US
vnetName String TestVNet
addressPrefix String 192.168.0.0/16
subnet1Prefix String 192.168.1.0/24
subnet1Name String FrontEnd
subnet2Prefix String 192.168.2.0/24
subnet2Name String BackEnd
Outputs :
4. Run the following command to view the properties of the new VNet:
Expected output:
Name : TestVNet
ResourceGroupName : TestRG
Location : centralus
Id :
/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
AddressSpace : {
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptions : {
"DnsServers": null
}
NetworkInterfaces : null
Subnets : [
{
"Name": "FrontEnd",
"Etag": "W/\"[Id]\"",
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/
FrontEnd",
"AddressPrefix": "192.168.1.0/24",
"IpConfigurations": [],
"NetworkSecurityGroup": null,
"RouteTable": null,
"ProvisioningState": "Succeeded"
},
{
"Name": "BackEnd",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/BackEnd"
,
"AddressPrefix": "192.168.2.0/24",
"IpConfigurations": [],
"NetworkSecurityGroup": null,
"RouteTable": null,
"ProvisioningState": "Succeeded"
}
]
5. Click Resource group and select a resource group to add the VNet to, or click Create new to add the VNet
to a new resource group. The following figure shows the resource group settings for a new resource group
called TestRG:
6. If necessary, change the Subscription and Location settings for your VNet.
7. If you do not want to see the VNet as a tile in the Startboard, disable Pin to Startboard.
8. Click Legal terms, read the terms, and click Buy to agree.
9. Click Create to create the VNet.
10. Once the deployment is complete, in the Azure portal click More services, type virtual networks in the filter
box that appears, then click Virtual networks to see the Virtual networks blade. In the blade, click TestVNet. In
the TestVNet blade, click Subnets to see the created subnets, as shown in the following picture:
Next steps
Learn how to connect:
A virtual machine (VM) to a virtual network by reading the Create a Windows VM or Create a Linux VM articles.
Instead of creating a VNet and subnet in the steps of the articles, you can select an existing VNet and subnet to
connect a VM to.
The virtual network to other virtual networks by reading the Connect VNets article.
The virtual network to an on-premises network using a site-to-site virtual private network (VPN) or
ExpressRoute circuit. Learn how by reading the Connect a VNet to an on-premises network using a site-to-site
VPN and Link a VNet to an ExpressRoute circuit articles.
Create network security groups using the Azure
portal
6/27/2017 3 min to read Edit Online
You can use an NSG to control traffic to one or more virtual machines (VMs), role instances, network adapters
(NICs), or subnets in your virtual network. An NSG contains access control rules that allow or deny traffic based on
traffic direction, protocol, source address and port, and destination address and port. The rules of an NSG can be
changed at any time, and changes are applied to all associated instances.
For more information about NSGs, visit what is an NSG.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the Resource Manager deployment model. You can also create NSGs in the classic deployment
model.
Scenario
To better illustrate how to create NSGs, this document will use the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
The sample PowerShell commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, first build the test environment
by deploying this template, click Deploy to Azure, replace the default parameter values if necessary, and follow
the instructions in the portal. The steps below use RG-NSG as the name of the resource group the template was
deployed to.
4. In the Add inbound security rule blade, create a rule named web-rule with priority of 200 allowing access
via TCP to port 80 to any VM from any source, and then click OK. Notice that most of these settings are
default values already.
5. After a few seconds you will see the new rule in the NSG.
6. Repeat steps to 6 to create an inbound rule named rdp-rule with a priority of 250 allowing access via TCP to
port 3389 to any VM from any source.
3. Repeat the steps in Associate the NSG to the FrontEnd subnet to associate the NSG-Backend NSG to the
BackEnd subnet.
Next Steps
Learn how to manage existing NSGs
Enable logging for NSGs.
Create network security groups using PowerShell
6/27/2017 4 min to read Edit Online
You can use an NSG to control traffic to one or more virtual machines (VMs), role instances, network adapters
(NICs), or subnets in your virtual network. An NSG contains access control rules that allow or deny traffic based on
traffic direction, protocol, source address and port, and destination address and port. The rules of an NSG can be
changed at any time, and changes are applied to all associated instances.
For more information about NSGs, visit what is an NSG.
Azure has two deployment models: Azure Resource Manager and classic. Microsoft recommends creating
resources through the Resource Manager deployment model. To learn more about the differences between the
two models, read the Understand Azure deployment models article. This article covers the Resource Manager
deployment model. You can also create NSGs in the classic deployment model.
Scenario
To better illustrate how to create NSGs, this document will use the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
The sample PowerShell commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, first build the test environment by
deploying this template, click Deploy to Azure, replace the default parameter values if necessary, and follow the
instructions in the portal.
3. Create a security rule allowing access from the Internet to port 80.
$nsg
Output showing only the FrontEnd subnet settings, notice the value for the NetworkSecurityGroup
property:
Subnets : [
{
"Name": "FrontEnd",
"Etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontEn
d",
"AddressPrefix": "192.168.1.0/24",
"IpConfigurations": [
{
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNICWeb2/ipConfigur
ations/ipconfig1"
},
{
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNICWeb1/ipConfigur
ations/ipconfig1"
}
],
"NetworkSecurityGroup": {
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/networkSecurityGroups/NSG-FrontEnd"
},
"RouteTable": null,
"ProvisioningState": "Succeeded"
}
WARNING
The output for the command above shows the content for the virtual network configuration object, which only exists
on the computer where you are running PowerShell. You need to run the Set-AzureRmVirtualNetwork cmdlet to
save these settings to Azure.
"NetworkSecurityGroup": {
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/networkSecurityGroups/NSG-FrontEnd"
}
Output showing only the BackEnd subnet settings, notice the value for the NetworkSecurityGroup
property:
Subnets : [
{
"Name": "BackEnd",
"Etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/BackEnd
",
"AddressPrefix": "192.168.2.0/24",
"IpConfigurations": [...],
"NetworkSecurityGroup": {
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG/providers/Microsoft.Network/networkSecurityGroups/NSG-BackEnd"
},
"RouteTable": null,
"ProvisioningState": "Succeeded"
}
Scenario
To better illustrate how to create NSGs, this document will use the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
The sample Azure CLI 2.0 commands following expect a simple environment already created based on the
scenario preceding.
Parameters:
--resource-group : Name of the resource group where the NSG is created. For our scenario, TestRG.
--location : Azure region where the new NSG is created. For our scenario, westus.
--name : Name for the new NSG. For our scenario, NSG-FrontEnd.
The expected output is quite a bit of information including a list of all the default rules. The following
example shows the default rules using a JMESPATH query filter with the table output format:
Output:
3. Create a rule that allows access to port 3389 (RDP) from the Internet with the az network nsg rule create
command.
NOTE
Depending on the shell you are using, you might need to modify the * character in the arguments following so as
not to expand the argument before execution.
Expected output:
{
"access": "Allow",
"description": null,
"destinationAddressPrefix": "*",
"destinationPortRange": "3389",
"direction": "Inbound",
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/networkSecurityGroups/NSG-
FrontEnd/securityRules/rdp-rule",
"name": "rdp-rule",
"priority": 100,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"sourceAddressPrefix": "Internet",
"sourcePortRange": "*"
}
Parameters:
--resource-group testrg : The resource group to use. Note that it is case-insensitive.
--nsg-name NSG-FrontEnd : Name of the NSG in which the rule is created.
--name rdp-rule : Name for the new rule.
--access Allow : Access level for the rule (Deny or Allow).
--protocol Tcp : Protocol (Tcp, Udp, or *).
--direction Inbound : Direction of the connection (Inbound or Outbound).
--priority 100 : Priority for the rule.
--source-address-prefix Internet : Source address prefix in CIDR or using default tags.
--source-port-range "*" : Source port or port range. Port that opened the connection.
--destination-address-prefix "*" : Destination address prefix in CIDR or using default tags.
--destination-port-range 3389 : Destination port or port range. Port that receives the connection request.
4. Create a rule that allows access to port 80 (HTTP) from the Internet az network nsg rule create command.
az network nsg rule create \
--resource-group testrg \
--nsg-name NSG-FrontEnd \
--name web-rule \
--access Allow \
--protocol Tcp \
--direction Inbound \
--priority 200 \
--source-address-prefix Internet \
--source-port-range "*" \
--destination-address-prefix "*" \
--destination-port-range 80
Expected putput:
{
"access": "Allow",
"description": null,
"destinationAddressPrefix": "*",
"destinationPortRange": "80",
"direction": "Inbound",
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/networkSecurityGroups/NSG-
FrontEnd/securityRules/web-rule",
"name": "web-rule",
"priority": 200,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"sourceAddressPrefix": "Internet",
"sourcePortRange": "*"
}
5. Bind the NSG to the FrontEnd subnet with the az network vnet subnet update command.
Expected output:
{
"addressPrefix": "192.168.1.0/24",
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/virtualNetworks/TestVNET/subne
ts/FrontEnd",
"ipConfigurations": [
{
"etag": null,
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC/ipCo
nfigurations/ipconfig1",
"name": null,
"privateIpAddress": null,
"privateIpAllocationMethod": null,
"provisioningState": null,
"publicIpAddress": null,
"resourceGroup": "TestRG",
"subnet": null
}
],
"name": "FrontEnd",
"networkSecurityGroup": {
"defaultSecurityRules": null,
"etag": null,
"id":
"/subscriptions/<guid>f/resourceGroups/testrg/providers/Microsoft.Network/networkSecurityGroups/NSG-
FrontEnd",
"location": null,
"name": null,
"networkInterfaces": null,
"provisioningState": null,
"resourceGroup": "testrg",
"resourceGuid": null,
"securityRules": null,
"subnets": null,
"tags": null,
"type": null
},
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"resourceNavigationLinks": null,
"routeTable": null
}
As in step 2, preceding, the expected output is quite large, including default rules.
2. Create a rule that allows access to port 1433 (SQL) from the FrontEnd subnet with the az network nsg
rule create command.
az network nsg rule create \
--resource-group testrg \
--nsg-name NSG-BackEnd \
--name sql-rule \
--access Allow \
--protocol Tcp \
--direction Inbound \
--priority 100 \
--source-address-prefix 192.168.1.0/24 \
--source-port-range "*" \
--destination-address-prefix "*" \
--destination-port-range 1433
Expected output:
{
"access": "Allow",
"description": null,
"destinationAddressPrefix": "*",
"destinationPortRange": "1433",
"direction": "Inbound",
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/networkSecurityGroups/NSG-
BackEnd/securityRules/sql-rule",
"name": "sql-rule",
"priority": 100,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"sourceAddressPrefix": "192.168.1.0/24",
"sourcePortRange": "*"
}
3. Create a rule that denies access to the Internet using the az network nsg rule create command.
Expected putput:
{
"access": "Deny",
"description": null,
"destinationAddressPrefix": "*",
"destinationPortRange": "*",
"direction": "Outbound",
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/networkSecurityGroups/NSG-
BackEnd/securityRules/web-rule",
"name": "web-rule",
"priority": 200,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"sourceAddressPrefix": "*",
"sourcePortRange": "*"
}
4. Bind the NSG to the BackEnd subnet using the az network vnet subnet set command.
Expected output:
{
"addressPrefix": "192.168.2.0/24",
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/virtualNetworks/TestVNET/subne
ts/BackEnd",
"ipConfigurations": null,
"name": "BackEnd",
"networkSecurityGroup": {
"defaultSecurityRules": null,
"etag": null,
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/networkSecurityGroups/NSG-
BackEnd",
"location": null,
"name": null,
"networkInterfaces": null,
"provisioningState": null,
"resourceGroup": "testrg",
"resourceGuid": null,
"securityRules": null,
"subnets": null,
"tags": null,
"type": null
},
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"resourceNavigationLinks": null,
"routeTable": null
}
Create network security groups using an Azure
Resource Manager template
6/27/2017 4 min to read Edit Online
You can use an NSG to control traffic to one or more virtual machines (VMs), role instances, network adapters
(NICs), or subnets in your virtual network. An NSG contains access control rules that allow or deny traffic based on
traffic direction, protocol, source address and port, and destination address and port. The rules of an NSG can be
changed at any time, and changes are applied to all associated instances.
For more information about NSGs, visit what is an NSG.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the Resource Manager deployment model. You can also create NSGs in the classic deployment
model.
Scenario
To better illustrate how to create NSGs, this document will use the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[parameters('frontEndNSGName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "NSG - Front End"
},
"properties": {
"securityRules": [
{
"name": "rdp-rule",
"properties": {
"description": "Allow RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "Internet",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
},
{
"name": "web-rule",
"properties": {
"description": "Allow WEB",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "80",
"sourceAddressPrefix": "Internet",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 101,
"direction": "Inbound"
}
}
]
}
To associate the NSG to the front-end subnet, you have to change the subnet definition in the template, and use
the reference id for the NSG.
"subnets": [
{
"name": "[parameters('frontEndSubnetName')]",
"properties": {
"addressPrefix": "[parameters('frontEndSubnetPrefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('frontEndNSGName'))]"
}
}
},
Notice the same being done for the back-end NSG and the back-end subnet in the template.
Expected output:
ResourceGroupName : TestRG
Location : westus
ProvisioningState : Succeeded
Tags :
Permissions :
Actions NotActions
======= ==========
*
Resources :
Name Type Location
================== ======================================= ========
sqlAvSet Microsoft.Compute/availabilitySets westus
webAvSet Microsoft.Compute/availabilitySets westus
SQL1 Microsoft.Compute/virtualMachines westus
SQL2 Microsoft.Compute/virtualMachines westus
Web1 Microsoft.Compute/virtualMachines westus
Web2 Microsoft.Compute/virtualMachines westus
TestNICSQL1 Microsoft.Network/networkInterfaces westus
TestNICSQL2 Microsoft.Network/networkInterfaces westus
TestNICWeb1 Microsoft.Network/networkInterfaces westus
TestNICWeb2 Microsoft.Network/networkInterfaces westus
NSG-BackEnd Microsoft.Network/networkSecurityGroups westus
NSG-FrontEnd Microsoft.Network/networkSecurityGroups westus
TestPIPSQL1 Microsoft.Network/publicIPAddresses westus
TestPIPSQL2 Microsoft.Network/publicIPAddresses westus
TestPIPWeb1 Microsoft.Network/publicIPAddresses westus
TestPIPWeb2 Microsoft.Network/publicIPAddresses westus
TestVNet Microsoft.Network/virtualNetworks westus
testvnetstorageprm Microsoft.Storage/storageAccounts westus
testvnetstoragestd Microsoft.Storage/storageAccounts westus
3. Run the azure group deployment create cmdlet to deploy the new VNet by using the template and
parameter files you downloaded and modified above. The list shown after the output explains the
parameters used.
Expected output:
info: Executing command group create
info: Getting resource group TestRG
info: Creating resource group TestRG
info: Created resource group TestRG
info: Initializing template configurations and parameters
info: Creating a deployment
info: Created template deployment "azuredeploy"
data: Id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx/resourceGroups/TestRG
data: Name: TestRG
data: Location: westus
data: Provisioning State: Succeeded
data: Tags: null
data:
info: group create command OK
You can use an NSG to control traffic to one or more virtual machines (VMs), role instances, network adapters
(NICs), or subnets in your virtual network. An NSG contains access control rules that allow or deny traffic based
on traffic direction, protocol, source address and port, and destination address and port. The rules of an NSG can
be changed at any time, and changes are applied to all associated instances.
For more information about NSGs, visit what is an NSG.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models:
Azure Resource Manager and classic. Make sure you understand deployment models and tools before you work with any
Azure resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the classic deployment model. You can also create NSGs in the Resource Manager deployment
model.
Scenario
To better illustrate how to create NSGs, this document will use the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
The sample PowerShell commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, first build the test environment
by creating a VNet.
Expected output:
3. Create a security rule allowing access from the Internet to port 3389.
Expected output:
Name : NSG-FrontEnd
Location : Central US
Label : Front end subnet NSG
Rules :
Type: Inbound
Type: Outbound
4. Create a security rule allowing access from the Internet to port 80.
Expected output:
Name : NSG-FrontEnd
Location : Central US
Label : Front end subnet NSG
Rules :
Type: Inbound
Type: Outbound
Expected output:
2. Create a security rule allowing access from the front end subnet to port 1433 (default port used by SQL
Server).
Get-AzureNetworkSecurityGroup -Name "NSG-FrontEnd" `
| Set-AzureNetworkSecurityRule -Name rdp-rule `
-Action Allow -Protocol TCP -Type Inbound -Priority 100 `
-SourceAddressPrefix 192.168.1.0/24 -SourcePortRange '*' `
-DestinationAddressPrefix '*' -DestinationPortRange '1433'
Expected output:
Name : NSG-BackEnd
Location : Central US
Label : Back end subnet NSG
Rules :
Type: Inbound
Type: Outbound
3. Create a security rule blocking access from the subnet to the Internet.
Expected output:
Name : NSG-BackEnd
Location : Central US
Label : Back end subnet NSG
Rules :
Type: Inbound
Type: Outbound
You can use an NSG to control traffic to one or more virtual machines (VMs), role instances, network adapters
(NICs), or subnets in your virtual network. An NSG contains access control rules that allow or deny traffic based on
traffic direction, protocol, source address and port, and destination address and port. The rules of an NSG can be
changed at any time, and changes are applied to all associated instances.
For more information about NSGs, visit what is an NSG.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the classic deployment model. You can also create NSGs in the Resource Manager deployment
model.
Scenario
To better illustrate how to create NSGs, this document will use the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
The sample Azure CLI commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, first build the test environment
by creating a VNet.
Expected output:
Expected output:
info: Executing command network nsg create
info: Creating a network security group "NSG-FrontEnd"
info: Looking up the network security group "NSG-FrontEnd"
data: Name : NSG-FrontEnd
data: Location : West US
data: Security group rules:
data: Name Source IP Source Port Destination IP
Destination Port Protocol Type Action Prior
ity Default
data: --------------------------------- ------------------ ----------- --------------- --------
-------- -------- -------- ------ -----
--- -------
data: ALLOW VNET OUTBOUND VIRTUAL_NETWORK * VIRTUAL_NETWORK *
* Outbound Allow 65000
true
data: ALLOW VNET INBOUND VIRTUAL_NETWORK * VIRTUAL_NETWORK *
* Inbound Allow 65000
true
data: ALLOW AZURE LOAD BALANCER INBOUND AZURE_LOADBALANCER * * *
* Inbound Allow 65001
true
data: ALLOW INTERNET OUTBOUND * * INTERNET *
* Outbound Allow 65001
true
data: DENY ALL OUTBOUND * * * *
* Outbound Deny 65500
true
data: DENY ALL INBOUND * * * *
* Inbound Deny 65500
true
info: network nsg create command OK
Parameters:
-l (or --location). Azure region where the new NSG will be created. For our scenario, westus.
-n (or --name). Name for the new NSG. For our scenario, NSG-FrontEnd.
4. Run the azure network nsg rule create command to create a rule that allows access to port 3389 (RDP)
from the Internet.
azure network nsg rule create -a NSG-FrontEnd -n rdp-rule -c Allow -p Tcp -r Inbound -y 100 -f
Internet -o * -e * -u 3389
Expected output:
Parameters:
-a (or --nsg-name). Name of the NSG in which the rule will be created. For our scenario, NSG-
FrontEnd.
-n (or --name). Name for the new rule. For our scenario, rdp-rule.
-c (or --action). Access level for the rule (Deny or Allow).
-p (or --protocol). Protocol (Tcp, Udp, or *) for the rule.
-r (or --type). Direction of connection (Inbound or Outbound).
-y (or --priority). Priority for the rule.
-f (or --source-address-prefix). Source address prefix in CIDR or using default tags.
-o (or --source-port-range). Source port, or port range.
-e (or --destination-address-prefix). Destination address prefix in CIDR or using default tags.
-u (or --destination-port-range). Destination port, or port range.
5. Run the azure network nsg rule create command to create a rule that allows access to port 80 (HTTP) from
the Internet.
azure network nsg rule create -a NSG-FrontEnd -n web-rule -c Allow -p Tcp -r Inbound -y 200 -f
Internet -o * -e * -u 80
Expected putput:
6. Run the azure network nsg subnet add command to link the NSG to the front end subnet.
azure network nsg subnet add -a NSG-FrontEnd --vnet-name TestVNet --subnet-name FrontEnd
Expected output:
Expected output:
Parameters:
-l (or --location). Azure region where the new NSG will be created. For our scenario, westus.
-n (or --name). Name for the new NSG. For our scenario, NSG-FrontEnd.
2. Run the azure network nsg rule create command to create a rule that allows access to port 1433 (SQL)
from the front end subnet.
azure network nsg rule create -a NSG-BackEnd -n sql-rule -c Allow -p Tcp -r Inbound -y 100 -f
192.168.1.0/24 -o * -e * -u 1433
Expected output:
info: Executing command network nsg rule create
info: Looking up the network security group "NSG-BackEnd"
info: Creating a network security rule "sql-rule"
info: Looking up the network security group "NSG-BackEnd"
data: Name : sql-rule
data: Source address prefix : 192.168.1.0/24
data: Source Port : *
data: Destination address prefix : *
data: Destination Port : 1433
data: Protocol : TCP
data: Type : Inbound
data: Action : Allow
data: Priority : 100
info: network nsg rule create command OK
3. Run the azure network nsg rule create command to create a rule that denies access to the Internet.
azure network nsg rule create -a NSG-BackEnd -n web-rule -c Deny -p Tcp -r Outbound -y 200 -f * -o * -
e Internet -u 80
Expected putput:
4. Run the azure network nsg subnet add command to link the NSG to the back end subnet.
azure network nsg subnet add -a NSG-BackEnd --vnet-name TestVNet --subnet-name BackEnd
Expected output:
Although the use of system routes facilitates traffic automatically for your deployment, there are cases in which
you want to control the routing of packets through a virtual appliance. You can do so by creating user defined
routes that specify the next hop for packets flowing to a specific subnet to go to your virtual appliance instead, and
enabling IP forwarding for the VM running as the virtual appliance.
Some of the cases where virtual appliances can be used include:
Monitoring traffic with an intrusion detection system (IDS)
Controlling traffic with a firewall
For more information about UDR and IP forwarding, visit User Defined Routes and IP Forwarding.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the Resource Manager deployment model. You can also create UDRs in the classic deployment
model.
Scenario
To better illustrate how to create UDRs, this document will use the scenario below.
In this scenario you will create one UDR for the Front end subnet and another UDR for the Back end subnet , as
described below:
UDR-FrontEnd. The front end UDR will be applied to the FrontEnd subnet, and contain one route:
RouteToBackend. This route will send all traffic to the back end subnet to the FW1 virtual machine.
UDR-BackEnd. The back end UDR will be applied to the BackEnd subnet, and contain one route:
RouteToFrontend. This route will send all traffic to the front end subnet to the FW1 virtual machine.
The combination of these routes will ensure that all traffic destined from one subnet to another will be routed to
the FW1 virtual machine, which is being used as a virtual appliance. You also need to turn on IP forwarding for that
VM, to ensure it can receive traffic destined to other VMs.
The sample PowerShell commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, first build the test environment by
deploying this template, click Deploy to Azure, replace the default parameter values if necessary, and follow the
instructions in the portal.
2. Create a route table named UDR-FrontEnd in the westus region that contains the route.
3. Create a variable that contains the VNet where the subnet is. In our scenario, the VNet is named TestVNet.
WARNING
The output for the command above shows the content for the virtual network configuration object, which only exists
on the computer where you are running PowerShell. You need to run the Set-AzureVirtualNetwork cmdlet to save
these settings to Azure.
Expected output:
Name : TestVNet
ResourceGroupName : TestRG
Location : westus
Id : /subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
Name Value
=========== =====
displayName VNet
AddressSpace : {
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptions : {
"DnsServers": null
}
NetworkInterfaces : null
Subnets : [
...,
{
"Name": "FrontEnd",
"Etag": "W/\"[Id]\"",
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets
/FrontEnd",
"AddressPrefix": "192.168.1.0/24",
"IpConfigurations": [
{
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/NICWEB2/ipConfigurations/ipconf
ig1"
},
{
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/NICWEB1/ipConfigurations/ipconf
ig1"
}
],
"NetworkSecurityGroup": {
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkSecurityGroups/NSG-FrontEnd"
},
"RouteTable": {
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/routeTables/UDR-FrontEnd"
},
"ProvisioningState": "Succeeded"
},
...
]
2. Create a route table named UDR-BackEnd in the uswest region that contains the route created above.
Expected output:
Name : TestVNet
ResourceGroupName : TestRG
Location : westus
Id : /subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
Name Value
=========== =====
displayName VNet
AddressSpace : {
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptions : {
"DnsServers": null
}
NetworkInterfaces : null
Subnets : [
...,
{
"Name": "BackEnd",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/BackEnd",
"AddressPrefix": "192.168.2.0/24",
"IpConfigurations": [
{
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/NICSQL2/ipConfigurations/ipconf
ig1"
},
{
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/NICSQL1/ipConfigurations/ipconf
ig1"
}
],
"NetworkSecurityGroup": {
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkSecurityGroups/NSG-BacEnd"
},
"RouteTable": {
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/routeTables/UDR-BackEnd"
},
"ProvisioningState": "Succeeded"
}
]
Expected output:
Name : NICFW1
ResourceGroupName : TestRG
Location : westus
Id : /subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/NICFW1
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
Name Value
=========== =======================
displayName NetworkInterfaces - DMZ
VirtualMachine : {
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/FW1"
}
IpConfigurations : [
{
"Name": "ipconfig1",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/NICFW1/ipConfigurations/ipconfi
g1",
"PrivateIpAddress": "192.168.0.4",
"PrivateIpAllocationMethod": "Static",
"Subnet": {
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/DMZ"
},
"PublicIpAddress": {
"Id": "/subscriptions/[Subscription
Id]/resourceGroups/TestRG/providers/Microsoft.Network/publicIPAddresses/PIPFW1"
},
"LoadBalancerBackendAddressPools": [],
"LoadBalancerInboundNatRules": [],
"ProvisioningState": "Succeeded"
}
]
DnsSettings : {
"DnsServers": [],
"AppliedDnsServers": [],
"InternalDnsNameLabel": null,
"InternalFqdn": null
}
EnableIPForwarding : True
NetworkSecurityGroup : null
Primary : True
Create User-Defined Routes (UDR) using the Azure
CLI 2.0
8/8/2017 5 min to read Edit Online
Scenario
To better illustrate how to create NSGs, this document will use the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
Although the use of system routes facilitates traffic automatically for your deployment, there are cases in which
you want to control the routing of packets through a virtual appliance. You can do so by creating user defined
routes that specify the next hop for packets flowing to a specific subnet to go to your virtual appliance instead, and
enabling IP forwarding for the VM running as the virtual appliance.
Some of the cases where virtual appliances can be used include:
Monitoring traffic with an intrusion detection system (IDS)
Controlling traffic with a firewall
For more information about UDR and IP forwarding, visit User Defined Routes and IP Forwarding.
Scenario
To better illustrate how to create UDRs, this document will use the scenario below.
In this scenario you will create one UDR for the Front end subnet and another UDR for the Back end subnet , as
described below:
UDR-FrontEnd. The front end UDR will be applied to the FrontEnd subnet, and contain one route:
RouteToBackend. This route will send all traffic to the back end subnet to the FW1 virtual machine.
UDR-BackEnd. The back end UDR will be applied to the BackEnd subnet, and contain one route:
RouteToFrontend. This route will send all traffic to the front end subnet to the FW1 virtual machine.
The combination of these routes will ensure that all traffic destined from one subnet to another will be routed to
the FW1 virtual machine, which is being used as a virtual appliance. You also need to turn on IP forwarding for that
VM, to ensure it can receive traffic destined to other VMs.
The sample Azure CLI commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, first build the test environment by
deploying this template, click Deploy to Azure, replace the default parameter values if necessary, and follow the
instructions in the portal.
Output:
{
"etag": "W/\"<guid>\"",
"id": "/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/routeTables/UDR-
FrontEnd",
"location": "centralus",
"name": "UDR-FrontEnd",
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"routes": [],
"subnets": null,
"tags": null,
"type": "Microsoft.Network/routeTables"
}
2. Create a route that sends all traffic destined to the back-end subnet (192.168.2.0/24) to the FW1 VM
(192.168.0.4) using the az network route-table route create command:
Output:
{
"addressPrefix": "192.168.2.0/24",
"etag": "W/\"<guid>\"",
"id": "/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/routeTables/UDR-
FrontEnd/routes/RouteToBackEnd",
"name": "RouteToBackEnd",
"nextHopIpAddress": "192.168.0.4",
"nextHopType": "VirtualAppliance",
"provisioningState": "Succeeded",
"resourceGroup": "testrg"
}
Parameters:
--route-table-name. Name of the route table where the route will be added. For our scenario, UDR-
FrontEnd.
--address-prefix. Address prefix for the subnet where packets are destined to. For our scenario,
192.168.2.0/24.
--next-hop-type. Type of object traffic will be sent to. Possible values are VirtualAppliance,
VirtualNetworkGateway, VNETLocal, Internet, or None.
--next-hop-ip-address. IP address for next hop. For our scenario, 192.168.0.4.
3. Run the az network vnet subnet update command to associate the route table created above with the
FrontEnd subnet:
Output:
{
"addressPrefix": "192.168.1.0/24",
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/virtualNetworks/testvnet/subne
ts/FrontEnd",
"ipConfigurations": null,
"name": "FrontEnd",
"networkSecurityGroup": null,
"provisioningState": "Succeeded",
"resourceGroup": "testrg",
"resourceNavigationLinks": null,
"routeTable": {
"etag": null,
"id": "/subscriptions/<guid>/resourceGroups/testrg/providers/Microsoft.Network/routeTables/UDR-
FrontEnd",
"location": null,
"name": null,
"provisioningState": null,
"resourceGroup": "testrg",
"routes": null,
"subnets": null,
"tags": null,
"type": null
}
}
Parameters:
--vnet-name. Name of the VNet where the subnet is located. For our scenario, TestVNet.
2. Run the following command to create a route in the route table to send all traffic destined to the front-end
subnet (192.168.1.0/24) to the FW1 VM (192.168.0.4):
3. Run the following command to associate the route table with the BackEnd subnet:
Output:
false
You can examine the output streamed to the console, or just retest for the specific enableIpForwarding
value:
Output:
true
Parameters:
--ip-forwarding: true or false.
Create User-Defined Routes (UDR) using a template
6/27/2017 7 min to read Edit Online
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article. This article covers
the Resource Manager deployment model.
Scenario
To better illustrate how to create UDRs, this document will use the scenario below.
In this scenario you will create one UDR for the Front end subnet and another UDR for the Back end subnet , as
described below:
UDR-FrontEnd. The front end UDR will be applied to the FrontEnd subnet, and contain one route:
RouteToBackend. This route will send all traffic to the back end subnet to the FW1 virtual machine.
UDR-BackEnd. The back end UDR will be applied to the BackEnd subnet, and contain one route:
RouteToFrontend. This route will send all traffic to the front end subnet to the FW1 virtual machine.
The combination of these routes will ensure that all traffic destined from one subnet to another will be routed to
the FW1 virtual machine, which is being used as a virtual appliance. You also need to turn on IP forwarding for
that VM, to ensure it can receive traffic destined to other VMs.
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/routeTables",
"name": "[parameters('frontEndRouteTableName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "UDR - FrontEnd"
},
"properties": {
"routes": [
{
"name": "RouteToBackEnd",
"properties": {
"addressPrefix": "[parameters('backEndSubnetPrefix')]",
"nextHopType": "VirtualAppliance",
"nextHopIpAddress": "[parameters('vmaIpAddress')]"
}
}
]
To associate the UDR to the front-end subnet, you have to change the subnet definition in the template, and use
the reference id for the UDR.
"subnets": [
"name": "[parameters('frontEndSubnetName')]",
"properties": {
"addressPrefix": "[parameters('frontEndSubnetPrefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('frontEndNSGName'))]"
},
"routeTable": {
"id": "[resourceId('Microsoft.Network/routeTables', parameters('frontEndRouteTableName'))]"
}
},
Notice the same being done for the back-end NSG and the back-end subnet in the template.
You also need to ensure that the FW1 VM has the IP forwarding property enabled on the NIC that will be used to
receive and forward packets. The section below shows the definition of the NIC for FW1 in the azuredeploy-nsg-
udr.json file, based on the scenario above.
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkInterfaces",
"location": "[variables('location')]",
"tags": {
"displayName": "NetworkInterfaces - DMZ"
},
"name": "[concat(variables('fwVMSettings').nicName, copyindex(1))]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('fwVMSettings').pipName, copyindex(1))]",
"[concat('Microsoft.Resources/deployments/', 'vnetTemplate')]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"enableIPForwarding": true,
"privateIPAllocationMethod": "Static",
"privateIPAddress": "[concat('192.168.0.',copyindex(4))]",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',concat(variables('fwVMSettings').pipName,
copyindex(1)))]"
},
"subnet": {
"id": "[variables('dmzSubnetRef')]"
}
}
}
]
},
"copy": {
"name": "fwniccount",
"count": "[parameters('fwCount')]"
}
Expected output:
ResourceGroupName : TestRG
Location : westus
ProvisioningState : Succeeded
Tags :
Permissions :
Actions NotActions
======= ==========
*
Resources :
Name Type Location
================== ======================================= ========
ASFW Microsoft.Compute/availabilitySets westus
ASSQL Microsoft.Compute/availabilitySets westus
ASWEB Microsoft.Compute/availabilitySets westus
FW1 Microsoft.Compute/virtualMachines westus
SQL1 Microsoft.Compute/virtualMachines westus
SQL2 Microsoft.Compute/virtualMachines westus
WEB1 Microsoft.Compute/virtualMachines westus
WEB2 Microsoft.Compute/virtualMachines westus
NICFW1 Microsoft.Network/networkInterfaces westus
NICSQL1 Microsoft.Network/networkInterfaces westus
NICSQL2 Microsoft.Network/networkInterfaces westus
NICWEB1 Microsoft.Network/networkInterfaces westus
NICWEB2 Microsoft.Network/networkInterfaces westus
NSG-BackEnd Microsoft.Network/networkSecurityGroups westus
NSG-FrontEnd Microsoft.Network/networkSecurityGroups westus
PIPFW1 Microsoft.Network/publicIPAddresses westus
PIPSQL1 Microsoft.Network/publicIPAddresses westus
PIPSQL2 Microsoft.Network/publicIPAddresses westus
PIPWEB1 Microsoft.Network/publicIPAddresses westus
PIPWEB2 Microsoft.Network/publicIPAddresses westus
UDR-BackEnd Microsoft.Network/routeTables westus
UDR-FrontEnd Microsoft.Network/routeTables westus
TestVNet Microsoft.Network/virtualNetworks westus
testvnetstorageprm Microsoft.Storage/storageAccounts westus
testvnetstoragestd Microsoft.Storage/storageAccounts westus
4. Run the following command to deploy the new VNet by using the template and parameter files you
downloaded and modified above:
Expected output:
5. Run the following command to view the resources created in the new resource group:
Expected result:
TIP
If you do not see all the resources, run the azure group deployment show command to ensure the provisioning state of
the deployment is Succeded.
Control routing and use virtual appliances (classic)
using PowerShell
6/27/2017 3 min to read Edit Online
Although the use of system routes facilitates traffic automatically for your deployment, there are cases in which
you want to control the routing of packets through a virtual appliance. You can do so by creating user defined
routes that specify the next hop for packets flowing to a specific subnet to go to your virtual appliance instead, and
enabling IP forwarding for the VM running as the virtual appliance.
Some of the cases where virtual appliances can be used include:
Monitoring traffic with an intrusion detection system (IDS)
Controlling traffic with a firewall
For more information about UDR and IP forwarding, visit User Defined Routes and IP Forwarding.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by selecting an option at the top of this article. This article
covers the classic deployment model.
Scenario
To better illustrate how to create UDRs, this document will use the scenario below.
In this scenario you will create one UDR for the Front end subnet and another UDR for the Back end subnet , as
described below:
UDR-FrontEnd. The front end UDR will be applied to the FrontEnd subnet, and contain one route:
RouteToBackend. This route will send all traffic to the back end subnet to the FW1 virtual machine.
UDR-BackEnd. The back end UDR will be applied to the BackEnd subnet, and contain one route:
RouteToFrontend. This route will send all traffic to the front end subnet to the FW1 virtual machine.
The combination of these routes will ensure that all traffic destined from one subnet to another will be routed to
the FW1 virtual machine, which is being used as a virtual appliance. You also need to turn on IP forwarding for
that VM, to ensure it can receive traffic destined to other VMs.
The sample Azure PowerShell commands below expect a simple environment already created based on the
scenario above. If you want to run the commands as they are displayed in this document, create the environment
shown in create a VNet (classic) using PowerShell.
2. Run the following command to create a route in the route table to send all traffic destined to the back-end
subnet (192.168.2.0/24) to the FW1 VM (192.168.0.4):
Get-AzureRouteTable UDR-FrontEnd `
|Set-AzureRoute -RouteName RouteToBackEnd -AddressPrefix 192.168.2.0/24 `
-NextHopType VirtualAppliance `
-NextHopIpAddress 192.168.0.4
3. Run the following command to associate the route table with the FrontEnd subnet:
2. Run the following command to create a route in the route table to send all traffic destined to the front-end
subnet (192.168.1.0/24) to the FW1 VM (192.168.0.4):
Get-AzureRouteTable UDR-BackEnd
| Set-AzureRoute `
-RouteName RouteToFrontEnd `
-AddressPrefix 192.168.1.0/24 `
-NextHopType VirtualAppliance `
-NextHopIpAddress 192.168.0.4
3. Run the following command to associate the route table with the BackEnd subnet:
Set-AzureSubnetRouteTable -VirtualNetworkName TestVNet `
-SubnetName BackEnd `
-RouteTableName UDR-BackEnd
2. Run the following command to enable IP forwarding for the FW1 VM:
Although the use of system routes facilitates traffic automatically for your deployment, there are cases in which
you want to control the routing of packets through a virtual appliance. You can do so by creating user defined
routes that specify the next hop for packets flowing to a specific subnet to go to your virtual appliance instead, and
enabling IP forwarding for the VM running as the virtual appliance.
Some of the cases where virtual appliances can be used include:
Monitoring traffic with an intrusion detection system (IDS)
Controlling traffic with a firewall
For more information about UDR and IP forwarding, visit User Defined Routes and IP Forwarding.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the classic deployment model. You can also control routing and use virtual appliances in the
Resource Manager deployment model.
Scenario
To better illustrate how to create UDRs, this document will use the scenario below.
In this scenario you will create one UDR for the Front end subnet and another UDR for the Back end subnet , as
described below:
UDR-FrontEnd. The front end UDR will be applied to the FrontEnd subnet, and contain one route:
RouteToBackend. This route will send all traffic to the back end subnet to the FW1 virtual machine.
UDR-BackEnd. The back end UDR will be applied to the BackEnd subnet, and contain one route:
RouteToFrontend. This route will send all traffic to the front end subnet to the FW1 virtual machine.
The combination of these routes will ensure that all traffic destined from one subnet to another will be routed to
the FW1 virtual machine, which is being used as a virtual appliance. You also need to turn on IP forwarding for
that VM, to ensure it can receive traffic destined to other VMs.
The sample Azure CLI commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, create the environment shown in
create a VNet (classic) using the Azure CLI.
Output:
2. Run the following command to create a route table for the front-end subnet:
Output:
Parameters:
-l (or --location). Azure region where the new NSG will be created. For our scenario, westus.
-n (or --name). Name for the new NSG. For our scenario, NSG-FrontEnd.
3. Run the following command to create a route in the route table to send all traffic destined to the back-end
subnet (192.168.2.0/24) to the FW1 VM (192.168.0.4):
Output:
Parameters:
-r (or --route-table-name). Name of the route table where the route will be added. For our scenario,
UDR-FrontEnd.
-a (or --address-prefix). Address prefix for the subnet where packets are destined to. For our scenario,
192.168.2.0/24.
-t (or --next-hop-type). Type of object traffic will be sent to. Possible values are VirtualAppliance,
VirtualNetworkGateway, VNETLocal, Internet, or None.
-p (or --next-hop-ip-address). IP address for next hop. For our scenario, 192.168.0.4.
4. Run the following command to associate the route table created with the FrontEnd subnet:
Output:
Parameters:
-t (or --vnet-name). Name of the VNet where the subnet is located. For our scenario, TestVNet.
-n (or --subnet-name. Name of the subnet the route table will be added to. For our scenario, FrontEnd.
2. Run the following command to create a route in the route table to send all traffic destined to the front-end
subnet (192.168.1.0/24) to the FW1 VM (192.168.0.4):
3. Run the following command to associate the route table with the BackEnd subnet:
In this tutorial, you learn to create a virtual network peering between virtual networks created through Resource
Manager. Both virtual networks exist in the same subscription. Peering two virtual networks enables resources in
different virtual networks to communicate with each other with the same bandwidth and latency as though the
resources were in the same virtual network. Learn more about Virtual network peering.
The steps to create a virtual network peering are different, depending on whether the virtual networks are in the
same, or different, subscriptions, and which Azure deployment model the virtual networks are created through.
Learn how to create a virtual network peering in other scenarios by clicking the scenario from the following table:
A virtual network peering cannot be created between two virtual networks deployed through the classic
deployment model. A virtual network peering can only be created between two virtual networks that exist in the
same Azure region. If you need to connect virtual networks that were both created through the classic deployment
model, or that exist in different Azure regions, you can use an Azure VPN Gateway to connect the virtual networks.
You can use the Azure portal, the Azure command-line interface (CLI), Azure PowerShell, or an Azure Resource
Manager template to create a virtual network peering. Click any of the previous tool links to go directly to the steps
for creating a virtual network peering using your tool of choice.
#!/bin/bash
3. After the script executes, review the peerings for each virtual network.
az network vnet peering list \
--resource-group myResourceGroup \
--vnet-name myVnet1 \
--output table
Run the previous command again, replacing myVnet1 with myVnet2. The output of both commands shows
Connected in the PeeringState column.
Any Azure resources you create in either virtual network are now able to communicate with each other
through their IP addresses. If you're using default Azure name resolution for the virtual networks, the
resources in the virtual networks are not able to resolve names across the virtual networks. If you want to
resolve names across virtual networks in a peering, you must create your own DNS server. Learn how to set
up Name resolution using your own DNS server.
4. Optional: Though creating virtual machines is not covered in this tutorial, you can create a virtual machine
in each virtual network and connect from one virtual machine to the other, to validate connectivity.
5. Optional: To delete the resources that you create in this tutorial, complete the steps in Delete resources in this
article.
5. Create a virtual network peering between the two virtual networks. Copy the following script, paste in to
PowerShell, and then press Enter after the last line appears on the screen:
# Peer VNet1 to VNet2.
Add-AzureRmVirtualNetworkPeering `
-Name 'myVnet1ToMyVnet2' `
-VirtualNetwork $vnet1 `
-RemoteVirtualNetworkId $vnet2.Id
6. To review the subnets for the virtual network, copy the following command, paste in to PowerShell, and
then press Enter :
Get-AzureRmVirtualNetworkPeering `
-ResourceGroupName myResourceGroup `
-VirtualNetworkName myVnet1 `
| Format-Table VirtualNetworkName, PeeringState
Run the previous command again, replacing myVnet1 with myVnet2. The output of both commands shows
Connected in the PeeringState column.
7. Optional: Though creating virtual machines is not covered in this tutorial, you can create a virtual machine in
each virtual network and connect from one virtual machine to the other, to validate connectivity.
8. Optional: To delete the resources that you create in this tutorial, complete the steps in Delete resources in this
article.
Any Azure resources you create in either virtual network are now able to communicate with each other through
their IP addresses. If you're using default Azure name resolution for the virtual networks, the resources in the
virtual networks are not able to resolve names across the virtual networks. If you want to resolve names across
virtual networks in a peering, you must create your own DNS server. Learn how to set up Name resolution using
your own DNS server.
Permissions
The accounts you use to create a virtual network peering must have the necessary role or permissions. For
example, if you were peering two virtual networks named VNet1 and VNet2, your account must be assigned the
following minimum role or permissions for each virtual network:
Learn more about built-in roles and assigning specific permissions to custom roles (Resource Manager only).
Delete resources
When you've finished this tutorial, you might want to delete the resources you created in the tutorial, so you don't
incur usage charges. Deleting a resource group also deletes all resources that are in the resource group.
Azure portal
1. In the portal search box, enter myResourceGroup. In the search results, click myResourceGroup.
2. On the myResourceGroup blade, click the Delete icon.
3. To confirm the deletion, in the TYPE THE RESOURCE GROUP NAME box, enter myResourceGroup, and then
click Delete.
Azure CLI
Enter the following command:
PowerShell
Enter the following command:
Next steps
Thoroughly familiarize yourself with important virtual network peering constraints and behaviors before
creating a virtual network peering for production use.
Learn about all virtual network peering settings.
Learn how to create a hub and spoke network topology with virtual network peering.
Create a virtual network peering - Resource
Manager, different subscriptions
8/30/2017 17 min to read Edit Online
In this tutorial, you learn to create a virtual network peering between virtual networks created through Resource
Manager. The virtual networks exist in different subscriptions. Peering two virtual networks enables resources in
different virtual networks to communicate with each other with the same bandwidth and latency as though the
resources were in the same virtual network. Learn more about Virtual network peering.
The steps to create a virtual network peering are different, depending on whether the virtual networks are in the
same, or different, subscriptions, and which Azure deployment model the virtual networks are created through.
Learn how to create a virtual network peering in other scenarios by clicking the scenario from the following table:
A virtual network peering cannot be created between two virtual networks deployed through the classic
deployment model. A virtual network peering can only be created between two virtual networks that exist in the
same Azure region. When creating a virtual network peering between virtual networks that exist in different
subscriptions, the subscriptions must both be associated to the same Azure Active Directory tenant. If you don't
already have an Azure Active Directory tenant, you can quickly create one. If you need to connect virtual networks
that were both created through the classic deployment model, or that exist in different Azure regions, or that exist
in subscriptions associated to different Azure Active Directory tenants, you can use an Azure VPN Gateway to
connect the virtual networks.
You can use the Azure portal, the Azure command-line interface (CLI), Azure PowerShell, or an Azure Resource
Manager template to create a virtual network peering. Click any of the previous tool links to go directly to the steps
for creating a virtual network peering using your tool of choice.
The permission assignment for UserB is not a requirement. Peering can be established even if users
individually raise peering requests for their respective virtual networks, as long as the requests match.
Adding a privileged user of myVNetB as a network contributor in the local virtual network makes it easier to
do the setup.
3. Log out of Azure as UserA using the az logout command, then log in to Azure as UserB. The account you log
in with must have the necessary permissions to create a virtual network peering. See the Permissions section of
this article for details.
4. Create myVnetB. Copy the script contents in step 2 to a text editor on your PC. Replace <SubscriptionA-Id>
with the ID of SubscriptionB. Change 10.0.0.0/16 to 10.1.0.0/16, change all As to B, and all Bs to A. Copy the
modified script, paste it in to your CLI session, and press Enter .
5. Log out of Azure as UserB and log in to Azure as UserA.
6. Create a virtual network peering from myVnetA to myVnetB. Copy the following script contents to a text
editor on your PC. Replace <SubscriptionB-Id> with the ID of SubscriptionB. To execute the script, copy the
modified script, paste it into your CLI session, and press Enter.
The state is Initiated. It changes to Connected once you create the peering to myVnetA from myVnetB.
8. Log out UserA from Azure and log in to Azure as UserB.
9. Create the peering from myVnetB to myVnetA. Copy the script contents in step 6 to a text editor on your PC.
Replace <SubscriptionB-Id> with the ID for SubscriptionA and change all As to B and all Bs to A. Once you've
made the changes, copy the modified script, paste it into your CLI session, and press Enter .
10. View the peering state of myVnetB. Copy the script contents in step 7 to a text editor on your PC. Change A
to B for the resource group and virtual network names, copy the script, paste the modified script in to your
CLI session, and then press Enter . The peering state is Connected. The peering state of myVnetA changes
to Connected after you've created the peering from myVnetB to myVnetA. You can log UserA back in to
Azure and complete step 7 again to verify the peering state of myVnetA.
NOTE
The peering is not established until the peering state is Connected for both virtual networks.
11. Optional: Though creating virtual machines is not covered in this tutorial, you can create a virtual machine
in each virtual network and connect from one virtual machine to the other, to validate connectivity.
12. Optional: To delete the resources that you create in this tutorial, complete the steps in Delete resources in this
article.
Any Azure resources you create in either virtual network are now able to communicate with each other through
their IP addresses. If you're using default Azure name resolution for the virtual networks, the resources in the
virtual networks are not able to resolve names across the virtual networks. If you want to resolve names across
virtual networks in a peering, you must create your own DNS server. Learn how to set up Name resolution using
your own DNS server.
The permission assignment for UserB is not a requirement. Peering can be established even if users
individually raise peering requests for their respective virtual networks, as long as the requests match.
Adding a privileged user of the other virtual network as a user in the local virtual network makes it easier to
do the setup.
5. Log out UserA from Azure and log in UserB. The account you log in with must have the necessary permissions
to create a virtual network peering. See the Permissions section of this article for details.
6. Copy the script contents in step 4 to a text editor on your PC. Replace <SubscriptionA-Id> with the ID for
subscription B. Change 10.0.0.0/16 to 10.1.0.0/16. Change all As to B and all Bs to A. To execute the script, copy
the modified script, paste into PowerShell, and then press Enter .
7. Log out UserB from Azure and log in UserA.
8. Create the peering from myVnetA to myVnetB. Copy the following script to a text editor on your PC. Replace
<SubscriptionB-Id> with the ID of subscription B. To execute the script, copy the modified script, paste in to
PowerShell, and then press Enter .
Get-AzureRmVirtualNetworkPeering `
-ResourceGroupName myResourceGroupA `
-VirtualNetworkName myVnetA `
| Format-Table VirtualNetworkName, PeeringState
The state is Initiated. It changes to Connected once you setup the peering to myVnetA from myVnetB.
10. Log out UserA from Azure and log in UserB.
11. Create the peering from myVnetB to myVnetA. Copy the script contents in step 8 to a text editor on your PC.
Replace <SubscriptionB-Id> with the ID of subscription A and change all As to B and all Bs to A. To execute the
script, copy the modified script, paste it in to PowerShell, and then press Enter .
12. View the peering state of myVnetB. Copy the script contents in step 9 to a text editor on your PC. Change A
to B for the resource group and virtual network names. To execute the script, paste the modified script into
PowerShell, and then press Enter . The state is Connected. The peering state of myVnetA changes to
Connected after you've created the peering from myVnetB to myVnetA. You can log UserA back in to
Azure and complete step 9 again to verify the peering state of myVnetA.
NOTE
The peering is not established until the peering state is Connected for both virtual networks.
Any Azure resources you create in either virtual network are now able to communicate with each other
through their IP addresses. If you're using default Azure name resolution for the virtual networks, the
resources in the virtual networks are not able to resolve names across the virtual networks. If you want to
resolve names across virtual networks in a peering, you must create your own DNS server. Learn how to set
up Name resolution using your own DNS server.
13. Optional: Though creating virtual machines is not covered in this tutorial, you can create a virtual machine
in each virtual network and connect from one virtual machine to the other, to validate connectivity.
14. Optional: To delete the resources that you create in this tutorial, complete the steps in Delete resources in this
article.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
},
"resources": [
{
"apiVersion": "2016-06-01",
"type": "Microsoft.Network/virtualNetworks/virtualNetworkPeerings",
"name": "myVnetA/myVnetAToMyVnetB",
"location": "[resourceGroup().location]",
"properties": {
"allowVirtualNetworkAccess": true,
"allowForwardedTraffic": false,
"allowGatewayTransit": false,
"useRemoteGateways": false,
"remoteVirtualNetwork": {
"id": "/subscriptions/<subscription
ID>/resourceGroups/PeeringTest/providers/Microsoft.Network/virtualNetworks/myVnetB"
}
}
}
]
}
3. Log into Azure as UserA and deploy the template using the portal, PowerShell, or the Azure CLI. Specify the
file name you saved the example json text in step 2 to.
4. Copy the example json from step 2 to a file on your computer and make changes to the lines that begin with:
name: Change myVnetA/myVnetAToMyVnetB to myVnetB/myVnetBToMyVnetA.
id: Replace <subscription ID> with UserB's subscription ID and change myVnetB to myVnetA.
5. Complete step 3 again, logged into Azure as UserB.
6. Optional: Though creating virtual machines is not covered in this tutorial, you can create a virtual machine in
each virtual network and connect from one virtual machine to the other, to validate connectivity.
7. Optional: To delete the resources that you create in this tutorial, complete the steps in the Delete resources
section of this article, using either the Azure portal, PowerShell, or the Azure CLI.
Permissions
The accounts you use to create a virtual network peering must have the necessary role or permissions. For
example, if you were peering two virtual networks named myVnetA and myVnetB, your account must be
assigned the following minimum role or permissions for each virtual network:
Learn more about built-in roles and assigning specific permissions to custom roles (Resource Manager only).
Delete resources
When you've finished this tutorial, you might want to delete the resources you created in the tutorial, so you don't
incur usage charges. Deleting a resource group also deletes all resources that are in the resource group.
Azure portal
1. Log in to the Azure portal as UserA.
2. In the portal search box, enter myResourceGroupA. In the search results, click myResourceGroupA.
3. On the myResourceGroupA blade, click the Delete icon.
4. To confirm the deletion, in the TYPE THE RESOURCE GROUP NAME box, enter myResourceGroupA, and
then click Delete.
5. Log out of the portal as UserA and log in as UserB.
6. Complete steps 2-4 for myResourceGroupB.
Azure CLI
1. Log in to Azure as UserA and execute the following command:
PowerShell
1. Log in to Azure as UserA and execute the following command:
Remove-AzureRmResourceGroup -Name myResourceGroupA -force
Next steps
Thoroughly familiarize yourself with important virtual network peering constraints and behaviors before
creating a virtual network peering for production use.
Learn about all virtual network peering settings.
Learn how to create a hub and spoke network topology with virtual network peering.
Create a virtual network peering - different
deployment models, same subscription
7/26/2017 11 min to read Edit Online
In this tutorial, you learn to create a virtual network peering between virtual networks created through different
deployment models. Both virtual networks exist in the same subscription. Peering two virtual networks enables
resources in different virtual networks to communicate with each other with the same bandwidth and latency as
though the resources were in the same virtual network. Learn more about Virtual network peering.
The steps to create a virtual network peering are different, depending on whether the virtual networks are in the
same, or different, subscriptions, and which Azure deployment model the virtual networks are created through.
Learn how to create a virtual network peering in other scenarios by clicking the scenario from the following table:
A virtual network peering cannot be created between two virtual networks deployed through the classic
deployment model. A virtual network peering can only be created between two virtual networks that exist in the
same Azure region. If you need to connect virtual networks that were both created through the classic deployment
model, or that exist in different Azure regions, you can use an Azure VPN Gateway to connect the virtual networks.
You can use the Azure portal, the Azure command-line interface (CLI), or Azure PowerShell to create a virtual
network peering. Click any of the previous tool links to go directly to the steps for creating a virtual network
peering using your tool of choice.
azure network vnet create --vnet myVnet2 --address-space 10.1.0.0 --cidr 16 --location "East US"
5. Create a resource group and a virtual network (Resource Manager). You can use either the CLI 1.0 or 2.0
(install). In this tutorial, the CLI 2.0 is used to create the virtual network (Resource Manager), since 2.0 must
be used to create the peering. Execute the following bash CLI script from your local machine with the CLI
2.0.4 or later installed. For options on running bash CLI scripts on Windows client, see Running the Azure
CLI in Windows. You can also run the script using the Azure Cloud Shell. The Azure Cloud Shell is a free
Bash shell that you can run directly within the Azure portal. It has the Azure CLI preinstalled and configured
to use with your account. Click the Try it button in the script that follows, which invokes a Cloud Shell that
logs you can log in to your Azure account with. To execute the script, click the Copy button and paste, the
contents into your Cloud Shell, then press Enter .
#!/bin/bash
6. Create a virtual network peering between the two virtual networks created through the different
deployment models. Copy the following script to a text editor on your PC. Replace <subscription id> with
your subscription Id. If you don't know your subscription Id, enter the az account show command. The
value for id in the output is your subscription Id. Paste the modified script in to your CLI session, and then
press Enter .
7. After the script executes, review the peering for the virtual network (Resource Manager). Copy the following
command, paste it in your CLI session, and then press Enter :
WARNING
Importing a changed network configuration file can cause changes to existing virtual networks (classic) in your
subscription. Ensure you only add the previous virtual network and that you don't change or remove any existing
virtual networks from your subscription.
5. Log in to Azure to create the virtual network (Resource Manager) by entering the login-azurermaccount
command. The account you log in with must have the necessary permissions to create a virtual network
peering. See the Permissions section of this article for details.
6. Create a resource group and a virtual network (Resource Manager). Copy the script, paste it into
PowerShell, and then press Enter .
7. Create a virtual network peering between the two virtual networks created through the different
deployment models. Copy the following script to a text editor on your PC. Replace <subscription id> with
your subscription Id. If you don't know your subscription Id, enter the Get-AzureRmSubscription command
to view it. The value for Id in the returned output is your subscription ID. To execute the script, copy the
modified script from your text editor, then right-click in your PowerShell session, and then press Enter .
# Peer VNet1 to VNet2.
Add-AzureRmVirtualNetworkPeering `
-Name myVnet1ToMyVnet2 `
-VirtualNetwork $vnet1 `
-RemoteVirtualNetworkId /subscriptions/<subscription Id>/resourceGroups/Default-
Networking/providers/Microsoft.ClassicNetwork/virtualNetworks/myVnet2
8. After the script executes, review the peering for the virtual network (Resource Manager). Copy the following
command, paste it in your PowerShell session, and then press Enter :
Get-AzureRmVirtualNetworkPeering `
-ResourceGroupName myResourceGroup `
-VirtualNetworkName myVnet1 `
| Format-Table VirtualNetworkName, PeeringState
Permissions
The accounts you use to create a virtual network peering must have the necessary role or permissions. For
example, if you were peering two virtual networks named myVnet1 and myVnet2, your account must be assigned
the following minimum role or permissions for each virtual network:
Learn more about built-in roles and assigning specific permissions to custom roles (Resource Manager only).
Delete resources
When you've finished this tutorial, you might want to delete the resources you created in the tutorial, so you don't
incur usage charges. Deleting a resource group also deletes all resources that are in the resource group.
Azure portal
1. In the portal search box, enter myResourceGroup. In the search results, click myResourceGroup.
2. On the myResourceGroup blade, click the Delete icon.
3. To confirm the deletion, in the TYPE THE RESOURCE GROUP NAME box, enter myResourceGroup, and then
click Delete.
Azure CLI
1. Use the Azure CLI 2.0 to delete the virtual network (Resource Manager) with the following command:
2. Use the Azure CLI 1.0 to delete the virtual network (classic) with the following commands:
PowerShell
1. Enter the following command to delete the virtual network (Resource Manager):
2. To delete the virtual network (classic) with PowerShell, you must modify an existing network configuration
file. Learn how to export, update, and import network configuration files. Remove the following
VirtualNetworkSite element for the virtual network used in this tutorial:
WARNING
Importing a changed network configuration file can cause changes to existing virtual networks (classic) in your
subscription. Ensure you only remove the previous virtual network and that you don't change or remove any other
existing virtual networks from your subscription.
Next steps
Thoroughly familiarize yourself with important virtual network peering constraints and behaviors before
creating a virtual network peering for production use.
Learn about all virtual network peering settings.
Learn how to create a hub and spoke network topology with virtual network peering.
Create a virtual network peering - different
deployment models and subscriptions
7/26/2017 16 min to read Edit Online
In this tutorial, you learn to create a virtual network peering between virtual networks created through different
deployment models. The virtual networks exist in different subscriptions. Peering two virtual networks enables
resources in different virtual networks to communicate with each other with the same bandwidth and latency as
though the resources were in the same virtual network. Learn more about Virtual network peering.
The steps to create a virtual network peering are different, depending on whether the virtual networks are in the
same, or different, subscriptions, and which Azure deployment model the virtual networks are created through.
Learn how to create a virtual network peering in other scenarios by clicking the scenario from the following table:
A virtual network peering cannot be created between two virtual networks deployed through the classic
deployment model. A virtual network peering can only be created between two virtual networks that exist in the
same Azure region. When creating a virtual network peering between virtual networks that exist in different
subscriptions, the subscriptions must both be associated to the same Azure Active Directory tenant. If you don't
already have an Azure Active Directory tenant, you can quickly create one. If you need to connect virtual networks
that were both created through the classic deployment model, or that exist in different Azure regions, or that exist
in subscriptions associated to different Azure Active Directory tenants, you can use an Azure VPN Gateway to
connect the virtual networks.
WARNING
Creating a virtual network peering between virtual networks in created through different Azure deployment models that
exist in different subscriptions is currently in preview. Virtual network peerings created in this scenario may not have the
same level of availability and reliability as creating a virtual network peering in scenarios in general availability release. Virtual
network peerings created in this scenario are not supported, may have constrained capabilities, and may not be available in
all Azure regions. For the most up-to-date notifications on availability and status of this feature, check the Azure Virtual
Network updates page.
You can use the Azure portal, the Azure command-line interface (CLI), or Azure PowerShell to create a virtual
network peering. Click any of the previous tool links to go directly to the steps for creating a virtual network
peering using your tool of choice.
Register-AzureRmProviderFeature `
-FeatureName AllowClassicCrossSubscriptionPeering `
-ProviderNamespace Microsoft.Network
Register-AzureRmResourceProvider `
-ProviderNamespace Microsoft.Network
Do not complete the steps in the Portal, Azure CLI, or PowerShell sections of this article until the
RegistrationState output you receive after entering the following command is Registered for both
subscriptions:
Get-AzureRmProviderFeature `
-FeatureName AllowClassicCrossSubscriptionPeering `
-ProviderNamespace Microsoft.Network
azure network vnet create --vnet myVnetB --address-space 10.1.0.0 --cidr 16 --location "East US"
5. The remaining steps must be completed using a bash shell with the Azure CLI 2.0.4 or later installed, or by
using the Azure Cloud Shell. The Azure Cloud Shell is a free Bash shell that you can run directly within the
Azure portal. It has the Azure CLI preinstalled and configured to use with your account. Click the Try it button
in the scripts that follow, which opens a Cloud Shell that logs you in to your Azure account. For options on
running bash CLI scripts on a Windows client, see Running the Azure CLI in Windows.
6. Copy the following script to a text editor on your PC. Replace <SubscriptionB-Id> with your subscription ID.
If you don't know your subscription Id, enter the az account show command. The value for id in the output
is your subscription Id. Copy the modified script, paste it in to your CLI 2.0 session, and then press Enter .
When you created the virtual network (classic) in step 4, Azure created the virtual network in the Default-
Networking resource group.
7. Log UserB out of Azure and log in as UserA in the CLI 2.0.
8. Create a resource group and a virtual network (Resource Manager). Copy the following script, paste it in to
your CLI session, and then press Enter .
#!/bin/bash
9. Create a virtual network peering between the two virtual networks created through the different
deployment models. Copy the following script to a text editor on your PC. Replace <SubscriptionB-id> with
your subscription Id. If you don't know your subscription Id, enter the az account show command. The
value for id in the output is your subscription Id. Azure created the virtual network (classic) you created in
step 4 in a resource group named Default-Networking. Paste the modified script in your CLI session, and
then press Enter .
10. After the script executes, review the peering for the virtual network (Resource Manager). Copy the following
script, and then paste it in your CLI session:
WARNING
Importing a changed network configuration file can cause changes to existing virtual networks (classic) in your
subscription. Ensure you only add the previous virtual network and that you don't change or remove any existing
virtual networks from your subscription.
5. Log in to UserB's subscription as UserB to use Resource Manager commands by entering the
login-azurermaccount command.
6. Assign UserA permissions to virtual network B. Copy the following script to a text editor on your PC and
replace <SubscriptionB-id> with the ID of subscription B. If you don't know the subscription Id, enter the
Get-AzureRmSubscription command to view it. The value for Id in the returned output is your subscription
ID. Azure created the virtual network (classic) you created in step 4 in a resource group named Default-
Networking. To execute the script, copy the modified script, paste it in to PowerShell, and then press Enter .
New-AzureRmRoleAssignment `
-SignInName UserA@azure.com `
-RoleDefinitionName "Classic Network Contributor" `
-Scope /subscriptions/<SubscriptionB-id>/resourceGroups/Default-
Networking/providers/Microsoft.ClassicNetwork/virtualNetworks/myVnetB
7. Log out of Azure as UserB and log in to UserA's subscription as UserA by entering the
login-azurermaccount command. The account you log in with must have the necessary permissions to
create a virtual network peering. See the Permissions section of this article for details.
8. Create the virtual network (Resource Manager) by copying the following script, pasting it in to PowerShell,
and then pressing Enter :
9. Assign UserB permissions to myVnetA. Copy the following script to a text editor on your PC and replace
<SubscriptionA-Id> with the ID of subscription A. If you don't know the subscription Id, enter the
Get-AzureRmSubscription command to view it. The value for Id in the returned output is your subscription
ID. Paste the modified version of the script in PowerShell, and then press Enter to execute it.
New-AzureRmRoleAssignment `
-SignInName UserB@azure.com `
-RoleDefinitionName "Network Contributor" `
-Scope /subscriptions/<SubscriptionA-
Id>/resourceGroups/myResourceGroupA/providers/Microsoft.Network/VirtualNetworks/myVnetA
10. Copy the following script to a text editor on your PC, and replace <SubscriptionB-id> with the ID of
subscription B. To peer myVnetA to myVNetB, copy the modified script, paste it in to PowerShell, and then
press Enter .
Add-AzureRmVirtualNetworkPeering `
-Name 'myVnetAToMyVnetB' `
-VirtualNetwork $vnetA `
-RemoteVirtualNetworkId /subscriptions/<SubscriptionB-id>/resourceGroups/Default-
Networking/providers/Microsoft.ClassicNetwork/virtualNetworks/myVnetB
11. View the peering state of myVnetA by copying the following script, pasting it into PowerShell, and pressing
Enter .
Get-AzureRmVirtualNetworkPeering `
-ResourceGroupName $rgName `
-VirtualNetworkName myVnetA `
| Format-Table VirtualNetworkName, PeeringState
The state is Connected. It changes to Connected once you setup the peering to myVnetA from myVnetB.
Any Azure resources you create in either virtual network are now able to communicate with each other
through their IP addresses. If you're using default Azure name resolution for the virtual networks, the
resources in the virtual networks are not able to resolve names across the virtual networks. If you want to
resolve names across virtual networks in a peering, you must create your own DNS server. Learn how to set
up Name resolution using your own DNS server.
12. Optional: Though creating virtual machines is not covered in this tutorial, you can create a virtual machine
in each virtual network and connect from one virtual machine to the other, to validate connectivity.
13. Optional: To delete the resources that you create in this tutorial, complete the steps in Delete resources in this
article.
Permissions
The accounts you use to create a virtual network peering must have the necessary role or permissions. For
example, if you were peering two virtual networks named myVnetA and myVnetB, your account must be assigned
the following minimum role or permissions for each virtual network:
Learn more about built-in roles and assigning specific permissions to custom roles (Resource Manager only).
Delete resources
When you've finished this tutorial, you might want to delete the resources you created in the tutorial, so you don't
incur usage charges. Deleting a resource group also deletes all resources that are in the resource group.
Azure portal
1. In the portal search box, enter myResourceGroupA. In the search results, click myResourceGroupA.
2. On the myResourceGroupA blade, click the Delete icon.
3. To confirm the deletion, in the TYPE THE RESOURCE GROUP NAME box, enter myResourceGroupA, and
then click Delete.
4. In the Search resources box at the top of the portal, type myVnetB. Click myVnetB when it appears in the
search results. A blade appears for the myVnetB virtual network.
5. In the myVnetB blade, click Delete.
6. To confirm the deletion, click Yes in the Delete virtual network box.
Azure CLI
1. Log in to Azure using the CLI 2.0 to delete the virtual network (Resource Manager) with the following
command:
2. Log in to Azure using the Azure CLI 1.0 to delete the virtual network (classic) with the following commands:
PowerShell
1. At the PowerShell command prompt, enter the following command to delete the virtual network (Resource
Manager):
2. To delete the virtual network (classic) with PowerShell, you must modify an existing network configuration
file. Learn how to export, update, and import network configuration files. Remove the following
VirtualNetworkSite element for the virtual network used in this tutorial:
WARNING
Importing a changed network configuration file can cause changes to existing virtual networks (classic) in your
subscription. Ensure you only remove the previous virtual network and that you don't change or remove any other
existing virtual networks from your subscription.
Next steps
Thoroughly familiarize yourself with important virtual network peering constraints and behaviors before
creating a virtual network peering for production use.
Learn about all virtual network peering settings.
Learn how to create a hub and spoke network topology with virtual network peering.
Create a VM with a static public IP address using the
Azure portal
6/27/2017 2 min to read Edit Online
You can create virtual machines (VMs) in Azure and expose them to the public Internet by using a public IP address.
By default, Public IPs are dynamic and the address associated to them may change when the VM is deleted. To
guarantee that the VM always uses the same public IP address, you need to create a static Public IP.
Before you can implement static Public IPs in VMs, it is necessary to understand when you can use static Public IPs,
and how they are used. Read the IP addressing overview to learn more about IP addressing in Azure.
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the Resource Manager deployment model, which Microsoft recommends for most new deployments
instead of the classic deployment model.
Scenario
This document will walk through a deployment that uses a static public IP address allocated to a virtual machine
(VM). In this scenario, you have a single VM with its own static public IP address. The VM is part of a subnet named
FrontEnd and also has a static private IP address (192.168.1.101) in that subnet.
You may need a static IP address for web servers that require SSL connections in which the SSL certificate is linked
to an IP address.
You can follow the steps below to deploy the environment shown in the figure above.
6. In the Settings blade, click Public IP address, then in the Create public IP address blade, under
Assignment, click Static as shown below. And then click OK.
10. Once the VM is created, the Settings blade will be displayed as shown below
Create a VM with a static public IP address using
PowerShell
6/27/2017 4 min to read Edit Online
You can create virtual machines (VMs) in Azure and expose them to the public Internet by using a public IP
address. By default, Public IPs are dynamic and the address associated to them may change when the VM is
deleted. To guarantee that the VM always uses the same public IP address, you need to create a static Public IP.
Before you can implement static Public IPs in VMs, it is necessary to understand when you can use static Public IPs,
and how they are used. Read the IP addressing overview to learn more about IP addressing in Azure.
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the Resource Manager deployment model, which Microsoft recommends for most new deployments
instead of the classic deployment model.
Scenario
This document will walk through a deployment that uses a static public IP address allocated to a virtual machine
(VM). In this scenario, you have a single VM with its own static public IP address. The VM is part of a subnet named
FrontEnd and also has a static private IP address (192.168.1.101) in that subnet.
You may need a static IP address for web servers that require SSL connections in which the SSL certificate is linked
to an IP address.
You can follow the steps below to deploy the environment shown in the figure above.
NOTE
If you don't have an Azure account, you'll need one. Go sign up for a free trial here.
Step 1 - Start your script
You can download the full PowerShell script used here. Follow the steps below to change the script to work in your
environment.
Change the values of the variables below based on the values you want to use for your deployment. The following
values map to the scenario used in this article:
4. Create the network interface (NIC) for the VM in the subnet created above, with the public IP. Notice the first
cmdlet retrieving the VNet from Azure, this is necessary since a Set-AzureRmVirtualNetwork was executed to
change the existing VNet.
$cred = Get-Credential -Message "Type the name and password for the local administrator account."
ResourceGroupName : IaaSStory
Location : westus
ProvisioningState : Succeeded
Tags :
ResourceId : /subscriptions/[Subscription ID]/resourceGroups/IaaSStory
AddressSpace : Microsoft.Azure.Commands.Network.Models.PSAddressSpace
DhcpOptions : Microsoft.Azure.Commands.Network.Models.PSDhcpOptions
Subnets : {FrontEnd}
ProvisioningState : Succeeded
AddressSpaceText : {
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptionsText : {}
SubnetsText : [
{
"Name": "FrontEnd",
"AddressPrefix": "192.168.1.0/24"
}
]
ResourceGroupName : IaaSStory
Location : westus
ResourceGuid : [Id]
Tag : {}
TagsTable :
Name : WTestVNet
Etag : W/"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Id : /subscriptions/[Subscription
ID]/resourceGroups/IaaSStory/providers/Microsoft.Network/virtualNetworks/WTestVNet
AddressSpace :
Microsoft.Azure.Commands.Network.Models.PSAddressSpace
DhcpOptions :
Microsoft.Azure.Commands.Network.Models.PSDhcpOptions
Subnets :
{FrontEnd}
ProvisioningState :
Succeeded
AddressSpaceText :
{
"AddressPrefixes": [
"192.168.0.0/16"
]
}
DhcpOptionsText : {
"DnsServers": []
}
SubnetsText : [
{
"Name": "FrontEnd",
"Etag": [Id],
"Id": "/subscriptions/[Subscription
ID]/resourceGroups/IaaSStory/providers/Microsoft.Network/virtualNetworks/WTestVNet/subnets/FrontEnd",
"AddressPrefix": "192.168.1.0/24",
"IpConfigurations": [],
"ProvisioningState": "Succeeded"
}
]
ResourceGroupName : IaaSStory
Location : westus
ResourceGuid : [Id]
Tag : {}
TagsTable :
TagsTable :
Name : WTestVNet
Etag : [Id]
Id : /subscriptions/[Subscription
Id]/resourceGroups/IaaSStory/providers/Microsoft.Network/virtualNetworks/WTestVNet
TrackingOperationId : [Id]
RequestId : [Id]
Status : Succeeded
StatusCode : OK
Output :
StartTime : [Subscription Id]
EndTime : [Subscription Id]
Error :
ErrorText :
Create a VM with a static public IP address using the
Azure CLI 2.0
6/27/2017 5 min to read Edit Online
You can create virtual machines (VMs) in Azure and expose them to the public Internet by using a public IP
address. By default, Public IPs are dynamic and the address associated to them may change when the VM is
deleted. To guarantee that the VM always uses the same public IP address, you need to create a static Public IP.
Before you can implement static Public IPs in VMs, it is necessary to understand when you can use static Public IPs,
and how they are used. Read the IP addressing overview to learn more about IP addressing in Azure.
Azure has two different deployment models for creating and working with resources: Resource Manager and
classic. This article covers using the Resource Manager deployment model, which Microsoft recommends for most
new deployments instead of the classic deployment model.
Scenario
This document will walk through a deployment that uses a static public IP address allocated to a virtual machine
(VM). In this scenario, you have a single VM with its own static public IP address. The VM is part of a subnet named
FrontEnd and also has a static private IP address (192.168.1.101) in that subnet.
You may need a static IP address for web servers that require SSL connections in which the SSL certificate is linked
to an IP address.
You can follow the steps below to deploy the environment shown in the figure above.
Create the VM
You can complete this task using the Azure CLI 2.0 (this article) or the Azure CLI 1.0. The values in "" for the
variables in the steps that follow create resources with settings from the scenario. Change the values, as
appropriate, for your environment.
1. Install the Azure CLI 2.0 if you don't already have it installed.
2. Create an SSH public and private key pair for Linux VMs by completing the steps in the Create an SSH public
and private key pair for Linux VMs.
3. From a command shell, login with the command az login .
4. Create the VM by executing the script that follows on a Linux or Mac computer. The Azure public IP address,
virtual network, network interface, and VM resources must all exist in the same location. Though the resources
don't all have to exist in the same resource group, in the following script they do.
RgName="IaaSStory"
Location="westus"
az group create \
--name $RgName \
--location $Location
# Create a public IP address resource with a static IP address using the --allocation-method Static option.
# If you do not specify this option, the address is allocated dynamically. The address is assigned to the
# resource from a pool of IP adresses unique to each Azure region. The DnsName must be unique within the
# Azure location it's created in. Download and view the file from https://www.microsoft.com/en-
us/download/details.aspx?id=41653#
# that lists the ranges for each region.
PipName="PIPWEB1"
DnsName="iaasstoryws1"
az network public-ip create \
--name $PipName \
--resource-group $RgName \
--location $Location \
--allocation-method Static \
--dns-name $DnsName
VnetName="TestVNet"
VnetPrefix="192.168.0.0/16"
SubnetName="FrontEnd"
SubnetPrefix="192.168.1.0/24"
az network vnet create \
--name $VnetName \
--resource-group $RgName \
--location $Location \
--address-prefix $VnetPrefix \
--subnet-name $SubnetName \
--subnet-prefix $SubnetPrefix
# Create a network interface connected to the VNet with a static private IP address and associate the public
IP address
# resource to the NIC.
NicName="NICWEB1"
PrivateIpAddress="192.168.1.101"
az network nic create \
--name $NicName \
--resource-group $RgName \
--location $Location \
--subnet $SubnetName \
--vnet-name $VnetName \
--private-ip-address $PrivateIpAddress \
--public-ip-address $PipName
VmName="WEB1"
# Replace the value for the VmSize variable with a value from the
# https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-sizes article.
VmSize="Standard_DS1"
# Replace the value for the OsImage variable with a value for *urn* from the output returned by entering
# the `az vm image list` command.
OsImage="credativ:Debian:8:latest"
Username='adminuser'
# Replace the following value with the path to your public key file.
SshKeyValue="~/.ssh/id_rsa.pub"
az vm create \
--name $VmName \
--resource-group $RgName \
--image $OsImage \
--location $Location \
--size $VmSize \
--nics $NicName \
--admin-username $Username \
--ssh-key-value $SshKeyValue
# If creating a Windows VM, remove the previous line and you'll be prompted for the password you want to
configure for the VM.
Next steps
Any network traffic can flow to and from the VM created in this article. You can define inbound and outbound rules
within an NSG that limit the traffic that can flow to and from the network interface, the subnet, or both. To learn
more about NSGs, read the NSG overview article.
Create a VM with a static public IP address using an
Azure Resource Manager template
6/27/2017 4 min to read Edit Online
You can create virtual machines (VMs) in Azure and expose them to the public Internet by using a public IP
address. By default, Public IPs are dynamic and the address associated to them may change when the VM is
deleted. To guarantee that the VM always uses the same public IP address, you need to create a static Public IP.
Before you can implement static Public IPs in VMs, it is necessary to understand when you can use static Public IPs,
and how they are used. Read the IP addressing overview to learn more about IP addressing in Azure.
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the Resource Manager deployment model, which Microsoft recommends for most new deployments
instead of the classic deployment model.
Scenario
This document will walk through a deployment that uses a static public IP address allocated to a virtual machine
(VM). In this scenario, you have a single VM with its own static public IP address. The VM is part of a subnet named
FrontEnd and also has a static private IP address (192.168.1.101) in that subnet.
You may need a static IP address for web servers that require SSL connections in which the SSL certificate is linked
to an IP address.
You can follow the steps below to deploy the environment shown in the figure above.
Notice the publicIPAllocationMethod property, which is set to Static. This property can be either Dynamic
(default value) or Static. Setting it to static guarantees that the public IP address assigned will never change.
The following section shows the association of the public IP address with a network interface:
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('webVMSetting').nicName]",
"location": "[variables('location')]",
"tags": {
"displayName": "NetworkInterface - Web"
},
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('webVMSetting').pipName)]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Static",
"privateIPAddress": "[variables('webVMSetting').ipAddress]",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('webVMSetting').pipName)]"
},
"subnet": {
"id": "[variables('frontEndSubnetRef')]"
}
}
}
]
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('webVMSetting').nicName)]"
}
]
}
Deploy the template by using click to deploy
The sample template available in the public repository uses a parameter file containing the default values used to
generate the scenario described above. To deploy this template using click to deploy, click Deploy to Azure in the
Readme.md file for the VM with static PIP template. Replace the default parameter values if desired and enter
values for the blank parameters. Follow the instructions in the portal to create a virtual machine with a static public
IP address.
Expected output:
ResourceGroupName : PIPTEST
Location : westus
ProvisioningState : Succeeded
Tags :
ResourceId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/StaticPublicIP
Expected output:
DeploymentName : DeployVM
ResourceGroupName : PIPTEST
ProvisioningState : Succeeded
Timestamp : [Date and time]
Mode : Incremental
TemplateLink :
Uri : https://raw.githubusercontent.com/Azure/azure-quickstart-
templates/mas
ter/IaaS-Story/03-Static-public-IP/azuredeploy.json
ContentVersion : 1.0.0.0
Parameters :
Name Type Value
======================== ========================= ==========
vnetName String WTestVNet
vnetPrefix String 192.168.0.0/16
frontEndSubnetName String FrontEnd
frontEndSubnetPrefix String 192.168.1.0/24
storageAccountNamePrefix String iaasestd
stdStorageType String Standard_LRS
osType String Windows
adminUsername String adminUser
adminPassword SecureString
Outputs :
3. Open the parameter file, select its content, and save it to a file in your computer. For this example, the
parameters are saved to a file named parameters.json. Change the parameter values within the file if
desired, but at a minimum, it's recommended that you change the value for the adminPassword parameter
to a unique, complex password.
4. Run the azure group deployment create cmd to deploy the new VNet by using the template and parameter
files you downloaded and modified above. In the command below, replace with the path you saved the file
to.
IP addresses in Azure fall into two categories: dynamic and reserved. Public IP addresses managed by Azure are
dynamic by default. That means that the IP address used for a given cloud service (VIP) or to access a VM or role
instance directly (ILPIP) can change from time to time, when resources are shut down or stopped (deallocated).
To prevent IP addresses from changing, you can reserve an IP address. Reserved IPs can be used only as a VIP,
ensuring that the IP address for the cloud service remains the same, even as resources are shut down or stopped
(deallocated). Furthermore, you can convert existing dynamic IPs used as a VIP to a reserved IP address.
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager model. Learn how to reserve a static public IP address using the Resource Manager deployment model.
FAQ
1. Can I use a reserved IP for all Azure services?
No. Reserved IPs can only be used for VMs and cloud service instance roles exposed through a VIP.
2. How many reserved IPs can I have?
For details, see the Azure limits article.
3. Is there a charge for reserved IPs?
Sometimes. For pricing details, see the Reserved IP Address Pricing Details page.
4. How do I reserve an IP address?
You can use PowerShell, the Azure Management REST API, or the Azure portal to reserve an IP address in an
Azure region. A reserved IP address is associated to your subscription.
5. Can I use a reserved IP with affinity group-based VNets?
No. Reserved IPs are only supported in regional VNets. Reserved IPs are not supported for VNets that are
associated with affinity groups. For more information about associating a VNet with a region or affinity group,
see the About Regional VNets and Affinity Groups article.
Notice, however, that you cannot specify what IP is being reserved. To view what IP addresses are reserved in
your subscription, run the following PowerShell command, and notice the values for ReservedIPName and
Address:
Get-AzureReservedIP
Expected output:
ReservedIPName : MyReservedIP
Address : 23.101.114.211
Id : d73be9dd-db12-4b5e-98c8-bc62e7c42041
Label :
Location : Central US
State : Created
InUse : False
ServiceName :
DeploymentName :
OperationDescription : Get-AzureReservedIP
OperationId : 55e4f245-82e4-9c66-9bd8-273e815ce30a
OperationStatus : Succeeded
NOTE
When you create a reserved IP address with PowerShell, you cannot specify a resource group to create the reserved IP in.
Azure places it into a resource group named Default-Networking automatically. If you create the reserved IP using the
Azure portal, you can specify any resource group you choose. If you create the reserved IP in a resource group other than
Default-Networking however, whenever you reference the reserved IP with commands such as Get-AzureReservedIP
and Remove-AzureReservedIP , you must reference the name Group resource-group-name reserved-ip-name. For
example, if you create a reserved IP named myReservedIP in a resource group named myResourceGroup, you must
reference the name of the reserved IP as Group myResourceGroup myReservedIP.
Once an IP is reserved, it remains associated to your subscription until you delete it. To delete a reserved IP, run
the following PowerShell command:
NOTE
When you create a reserved IP to use with a cloud service, you still refer to the VM by using VIP:<port number> for
inbound communication. Reserving an IP does not mean you can connect to the VM directly. The reserved IP is assigned
to the cloud service that the VM has been deployed to. If you want to connect to a VM by IP directly, you have to
configure an instance-level public IP. An instance-level public IP is a type of public IP (called an ILPIP) that is assigned
directly to your VM. It cannot be reserved. For more information, read the Instance-level Public IP (ILPIP) article.
NOTE
Removing a reserved IP from a running deployment does not remove the reservation from your subscription. It simply
frees the IP to be used by another resource in your subscription.
Next steps
Understand how IP addressing works in the classic deployment model.
Learn about reserved private IP addresses.
Learn about Instance Level Public IP (ILPIP) addresses.
Configure private IP addresses for a virtual machine
using the Azure portal
6/27/2017 3 min to read Edit Online
Your IaaS virtual machines (VMs) and PaaS role instances in a virtual network automatically receive a private IP
address from a range that you specify, based on the subnet they are connected to. That address is retained by the
VMs and role instances, until they are decommissioned. You decommission a VM or role instance by stopping it
from PowerShell, the Azure CLI, or the Azure portal. In those cases, once the VM or role instance starts again, it will
receive an available IP address from the Azure infrastructure, which might not be the same it previously had. If you
shut down the VM or role instance from the guest operating system, it retains the IP address it had.
In certain cases, you want a VM or role instance to have a static IP address, for example, if your VM is going to run
DNS or will be a domain controller. You can do so by setting a static private IP address.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the Resource Manager deployment model. You can also manage static private IP address in the
classic deployment model.
Scenario
To better illustrate how to configure a static IP address for a VM, this document will use the scenario below.
In this scenario you will create a VM named DNS01 in the FrontEnd subnet, and set it to use a static IP address of
192.168.1.101.
The sample steps below expect a simple environment already created. If you want to run the steps as they are
displayed in this document, first build the test environment described in create a vnet.
3. In the Basics blade, enter the name of the VM to be created (DNS01 in our scenario), the local administrator
account, and password, as seen in the figure below.
4. Make sure the Location selected is Central US, then click Select existing under Resource group, then
click Resource group again, then click TestRG, and then click OK.
5. In the Choose a size blade, select A1 Standard, and then click Select.
6. In teh Settings blade, make sure the following properties are set are set with the values below, and then
click OK.
-Storage account: vnetstorage
Network: TestVNet
Subnet: FrontEnd
7. In the Summary blade, click OK. Notice the tile below displayed in your dashboard.
2. In the Network interface blade, click All settings > IP addresses and notice the Assignment and IP
address values.
Next steps
Learn about reserved public IP addresses.
Learn about instance-level public IP (ILPIP) addresses.
Consult the Reserved IP REST APIs.
Configure private IP addresses for a virtual machine
using PowerShell
6/27/2017 5 min to read Edit Online
Your IaaS virtual machines (VMs) and PaaS role instances in a virtual network automatically receive a private IP
address from a range that you specify, based on the subnet they are connected to. That address is retained by the
VMs and role instances, until they are decommissioned. You decommission a VM or role instance by stopping it
from PowerShell, the Azure CLI, or the Azure portal. In those cases, once the VM or role instance starts again, it will
receive an available IP address from the Azure infrastructure, which might not be the same it previously had. If you
shut down the VM or role instance from the guest operating system, it retains the IP address it had.
In certain cases, you want a VM or role instance to have a static IP address, for example, if your VM is going to run
DNS or will be a domain controller. You can do so by setting a static private IP address.
Azure has two deployment models: Azure Resource Manager and classic. Microsoft recommends creating
resources through the Resource Manager deployment model. To learn more about the differences between the
two models, read the Understand Azure deployment models article. This article covers the Resource Manager
deployment model. You can also manage static private IP address in the classic deployment model.
Scenario
To better illustrate how to configure a static IP address for a VM, this document will use the scenario below.
In this scenario you will create a VM named DNS01 in the FrontEnd subnet, and set it to use a static IP address of
192.168.1.101.
The sample PowerShell commands below expect a simple environment already created based on the scenario
above. If you want to run the commands as they are displayed in this document, first build the test environment
described in create a vnet.
$stName = "vnetstorage"
$locName = "Central US"
$rgName = "TestRG"
$cred = Get-Credential -Message "Type the name and password of the local administrator account."
2. Retrieve the virtual network and subnet you want to create the VM in.
4. Create a NIC using the static private IP address you want to assign to the VM. Make sure the IP is from the
subnet range you are adding the VM to. This is the main step for this article, where you set the private IP to
be static.
Expected output:
Expected output:
Name : TestNIC
ResourceGroupName : TestRG
Location : centralus
Id :
/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
VirtualMachine : {
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/DNS01"
}
IpConfigurations : [
{
"Name": "ipconfig1",
"Etag": "W/\"[Id]\"",
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC/ipConfigurati
ons/ipconfig1",
"PrivateIpAddress": "192.168.1.101",
"PrivateIpAllocationMethod": "Static",
"Subnet": {
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontE
nd"
},
"PublicIpAddress": {
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/publicIPAddresses/TestPIP"
},
"LoadBalancerBackendAddressPools": [],
"LoadBalancerInboundNatRules": [],
"ProvisioningState": "Succeeded"
}
]
DnsSettings : {
"DnsServers": [],
"AppliedDnsServers": [],
"InternalDnsNameLabel": null,
"InternalFqdn": null
}
EnableIPForwarding : False
NetworkSecurityGroup : null
Primary : True
Expected output:
Name : TestNIC
ResourceGroupName : TestRG
Location : centralus
Id :
/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC
Etag : W/"[Id]"
ProvisioningState : Succeeded
Tags :
VirtualMachine : {
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/WindowsVM"
}
IpConfigurations : [
{
"Name": "ipconfig1",
"Etag": "W/\"[Id]\"",
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC/ipConfigurati
ons/ipconfig1",
"PrivateIpAddress": "192.168.1.101",
"PrivateIpAllocationMethod": "Dynamic",
"Subnet": {
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontE
nd"
},
"PublicIpAddress": {
"Id":
"/subscriptions/[Id]/resourceGroups/TestRG/providers/Microsoft.Network/publicIPAddresses/TestPIP"
},
"LoadBalancerBackendAddressPools": [],
"LoadBalancerInboundNatRules": [],
"ProvisioningState": "Succeeded"
}
]
DnsSettings : {
"DnsServers": [],
"AppliedDnsServers": [],
"InternalDnsNameLabel": null,
"InternalFqdn": null
}
EnableIPForwarding : False
NetworkSecurityGroup : null
Primary : True
$RG = "TestRG"
$NIC_name = "testnic1"
If you don't know the name of the NIC, you can view a list of NICs within a resource group by entering the
following command:
Next steps
Learn about reserved public IP addresses.
Learn about instance-level public IP (ILPIP) addresses.
Consult the Reserved IP REST APIs.
Configure private IP addresses for a virtual machine
using the Azure CLI 2.0
6/27/2017 5 min to read Edit Online
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the Resource Manager deployment model. You can also manage static private IP address in the
classic deployment model.
Scenario
To better illustrate how to configure a static IP address for a VM, this document will use the scenario below.
In this scenario you will create a VM named DNS01 in the FrontEnd subnet, and set it to use a static IP address of
192.168.1.101.
NOTE
The sample Azure CLI 2.0 commands below expect a simple environment already created. If you want to run the commands
as they are displayed in this document, first build the test environment described in create a vnet.
NOTE
You may want or need to use different values for your arguments in this and subsequent steps, depending upon
your environment.
Expected output:
{
"publicIp": {
"idleTimeoutInMinutes": 4,
"ipAddress": "52.176.43.167",
"provisioningState": "Succeeded",
"publicIPAllocationMethod": "Static",
"resourceGuid": "79e8baa3-33ce-466a-846c-37af3c721ce1"
}
}
--resource-group : Name of the resource group in which to create the public IP.
--name : Name of the public IP.
--location : Azure region in which to create the public IP.
3. Run the az network nic create command to create a NIC with a static private IP. The list shown after the
output explains the parameters used.
{
"newNIC": {
"dnsSettings": {
"appliedDnsServers": [],
"dnsServers": []
},
"enableIPForwarding": false,
"ipConfigurations": [
{
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC/ipCo
nfigurations/ipconfig1",
"name": "ipconfig1",
"properties": {
"primary": true,
"privateIPAddress": "192.168.1.101",
"privateIPAllocationMethod": "Static",
"provisioningState": "Succeeded",
"subnet": {
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subne
ts/FrontEnd",
"resourceGroup": "TestRG"
}
},
"resourceGroup": "TestRG"
}
],
"provisioningState": "Succeeded",
"resourceGuid": "<guid>"
}
}
Parameters:
--private-ip-address : Static private IP address for the NIC.
--vnet-name : Name of the VNet in wihch to create the NIC.
--subnet : Name of the subnet in which to create the NIC.
4. Run the azure vm create command to create the VM using the public IP and NIC created above. The list
shown after the output explains the parameters used.
az vm create \
--resource-group TestRG \
--name DNS01 \
--location centralus \
--image Debian \
--admin-username adminuser \
--ssh-key-value ~/.ssh/id_rsa.pub \
--nics TestNIC
Expected output:
{
"fqdns": "",
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/DNS01",
"location": "centralus",
"macAddress": "00-0D-3A-92-C1-66",
"powerState": "VM running",
"privateIpAddress": "192.168.1.101",
"publicIpAddress": "",
"resourceGroup": "TestRG"
}
Expected output:
"192.168.1.101"
To display the specific IP information of the NIC for that VM, query the NIC specifically:
{
"IPVer": "IPv4",
"IpAllocMethod": "Static",
"PrivateAddress": "192.168.1.101",
"PublicAddress": null
}
Expected output:
{
"newNIC": {
"dnsSettings": {
"appliedDnsServers": [],
"dnsServers": []
},
"enableIPForwarding": false,
"ipConfigurations": [
{
"etag": "W/\"<guid>\"",
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC2/ipC
onfigurations/ipconfig1",
"name": "ipconfig1",
"properties": {
"primary": true,
"privateIPAddress": "192.168.1.4",
"privateIPAllocationMethod": "Dynamic",
"provisioningState": "Succeeded",
"subnet": {
"id":
"/subscriptions/<guid>/resourceGroups/TestRG/providers/Microsoft.Network/virtualNetworks/TestVNet/subne
ts/FrontEnd",
"resourceGroup": "TestRG"
}
},
"resourceGroup": "TestRG"
}
],
"provisioningState": "Succeeded",
"resourceGuid": "0808a61c-476f-4d08-98ee-0fa83671b010"
}
}
2. Run the azure vm set command to change the NIC used by the VM.
Expected output:
[
{
"id": "/subscriptions/0e220bf6-5caa-4e9f-8383-
51f16b6c109f/resourceGroups/TestRG/providers/Microsoft.Network/networkInterfaces/TestNIC3",
"primary": true,
"resourceGroup": "TestRG"
}
]
NOTE
If the VM is large enough to have more than one NIC, run the azure network nic delete command to delete the
old NIC.
Next steps
Learn about reserved public IP addresses.
Learn about instance-level public IP (ILPIP) addresses.
Consult the Reserved IP REST APIs.
Configure private IP addresses for a virtual machine
(Classic) using the Azure portal
6/27/2017 3 min to read Edit Online
Your IaaS virtual machines (VMs) and PaaS role instances in a virtual network automatically receive a private IP
address from a range that you specify, based on the subnet they are connected to. That address is retained by the
VMs and role instances, until they are decommissioned. You decommission a VM or role instance by stopping it
from PowerShell, the Azure CLI, or the Azure portal. In those cases, once the VM or role instance starts again, it
will receive an available IP address from the Azure infrastructure, which might not be the same it previously had. If
you shut down the VM or role instance from the guest operating system, it retains the IP address it had.
In certain cases, you want a VM or role instance to have a static IP address, for example, if your VM is going to run
DNS or will be a domain controller. You can do so by setting a static private IP address.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the classic deployment model. You can also manage a static private IP address in the Resource
Manager deployment model.
Scenario
To better illustrate how to configure a static IP address for a VM, this document will use the scenario below.
In this scenario you will create a VM named DNS01 in the FrontEnd subnet, and set it to use a static IP address of
192.168.1.101.
The sample steps below expect a simple environment already created. If you want to run the steps as they are
displayed in this document, first build the test environment described in create a vnet.
3. In the Create VM blade, enter the name of the VM to be created (DNS01 in our scenario), the local
administrator account, and password.
4. Click Optional Configuration > Network > Virtual Network, and then click TestVNet. If TestVNet is
not available, make sure you are using the Central US location and have created the test environment
described at the beginning of this article.
5. In the Network blade, make sure the subnet currently selected is FrontEnd, then click IP addresses, under
IP address assignment click Static, and then enter 192.168.1.101 for IP Address as seen below.
6. Click OK in the IP addresses blade, then click OK in the Network blade, and click OK in the Optional config
blade.
7. In the Create VM blade, click Create. Notice the tile below displayed in your dashboard.
Next steps
Learn about reserved public IP addresses.
Learn about instance-level public IP (ILPIP) addresses.
Consult the Reserved IP REST APIs.
Configure private IP addresses for a virtual machine
(Classic) using PowerShell
6/27/2017 3 min to read Edit Online
Your IaaS virtual machines (VMs) and PaaS role instances in a virtual network automatically receive a private IP
address from a range that you specify, based on the subnet they are connected to. That address is retained by the
VMs and role instances, until they are decommissioned. You decommission a VM or role instance by stopping it
from PowerShell, the Azure CLI, or the Azure portal. In those cases, once the VM or role instance starts again, it will
receive an available IP address from the Azure infrastructure, which might not be the same it previously had. If
you shut down the VM or role instance from the guest operating system, it retains the IP address it had.
In certain cases, you want a VM or role instance to have a static IP address, for example, if your VM is going to run
DNS or will be a domain controller. You can do so by setting a static private IP address.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the classic deployment model. You can also manage a static private IP address in the Resource
Manager deployment model.
Scenario
To better illustrate how to configure a static IP address for a VM, this document will use the scenario below.
In this scenario you will create a VM named DNS01 in the FrontEnd subnet, and set it to use a static IP address of
192.168.1.101.
The sample PowerShell commands below expect a simple environment already created. If you want to run the
commands as they are displayed in this document, first build the test environment described in Create a VNet.
Expected output:
IsAvailable : True
AvailableAddresses : {}
OperationDescription : Test-AzureStaticVNetIP
OperationId : fd3097e1-5f4b-9cac-8afa-bba1e3492609
OperationStatus : Succeeded
Expected output:
Expected output:
DeploymentName : TestService
Name : DNS01
Label :
VM : Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM
InstanceStatus : Provisioning
IpAddress : 192.168.1.7
InstanceStateDetails : Windows is preparing your computer for first use...
PowerState : Started
InstanceErrorCode :
InstanceFaultDomain : 0
InstanceName : DNS01
InstanceUpgradeDomain : 0
InstanceSize : Small
HostName : rsR2-797
AvailabilitySetName :
DNSName : http://testservice000.cloudapp.net/
Status : Provisioning
GuestAgentStatus : Microsoft.WindowsAzure.Commands.ServiceManagement.Model.GuestAgentStatus
ResourceExtensionStatusList : {Microsoft.Compute.BGInfo}
PublicIPAddress :
PublicIPName :
NetworkInterfaces : {}
ServiceName : TestService
OperationDescription : Get-AzureVM
OperationId : 34c1560a62f0901ab75cde4fed8e8bd1
OperationStatus : OK
Expected output:
Expected output:
Your IaaS virtual machines (VMs) and PaaS role instances in a virtual network automatically receive a private IP
address from a range that you specify, based on the subnet they are connected to. That address is retained by the
VMs and role instances, until they are decommissioned. You decommission a VM or role instance by stopping it
from PowerShell, the Azure CLI, or the Azure portal. In those cases, once the VM or role instance starts again, it
will receive an available IP address from the Azure infrastructure, which might not be the same it previously had. If
you shut down the VM or role instance from the guest operating system, it retains the IP address it had.
In certain cases, you want a VM or role instance to have a static IP address, for example, if your VM is going to run
DNS or will be a domain controller. You can do so by setting a static private IP address.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the classic deployment model. You can also manage a static private IP address in the Resource
Manager deployment model.
The sample Azure CLI commands below expect a simple environment already created. If you want to run the
commands as they are displayed in this document, first build the test environment described in create a vnet.
Expected output:
3. Run the azure create vm command to create the VM. Notice the value for a static private IP address. The
list shown after the output explains the parameters used.
azure vm create -l centralus -n DNS01 -w TestVNet -S "192.168.1.101" TestService
bd507d3a70934695bc2128e3e5a255ba__RightImage-Windows-2012R2-x64-v14.2 adminuser AdminP@ssw0rd
Expected output:
-l (or --location). Azure region where the VM will be created. For our scenario, centralus.
-n (or --vm-name). Name of the VM to be created.
-w (or --virtual-network-name). Name of the VNet where the VM will be created.
-S (or --static-ip). Static private IP address for the VM.
TestService. Name of the cloud service where the VM will be created.
bd507d3a70934695bc2128e3e5a255ba__RightImage-Windows-2012R2-x64-v14.2. Image used to
create the VM.
adminuser. Local administrator for the Windows VM.
AdminP@ssw0rd. Local administrator password for the Windows VM.
Expected output:
Expected output:
info: Executing command vm static-ip remove
info: Getting virtual machines
info: Reading network configuration
info: Updating network configuration
info: vm static-ip remove command OK
Expected output:
Next steps
Learn about reserved public IP addresses.
Learn about instance-level public IP (ILPIP) addresses.
Consult the Reserved IP REST APIs.
Create and manage a Windows virtual machine that
has multiple NICs
7/6/2017 5 min to read Edit Online
Virtual machines (VMs) in Azure can have multiple virtual network interface cards (NICs) attached to them. A
common scenario is to have different subnets for front-end and back-end connectivity, or a network dedicated to a
monitoring or backup solution. This article details how to create a VM that has multiple NICs attached to it. You
also learn how to add or remove NICs from an existing VM. Different VM sizes support a varying number of NICs,
so size your VM accordingly.
For detailed information, including how to create multiple NICs within your own PowerShell scripts, see deploying
multiple-NIC VMs.
Prerequisites
Make sure that you have the latest Azure PowerShell version installed and configured.
In the following examples, replace example parameter names with your own values. Example parameter names
include myResourceGroup, myVnet, and myVM.
2. Create your virtual network and subnets with New-AzureRmVirtualNetwork. The following example creates
a virtual network named myVnet:
Typically you also create a network security group or load balancer to help manage and distribute traffic across
your VMs. The more detailed multiple-NIC VM article guides you through creating a network security group and
assigning NICs.
Create the virtual machine
Now start to build your VM configuration. Each VM size has a limit for the total number of NICs that you can add to
a VM. For more information, see Windows VM sizes.
1. Set your VM credentials to the $cred variable as follows:
$cred = Get-Credential
2. Define your VM with New-AzureRmVMConfig. The following example defines a VM named myVM and uses
a VM size that supports more than two NICs (Standard_DS3_v2):
4. Attach the two NICs that you previously created with Add-AzureRmVMNetworkInterface:
2. Get the existing configuration of the VM with Get-AzureRmVm. The following example gets information for
the VM named myVM in myResourceGroup:
3. The following example creates a virtual NIC with New-AzureRmNetworkInterface named myNic3 that is
attached to mySubnetBackEnd. The virtual NIC is then attached to the VM named myVM in
myResourceGroup with Add-AzureRmVMNetworkInterface:
2. Get the existing configuration of the VM with Get-AzureRmVm. The following example gets information for
the VM named myVM in myResourceGroup:
3. Get information about the NIC remove with Get-AzureRmNetworkInterface. The following example gets
information about myNic3:
4. Remove the NIC with Remove-AzureRmVMNetworkInterface and then update the VM with Update-
AzureRmVm. The following example removes myNic3 as obtained by $nicId in the preceding step:
"copy": {
"name": "multiplenics",
"count": "[parameters('count')]"
}
You can read a complete example of creating multiple NICs by using Resource Manager templates.
Next steps
Review Windows VM sizes when you're trying to create a VM that has multiple NICs. Pay attention to the
maximum number of NICs that each VM size supports.
How to create a Linux virtual machine in Azure with
multiple network interface cards
9/1/2017 5 min to read Edit Online
You can create a virtual machine (VM) in Azure that has multiple virtual network interfaces (NICs) attached to it. A
common scenario is to have different subnets for front-end and back-end connectivity, or a network dedicated to a
monitoring or backup solution. This article details how to create a VM with multiple NICs attached to it and how to
add or remove NICs from an existing VM. For detailed information, including how to create multiple NICs within
your own Bash scripts, read more about deploying multi-NIC VMs. Different VM sizes support a varying number of
NICs, so size your VM accordingly.
This article details how to create a VM with multiple NICs with the Azure CLI 2.0. You can also perform these steps
with the Azure CLI 1.0.
Create the virtual network with az network vnet create. The following example creates a virtual network named
myVnet and subnet named mySubnetFrontEnd:
Create a subnet for the back-end traffic with az network vnet subnet create. The following example creates a subnet
named mySubnetBackEnd:
Create a network security group with az network nsg create. The following example creates a network security
group named myNetworkSecurityGroup:
az network nsg create \
--resource-group myResourceGroup \
--name myNetworkSecurityGroup
az vm create \
--resource-group myResourceGroup \
--name myVM \
--image UbuntuLTS \
--size Standard_DS3_v2 \
--admin-username azureuser \
--generate-ssh-keys \
--nics myNic1 myNic2
Add a NIC to a VM
The previous steps created a VM with multiple NICs. You can also add NICs to an existing VM with the Azure CLI
2.0.
Create another NIC with az network nic create. The following example creates a NIC named myNic3 connected to
the back-end subnet and network security group created in the previous steps:
To add a NIC to an existing VM, first deallocate the VM with az vm deallocate. The following example deallocates
the VM named myVM:
az vm deallocate --resource-group myResourceGroup --name myVM
Add the NIC with az vm nic add. The following example adds myNic3 to myVM:
az vm nic add \
--resource-group myResourceGroup \
--vm-name myVM \
--nics myNic3
Remove the NIC with az vm nic remove. The following example removes myNic3 from myVM:
az vm nic remove \
--resource-group myResourceGroup \
--vm-name myVM
--nics myNic3
"copy": {
"name": "multiplenics"
"count": "[parameters('count')]"
}
To make the change persistent and applied during the network stack activation, it is required to alter the
/etc/sysconfig/network-scipts/ifcfg-eth0 and /etc/sysconfig/network-scipts/ifcfg-eth1 file. Alter the line
"NM_CONTROLLED=yes" to "NM_CONTROLLED=no". Without this step the additonal rules/routing we are going to
add taking no effect.
Next step is to extend the routing tables. In order to make the next steps more visible let's assume we have the
following setup in place
Routing
Interfaces
With the above information it is possible to create the following additional files as root
/etc/sysconfig/network-scripts/rule-eth0
/etc/sysconfig/network-scripts/route-eth0
/etc/sysconfig/network-scripts/rule-eth1
/etc/sysconfig/network-scripts/route-eth1
The content of each file is the following
cat /etc/sysconfig/network-scripts/rule-eth0
from 10.0.1.4/32 table eth0-rt
to 10.0.1.4/32 table eth0-rt
cat /etc/sysconfig/network-scripts/route-eth0
10.0.1.0/24 dev eth0 table eth0-rt
default via 10.0.1.1 dev eth0 table eth0-rt
cat /etc/sysconfig/network-scripts/rule-eth1
from 10.0.1.5/32 table eth1-rt
to 10.0.1.5/32 table eth1-rt
cat /etc/sysconfig/network-scripts/route-eth1
10.0.1.0/24 dev eth1 table eth1-rt
default via 10.0.1.1 dev eth1 table eth1-rt
After the files got created and popultated it is necessary to restart the network service systemctl restart network
Connecting from the outside against either eth0 or eth1 is possible now
Next steps
Review Linux VM sizes when trying to creating a VM with multiple NICs. Pay attention to the maximum number of
NICs each VM size supports.
Create a VM (Classic) with multiple NICs using
PowerShell
7/12/2017 5 min to read Edit Online
You can create virtual machines (VMs) in Azure and attach multiple network interfaces (NICs) to each of your VMs.
Multiple NICs enable separation of traffic types across NICs. For example, one NIC might communicate with the
Internet, while another communicates only with internal resources not connected to the Internet. The ability to
separate network traffic across multiple NICs is required for many network virtual appliances, such as application
delivery and WAN optimization solutions.
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager model. Learn how to perform these steps using the Resource Manager deployment model.
Scenario
This document will walk through a deployment that uses multiple NICs in VMs in a specific scenario. In this
scenario, you have a two-tiered IaaS workload hosted in Azure. Each tier is deployed in its own subnet in a virtual
network (VNet). The front end tier is composed of several web servers, grouped together in a load balancer set for
high availability. The back end tier is composed of several database servers. These database servers will be
deployed with two NICs each, one for database access, the other for management. The scenario also includes
Network Security Groups (NSGs) to control what traffic is allowed to each subnet, and NIC in the deployment. The
figure below shows the basic architecture of this scenario.
The following steps use a resource group named IaaSStory for the WEB servers and a resource group named
IaaSStory-BackEnd for the DB servers.
Prerequisites
Before you can create the DB servers, you need to create the IaaSStory resource group with all the necessary
resources for this scenario. To create these resources, complete the steps that follow. Create a virtual network by
following the steps in the Create a virtual network article.
NOTE
If you don't have an Azure account, you'll need one. Go sign up for a free trial here.
2. Change the values of the variables below based on the values you want to use for your backend deployment.
$backendCSName = "IaaSStory-Backend"
$prmStorageAccountName = "iaasstoryprmstorage"
$avSetName = "ASDB"
$vmSize = "Standard_DS3"
$diskSize = 127
$vmNamePrefix = "DB"
$dataDiskSuffix = "datadisk"
$ipAddressPrefix = "192.168.2."
$numberOfVMs = 2
3. Set the storage account created above as the current storage account for your subscription.
$image = Get-AzureVMImage `
| where{$_.ImageFamily -eq "SQL Server 2014 RTM Web on Windows Server 2012 R2"} `
| sort PublishedDate -Descending `
| select -ExpandProperty ImageName -First 1
$cred = Get-Credential -Message "Enter username and password for local admin account"
2. Create a VMConfig object specifying the image, size, and availability set for the VM.
2. Fill out the information needed in the credentials prompt and click OK. The output below is returned.
You can create virtual machines (VMs) in Azure and attach multiple network interfaces (NICs) to each of your VMs.
Multiple NICs enable separation of traffic types across NICs. For example, one NIC might communicate with the
Internet, while another communicates only with internal resources not connected to the Internet. The ability to
separate network traffic across multiple NICs is required for many network virtual appliances, such as application
delivery and WAN optimization solutions.
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager model. Learn how to perform these steps using the Resource Manager deployment model.
Scenario
This document will walk through a deployment that uses multiple NICs in VMs in a specific scenario. In this
scenario, you have a two-tiered IaaS workload hosted in Azure. Each tier is deployed in its own subnet in a virtual
network (VNet). The front end tier is composed of several web servers, grouped together in a load balancer set for
high availability. The back end tier is composed of several database servers. These database servers will be
deployed with two NICs each, one for database access, the other for management. The scenario also includes
Network Security Groups (NSGs) to control what traffic is allowed to each subnet, and NIC in the deployment. The
figure below shows the basic architecture of this scenario.
The following steps use a resource group named IaaSStory for the WEB servers and a resource group named
IaaSStory-BackEnd for the DB servers.
Prerequisites
Before you can create the DB servers, you need to create the IaaSStory resource group with all the necessary
resources for this scenario. To create these resources, complete the steps that follow. Create a virtual network by
following the steps in the Create a virtual network article.
NOTE
If you don't have an Azure account, you need one. Go sign up for a free trial here. In addition, to follow along completely you
need to have either jq or some other JSON parsing tool or library installed.
location="useast2"
vnetName="WTestVNet"
backendSubnetName="BackEnd"
2. Change the values of the variables below based on the values you want to use for your backend
deployment.
backendCSName="IaaSStory-Backend"
prmStorageAccountName="iaasstoryprmstorage"
image="0b11de9248dd4d87b18621318e037d37__RightImage-Ubuntu-14.04-x64-v14.2.1"
avSetName="ASDB"
vmSize="Standard_DS3"
diskSize=127
vmNamePrefix="DB"
osDiskName="osdiskdb"
dataDiskPrefix="db"
dataDiskName="datadisk"
ipAddressPrefix="192.168.2."
username='adminuser'
password='adminP@ssw0rd'
numberOfVMs=2
for ((suffixNumber=1;suffixNumber<=numberOfVMs;suffixNumber++));
do
2. For each VM, specify the name and IP address of each of the two NICs.
nic1Name=$vmNamePrefix$suffixNumber-DA
x=$((suffixNumber+3))
ipAddress1=$ipAddressPrefix$x
nic2Name=$vmNamePrefix$suffixNumber-RA
x=$((suffixNumber+53))
ipAddress2=$ipAddressPrefix$x
3. Create the VM. Notice the usage of the --nic-config parameter, containing a list of all NICs with name,
subnet, and IP address.
2. After a few minutes, the execution will end and you will see the rest of the output as shown below.
info: OK
info: vm create command OK
info: Executing command vm disk attach-new
info: Getting virtual machines
info: Adding Data-Disk
info: vm disk attach-new command OK
info: Executing command vm disk attach-new
info: Getting virtual machines
info: Adding Data-Disk
info: vm disk attach-new command OK
info: Executing command vm create
info: Looking up image 0b11de9248dd4d87b18621318e037d37__RightImage-Ubuntu-14.04-x64-v14.2.1
info: Looking up virtual network
info: Looking up cloud service
info: Getting cloud service properties
info: Looking up deployment
info: Creating VM
info: OK
info: vm create command OK
info: Executing command vm disk attach-new
info: Getting virtual machines
info: Adding Data-Disk
info: vm disk attach-new command OK
info: Executing command vm disk attach-new
info: Getting virtual machines
info: Adding Data-Disk
info: vm disk attach-new command OK
Assign multiple IP addresses to virtual machines using
the Azure portal
6/27/2017 12 min to read Edit Online
An Azure Virtual Machine (VM) has one or more network interfaces (NIC) attached to it. Any NIC can have one
or more static or dynamic public and private IP addresses assigned to it. Assigning multiple IP addresses to a
VM enables the following capabilities:
Hosting multiple websites or services with different IP addresses and SSL certificates on a single server.
Serve as a network virtual appliance, such as a firewall or load balancer.
The ability to add any of the private IP addresses for any of the NICs to an Azure Load Balancer back-end
pool. In the past, only the primary IP address for the primary NIC could be added to a back-end pool. To
learn more about how to load balance multiple IP configurations, read the Load balancing multiple IP
configurations article.
Every NIC attached to a VM has one or more IP configurations associated to it. Each configuration is assigned
one static or dynamic private IP address. Each configuration may also have one public IP address resource
associated to it. A public IP address resource has either a dynamic or static public IP address assigned to it. To
learn more about IP addresses in Azure, read the IP addresses in Azure article.
There is a limit to how many private IP addresses can be assigned to a NIC. There is also a limit to how many
public IP addresses that can be used in an Azure subscription. See the Azure limits article for details.
This article explains how to create a virtual machine (VM) through the Azure Resource Manager deployment
model using the Azure portal. Multiple IP addresses cannot be assigned to resources created through the
classic deployment model. To learn more about Azure deployment models, read the Understand deployment
models article.
Scenario
A VM with a single NIC is created and connected to a virtual network. The VM requires three different private IP
addresses and two public IP addresses. The IP addresses are assigned to the following IP configurations:
IPConfig-1: Assigns a static private IP address and a static public IP address.
IPConfig-2: Assigns a static private IP address and a static public IP address.
IPConfig-3: Assigns a static private IP address and no public IP address.
The IP configurations are associated to the NIC when the NIC is created and the NIC is attached to the VM when the
VM is created. The types of IP addresses used for the scenario are for illustration. You can assign whatever IP
address and assignment types you require.
NOTE
Though the steps in this article assigns all IP configurations to a single NIC, you can also assign multiple IP configurations to
any NIC in a multi-NIC VM. To learn how to create a VM with multiple NICs, read the Create a VM with multiple NICs article.
Add IP addresses to a VM
You can add private and public IP addresses to a NIC by completing the steps that follow. The examples in the
following sections assume that you already have a VM with the three IP configurations described in the scenario in
this article, but it's not required that you do.
Core steps
1. Browse to the Azure portal at https://portal.azure.com and sign into it, if necessary.
2. In the portal, click More services > type virtual machines in the filter box, and then click Virtual machines.
3. In the Virtual machines blade, click the VM you want to add IP addresses to. Click Network interfaces in
the virtual machine blade that appears, and then select the network interface you want to add the IP
addresses to. In the example shown in the following picture, the NIC named myNIC from the VM named
myVM is selected:
4. In the blade that appears for the NIC you selected, click IP configurations.
Complete the steps in one of the sections that follow, based on the type of IP address you want to add.
Add a private IP address
Complete the following steps to add a new private IP address:
1. Complete the steps in the Core steps section of this article.
2. Click Add. In the Add IP configuration blade that appears, create an IP configuration named IPConfig-4
with 10.0.0.7 as a Static private IP address, then click OK.
NOTE
When adding a static IP address, you must specify an unused, valid address on the subnet the NIC is connected to. If
the address you select is not available, the portal will show an X for the IP address and you'll need to select a different
one.
3. Once you click OK, the blade will close and you'll see the new IP configuration listed. Click OK to close the
Add IP configuration blade.
4. You can click Add to add additional IP configurations, or close all open blades to finish adding IP addresses.
5. Add the private IP addresses to the VM operating system by completing the steps for your operating system in
the Add IP addresses to a VM operating system section of this article.
Add a public IP address
A public IP address is added by associating a public IP address resource to either a new IP configuration or an
existing IP configuration.
NOTE
Public IP addresses have a nominal fee. To learn more about IP address pricing, read the IP address pricing page. There is a
limit to the number of public IP addresses that can be used in a subscription. To learn more about the limits, read the Azure
limits article.
4. Complete the steps in one of the sections that follow to associate the public IP address resource to an IP
configuration.
Associate the public IP address resource to a new IP configuration
1. Complete the steps in the Core steps section of this article.
2. Click Add. In the Add IP configuration blade that appears, create an IP configuration named IPConfig-4.
Enable the Public IP address and select an existing, available public IP address resource from the Choose
public IP address blade that appears.
Once you've selected the public IP address resource, click OK and the blade will close. If you don't have an
existing public IP address, you can create one by completing the steps in the Create a public IP address
resource section of this article.
3. Review the new IP configuration. Even though a private IP address wasn't explicitly assigned, one was
automatically assigned to the IP configuration, because all IP configurations must have a private IP address.
4. You can click Add to add additional IP configurations, or close all open blades to finish adding IP addresses.
5. Add the private IP address to the VM operating system by completing the steps for your operating system in the
Add IP addresses to a VM operating system section of this article. Do not add the public IP address to the
operating system.
Associate the public IP address resource to an existing IP configuration
1. Complete the steps in the Core steps section of this article.
2. Click the IP configuration you want to add the public IP address resource to.
3. In the IPConfig blade that appears, click IP address.
4. In the Choose public IP address blade that appears, select a public IP address.
5. Click Save and the blades will close. If you don't have an existing public IP address, you can create one by
completing the steps in the Create a public IP address resource section of this article.
6. Review the new IP configuration.
7. You can click Add to add additional IP configurations, or close all open blades to finish adding IP addresses. Do
not add the public IP address to the operating system.
WARNING
If you do not follow the steps above correctly, you may lose connectivity to your VM. Ensure the information
entered for step 5 is accurate before proceeding.
Click OK to close out the TCP/IP settings and then OK again to close the adapter settings. Your RDP
connection is re-established.
6. From a command prompt, type ipconfig /all. All IP addresses you added are shown and DHCP is turned off.
Validation (Windows)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, once you have added it correctly using steps above, use the following command:
Linux (Ubuntu)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
cd /etc/network/interfaces.d/
ls
auto eth0
iface eth0 inet dhcp
5. Add the following lines after the lines that exist in this file:
:wq
IMPORTANT
Run both ifdown and ifup in the same line if using a remote connection.
8. Verify the IP address is added to the network interface with the following command:
You should see the IP address you added as part of the list.
Linux (Redhat, CentOS, and others)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
3. Enter your password and follow instructions as prompted. Once you are the root user, navigate to the
network scripts folder with the following command:
cd /etc/sysconfig/network-scripts
ls ifcfg-*
touch ifcfg-eth0:0
vi ifcfg-eth0:0
7. Add content to the file, eth0:0 in this case, with the following command. Be sure to update information based
on your IP address.
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.101.101
NETMASK=255.255.255.0
:wq
9. Restart the network services and make sure the changes are successful by running the following commands:
/etc/init.d/network restart
ifconfig
You should see the IP address you added, eth0:0, in the list returned.
Validation (Linux)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, use the following command:
ping -I 10.0.0.5 hotmail.com
NOTE
For secondary IP configurations, you can only ping to the Internet if the configuration has a public IP address associated with
it. For primary IP configurations, a public IP address is not required to ping to the Internet.
For Linux VMs, when trying to validate outbound connectivity from a secondary NIC, you may need to add
appropriate routes. There are many ways to do this. Please see appropriate documentation for your Linux
distribution. The following is one method to accomplish this:
Be sure to replace:
10.0.0.5 with the private IP address that has a public IP address associated to it
10.0.0.1 to your default gateway
eth2 to the name of your secondary NIC
Assign multiple IP addresses to virtual machines
using PowerShell
6/27/2017 15 min to read Edit Online
An Azure Virtual Machine (VM) has one or more network interfaces (NIC) attached to it. Any NIC can have one or
more static or dynamic public and private IP addresses assigned to it. Assigning multiple IP addresses to a VM
enables the following capabilities:
Hosting multiple websites or services with different IP addresses and SSL certificates on a single server.
Serve as a network virtual appliance, such as a firewall or load balancer.
The ability to add any of the private IP addresses for any of the NICs to an Azure Load Balancer back-end pool.
In the past, only the primary IP address for the primary NIC could be added to a back-end pool. To learn more
about how to load balance multiple IP configurations, read the Load balancing multiple IP configurations article.
Every NIC attached to a VM has one or more IP configurations associated to it. Each configuration is assigned one
static or dynamic private IP address. Each configuration may also have one public IP address resource associated
to it. A public IP address resource has either a dynamic or static public IP address assigned to it. To learn more
about IP addresses in Azure, read the IP addresses in Azure article.
There is a limit to how many private IP addresses can be assigned to a NIC. There is also a limit to how many
public IP addresses that can be used in an Azure subscription. See the Azure limits article for details.
This article explains how to create a virtual machine (VM) through the Azure Resource Manager deployment
model using PowerShell. Multiple IP addresses cannot be assigned to resources created through the classic
deployment model. To learn more about Azure deployment models, read the Understand deployment models
article.
Scenario
A VM with a single NIC is created and connected to a virtual network. The VM requires three different private IP
addresses and two public IP addresses. The IP addresses are assigned to the following IP configurations:
IPConfig-1: Assigns a static private IP address and a static public IP address.
IPConfig-2: Assigns a static private IP address and a static public IP address.
IPConfig-3: Assigns a static private IP address and no public IP address.
The IP configurations are associated to the NIC when the NIC is created and the NIC is attached to the VM when
the VM is created. The types of IP addresses used for the scenario are for illustration. You can assign whatever IP
address and assignment types you require.
NOTE
Though the steps in this article assigns all IP configurations to a single NIC, you can also assign multiple IP configurations to
any NIC in a multi-NIC VM. To learn how to create a VM with multiple NICs, read the Create a VM with multiple NICs article.
$RgName = "MyResourceGroup"
$Location = "westus"
New-AzureRmResourceGroup `
-Name $RgName `
-Location $Location
4. Create a virtual network (VNet) and subnet in the same location as the resource group:
5. Create a network security group (NSG) and a rule. The NSG secures the VM using inbound and outbound
rules. In this case, an inbound rule is created for port 3389, which allows incoming remote desktop
connections.
# Create an inbound network security group rule for port 3389
$NSGRule = New-AzureRmNetworkSecurityRuleConfig `
-Name MyNsgRuleRDP `
-Protocol Tcp `
-Direction Inbound `
-Priority 1000 `
-SourceAddressPrefix * `
-SourcePortRange * `
-DestinationAddressPrefix * `
-DestinationPortRange 3389 -Access Allow
6. Define the primary IP configuration for the NIC. Change 10.0.0.4 to a valid address in the subnet you
created, if you didn't use the value defined previously. Before assigning a static IP address, it's
recommended that you first confirm it's not already in use. Enter the command
Test-AzureRmPrivateIPAddressAvailability -IPAddress 10.0.0.4 -VirtualNetwork $VNet . If the address is
available, the output returns True. If it's not available, the output returns False and a list of addresses that
are available.
In the following commands, Replace with the unique DNS name to use. The name must be unique
across all public IP addresses within an Azure region. This is an optional parameter. It can be removed if you
only want to connect to the VM using the public IP address.
#Create an IP configuration with a static private IP address and assign the public IP ddress to it
$IpConfigName1 = "IPConfig-1"
$IpConfig1 = New-AzureRmNetworkInterfaceIpConfig `
-Name $IpConfigName1 `
-Subnet $Subnet `
-PrivateIpAddress 10.0.0.4 `
-PublicIpAddress $PublicIP1 `
-Primary
When you assign multiple IP configurations to a NIC, one configuration must be assigned as the -Primary.
NOTE
Public IP addresses have a nominal fee. To learn more about IP address pricing, read the IP address pricing page.
There is a limit to the number of public IP addresses that can be used in a subscription. To learn more about the
limits, read the Azure limits article.
7. Define the secondary IP configurations for the NIC. You can add or remove configurations as necessary.
Each IP configuration must have a private IP address assigned. Each configuration can optionally have one
public IP address assigned.
#Create an IP configuration with a static private IP address and assign the public IP ddress to it
$IpConfigName2 = "IPConfig-2"
$IpConfig2 = New-AzureRmNetworkInterfaceIpConfig `
-Name $IpConfigName2 `
-Subnet $Subnet `
-PrivateIpAddress 10.0.0.5 `
-PublicIpAddress $PublicIP2
$IpConfigName3 = "IpConfig-3"
$IpConfig3 = New-AzureRmNetworkInterfaceIpConfig `
-Name $IPConfigName3 `
-Subnet $Subnet `
-PrivateIpAddress 10.0.0.6
$NIC = New-AzureRmNetworkInterface `
-Name MyNIC `
-ResourceGroupName $RgName `
-Location $Location `
-NetworkSecurityGroupId $NSG.Id `
-IpConfiguration $IpConfig1,$IpConfig2,$IpConfig3
NOTE
Though all configurations are assigned to one NIC in this article, you can assign multiple IP configurations to every
NIC attached to the VM. To learn how to create a VM with multiple NICs, read the Create a VM with multiple NICs
article.
# Create the VM
New-AzureRmVM `
-ResourceGroupName $RgName `
-Location $Location `
-VM $VmConfig
10. Add the private IP addresses to the VM operating system by completing the steps for your operating
system in the Add IP addresses to a VM operating system section of this article. Do not add the public IP
addresses to the operating system.
Add IP addresses to a VM
You can add private and public IP addresses to a NIC by completing the steps that follow. The examples in the
following sections assume that you already have a VM with the three IP configurations described in the scenario in
this article, but it's not required that you do.
1. Open a PowerShell command prompt and complete the remaining steps in this section within a single
PowerShell session. If you don't already have PowerShell installed and configured, complete the steps in the
How to install and configure Azure PowerShell article.
2. Change the "values" of the following $Variables to the name of the NIC you want to add IP address to and
the resource group and location the NIC exists in:
$NicName = "MyNIC"
$RgName = "MyResourceGroup"
$Location = "westus"
If you don't know the name of the NIC you want to change, enter the following commands, then change the
values of the previous variables:
3. Create a variable and set it to the existing NIC by typing the following command:
4. In the following commands, change MyVNet and MySubnet to the names of the VNet and subnet the NIC is
connected to. Enter the commands to retrieve the VNet and subnet objects the NIC is connected to:
$MyVNet = Get-AzureRMVirtualnetwork -Name MyVNet -ResourceGroupName $RgName
$Subnet = $MyVnet.Subnets | Where-Object { $_.Name -eq "MySubnet" }
If you don't know the VNet or subnet name the NIC is connected to, enter the following command:
$MyNIC.IpConfigurations
In the output, look for text similar to the following example output:
"Id":
"/subscriptions/[Id]/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVNet/
subnets/MySubnet"
In this output, MyVnet is the VNet and MySubnet is the subnet the NIC is connected to.
5. Complete the steps in one of the following sections, based on your requirements:
Add a private IP address
To add a private IP address to a NIC, you must create an IP configuration. The following command creates a
configuration with a static IP address of 10.0.0.7. When specifying a static IP address, it must be an unused
address for the subnet. It's recommended that you first test the address to ensure it's available by entering
the Test-AzureRmPrivateIPAddressAvailability -IPAddress 10.0.0.7 -VirtualNetwork $myVnet command. If the
IP address is available, the output returns True. If it's not available, the output returns False, and a list of
addresses that are available.
Create as many configurations as you require, using unique configuration names and private IP addresses
(for configurations with static IP addresses).
Add the private IP address to the VM operating system by completing the steps for your operating system
in the Add IP addresses to a VM operating system section of this article.
Add a public IP address
A public IP address is added by associating a public IP address resource to either a new IP configuration or
an existing IP configuration. Complete the steps in one of the sections that follow, as you require.
NOTE
Public IP addresses have a nominal fee. To learn more about IP address pricing, read the IP address pricing page.
There is a limit to the number of public IP addresses that can be used in a subscription. To learn more about the
limits, read the Azure limits article.
To create a new IP configuration with a static private IP address and the associated myPublicIp3
public IP address resource, enter the following command:
Add-AzureRmNetworkInterfaceIpConfig `
-Name IPConfig-4 `
-NetworkInterface $myNIC `
-Subnet $Subnet `
-PrivateIpAddress 10.0.0.7 `
-PublicIpAddress $myPublicIp3
Since the PublicIpAddress column for IpConfig-3 is blank, no public IP address resource is currently
associated to it. You can add an existing public IP address resource to IpConfig-3, or enter the
following command to create one:
$MyPublicIp3 = New-AzureRmPublicIpAddress `
-Name "MyPublicIp3" `
-ResourceGroupName $RgName `
-Location $Location -AllocationMethod Static
Enter the following command to associate the public IP address resource to the existing IP
configuration named IpConfig-3:
Set-AzureRmNetworkInterfaceIpConfig `
-Name IpConfig-3 `
-NetworkInterface $mynic `
-Subnet $Subnet `
-PublicIpAddress $myPublicIp3
6. Set the NIC with the new IP configuration by entering the following command:
8. Add the private IP address to the VM operating system by completing the steps for your operating system in
the Add IP addresses to a VM operating system section of this article. Do not add the public IP address to the
operating system.
WARNING
If you do not follow the steps above correctly, you may lose connectivity to your VM. Ensure the information
entered for step 5 is accurate before proceeding.
Click OK to close out the TCP/IP settings and then OK again to close the adapter settings. Your RDP
connection is re-established.
6. From a command prompt, type ipconfig /all. All IP addresses you added are shown and DHCP is turned off.
Validation (Windows)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, once you have added it correctly using steps above, use the following command:
Linux (Ubuntu)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
cd /etc/network/interfaces.d/
ls
auto eth0
iface eth0 inet dhcp
5. Add the following lines after the lines that exist in this file:
:wq
IMPORTANT
Run both ifdown and ifup in the same line if using a remote connection.
8. Verify the IP address is added to the network interface with the following command:
You should see the IP address you added as part of the list.
Linux (Redhat, CentOS, and others)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
3. Enter your password and follow instructions as prompted. Once you are the root user, navigate to the
network scripts folder with the following command:
cd /etc/sysconfig/network-scripts
ls ifcfg-*
touch ifcfg-eth0:0
vi ifcfg-eth0:0
7. Add content to the file, eth0:0 in this case, with the following command. Be sure to update information
based on your IP address.
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.101.101
NETMASK=255.255.255.0
:wq
9. Restart the network services and make sure the changes are successful by running the following
commands:
/etc/init.d/network restart
ifconfig
You should see the IP address you added, eth0:0, in the list returned.
Validation (Linux)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, use the following command:
ping -I 10.0.0.5 hotmail.com
NOTE
For secondary IP configurations, you can only ping to the Internet if the configuration has a public IP address associated
with it. For primary IP configurations, a public IP address is not required to ping to the Internet.
For Linux VMs, when trying to validate outbound connectivity from a secondary NIC, you may need to add
appropriate routes. There are many ways to do this. Please see appropriate documentation for your Linux
distribution. The following is one method to accomplish this:
Be sure to replace:
10.0.0.5 with the private IP address that has a public IP address associated to it
10.0.0.1 to your default gateway
eth2 to the name of your secondary NIC
Assign multiple IP addresses to virtual machines
using the Azure CLI 2.0
6/27/2017 14 min to read Edit Online
An Azure Virtual Machine (VM) has one or more network interfaces (NIC) attached to it. Any NIC can have one or
more static or dynamic public and private IP addresses assigned to it. Assigning multiple IP addresses to a VM
enables the following capabilities:
Hosting multiple websites or services with different IP addresses and SSL certificates on a single server.
Serve as a network virtual appliance, such as a firewall or load balancer.
The ability to add any of the private IP addresses for any of the NICs to an Azure Load Balancer back-end pool.
In the past, only the primary IP address for the primary NIC could be added to a back-end pool. To learn more
about how to load balance multiple IP configurations, read the Load balancing multiple IP configurations article.
Every NIC attached to a VM has one or more IP configurations associated to it. Each configuration is assigned one
static or dynamic private IP address. Each configuration may also have one public IP address resource associated
to it. A public IP address resource has either a dynamic or static public IP address assigned to it. To learn more
about IP addresses in Azure, read the IP addresses in Azure article.
There is a limit to how many private IP addresses can be assigned to a NIC. There is also a limit to how many
public IP addresses that can be used in an Azure subscription. See the Azure limits article for details.
This article explains how to create a virtual machine (VM) through the Azure Resource Manager deployment
model using the Azure CLI 2.0. Multiple IP addresses cannot be assigned to resources created through the classic
deployment model. To learn more about Azure deployment models, read the Understand deployment models
article.
Scenario
A VM with a single NIC is created and connected to a virtual network. The VM requires three different private IP
addresses and two public IP addresses. The IP addresses are assigned to the following IP configurations:
IPConfig-1: Assigns a static private IP address and a static public IP address.
IPConfig-2: Assigns a static private IP address and a static public IP address.
IPConfig-3: Assigns a static private IP address and no public IP address.
The IP configurations are associated to the NIC when the NIC is created and the NIC is attached to the VM when
the VM is created. The types of IP addresses used for the scenario are for illustration. You can assign whatever IP
address and assignment types you require.
NOTE
Though the steps in this article assigns all IP configurations to a single NIC, you can also assign multiple IP configurations to
any NIC in a multi-NIC VM. To learn how to create a VM with multiple NICs, read the Create a VM with multiple NICs article.
#!/bin/sh
RgName="myResourceGroup"
Location="westcentralus"
az group create --name $RgName --location $Location
# Create a public IP address resource with a static IP address using the `--allocation-method Static` option.
If you
# do not specify this option, the address is allocated dynamically. The address is assigned to the resource
from a pool
# of IP adresses unique to each Azure region. Download and view the file from
# https://www.microsoft.com/en-us/download/details.aspx?id=41653 that lists the ranges for each region.
PipName="myPublicIP"
VnetName="myVnet"
VnetPrefix="10.0.0.0/16"
VnetSubnetName="mySubnet"
VnetSubnetPrefix="10.0.0.0/24"
# Create a network interface connected to the subnet and associate the public IP address to it. Azure will
create the
# first IP configuration with a static private IP address and will associate the public IP address resource to
it.
NicName="MyNic1"
az network nic create \
--name $NicName \
--resource-group $RgName \
--location $Location \
--subnet $VnetSubnet1Name \
--private-ip-address 10.0.0.4
--vnet-name $VnetName \
--public-ip-address $PipName
# Create a second public IP address, a second IP configuration, and associate it to the NIC. This
configuration has a
# static public IP address and a static private IP address.
# Create a third IP configuration, and associate it to the NIC. This configuration has static private IP
address and # no public IP address.
# Note: Though this article assigns all IP configurations to a single NIC, you can also assign multiple IP
configurations
# to any NIC in a VM. To learn how to create a VM with multiple NICs, read the Create a VM with multiple NICs
# article: https://docs.microsoft.com/azure/virtual-network/virtual-network-deploy-multinic-arm-cli.
VmName="myVm"
# Replace the value for the following **VmSize** variable with a value from the
# https://docs.microsoft.com/azure/virtual-machines/virtual-machines-linux-sizes rticle. The script fails if
the VM size
# is not supported in the location you select. Run the `azure vm sizes --location estcentralus` command to get
a full list
# of VMs in US West Central, for example.
VmSize="Standard_DS1"
# Replace the value for the OsImage variable value with a value for *urn* from the utput returned by entering
the
the
# `az vm image list` command.
OsImage="credativ:Debian:8:latest"
Username="adminuser"
# Replace the following value with the path to your public key file. If you're creating a Windows VM, remove
the following
# line and you'll be prompted for the password you want to configure for the VM.
SshKeyValue="~/.ssh/id_rsa.pub"
az vm create \
--name $VmName \
--resource-group $RgName \
--image $OsImage \
--location $Location \
--size $VmSize \
--nics $NicName \
--admin-username $Username \
--ssh-key-value $SshKeyValue
Public IP addresses have a nominal fee. To learn more about IP address pricing, read the IP address pricing page.
There is a limit to the number of public IP addresses that can be used in a subscription. To learn more about the
limits, read the Azure limits article.
After the VM is created, enter the az network nic show --name MyNic1 --resource-group myResourceGroup command
to view the NIC configuration. Enter the
az network nic ip-config list --nic-name MyNic1 --resource-group myResourceGroup --output table to view a list of
the IP configurations associated to the NIC.
Add the private IP addresses to the VM operating system by completing the steps for your operating system in the
Add IP addresses to a VM operating system section of this article.
Add IP addresses to a VM
You can add additional private and public IP addresses to an existing NIC by completing the steps that follow. The
examples build upon the scenario described in this article.
1. Open a command shell and complete the remaining steps in this section within a single session. If you don't
already have Azure CLI installed and configured, complete the steps in the Azure CLI 2.0 installation article
and login to your Azure account with the az-login command.
2. Complete the steps in one of the following sections, based on your requirements:
Add a private IP address
To add a private IP address to a NIC, you must create an IP configuration using the command that follows.
The static IP address must be an unused address for the subnet.
az network nic ip-config create \
--resource-group myResourceGroup \
--nic-name myNic1 \
--private-ip-address 10.0.0.7 \
--name IPConfig-4
Create as many configurations as you require, using unique configuration names and private IP addresses
(for configurations with static IP addresses).
Add a public IP address
A public IP address is added by associating it to either a new IP configuration or an existing IP configuration.
Complete the steps in one of the sections that follow, as you require.
Public IP addresses have a nominal fee. To learn more about IP address pricing, read the IP address pricing
page. There is a limit to the number of public IP addresses that can be used in a subscription. To learn more
about the limits, read the Azure limits article.
Associate the resource to a new IP configuration
Whenever you add a public IP address in a new IP configuration, you must also add a private IP
address, because all IP configurations must have a private IP address. You can either add an existing
public IP address resource, or create a new one. To create a new one, enter the following command:
To create a new IP configuration with a static private IP address and the associated myPublicIP3
public IP address resource, enter the following command:
Associate the resource to an existing IP configuration A public IP address resource can only be
associated to an IP configuration that doesn't already have one associated. You can determine
whether an IP configuration has an associated public IP address by entering the following command:
Returned output:
Name PublicIpAddressId
ipconfig1
/subscriptions/[Id]/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses
/myPublicIP1
IPConfig-2
/subscriptions/[Id]/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses
/myPublicIP2
IPConfig-3
Since the PublicIpAddressId column for IpConfig-3 is blank in the output, no public IP address
resource is currently associated to it. You can add an existing public IP address resource to IpConfig-
3, or enter the following command to create one:
Enter the following command to associate the public IP address resource to the existing IP
configuration named IPConfig-3:
3. View the private IP addresses and the public IP address resource Ids assigned to the NIC by entering the
following command:
Returned output:
4. Add the private IP addresses you added to the NIC to the VM operating system by following the instructions
in the Add IP addresses to a VM operating system section of this article. Do not add the public IP addresses
to the operating system.
Add IP addresses to a VM operating system
Connect and login to a VM you created with multiple private IP addresses. You must manually add all the private
IP addresses (including the primary) that you added to the VM. Complete the following steps for your VM
operating system:
Windows
1. From a command prompt, type ipconfig /all. You only see the Primary private IP address (through DHCP).
2. Type ncpa.cpl in the command prompt to open the Network connections window.
3. Open the properties for the appropriate adapter: Local Area Connection.
4. Double-click Internet Protocol version 4 (IPv4).
5. Select Use the following IP address and enter the following values:
IP address: Enter the Primary private IP address
Subnet mask: Set based on your subnet. For example, if the subnet is a /24 subnet then the subnet
mask is 255.255.255.0.
Default gateway: The first IP address in the subnet. If your subnet is 10.0.0.0/24, then the gateway IP
address is 10.0.0.1.
Click Use the following DNS server addresses and enter the following values:
Preferred DNS server: If you are not using your own DNS server, enter 168.63.129.16. If you are
using your own DNS server, enter the IP address for your server.
Click the Advanced button and add additional IP addresses. Add each of the secondary private IP
addresses listed in step 8 to the NIC with the same subnet specified for the primary IP address.
WARNING
If you do not follow the steps above correctly, you may lose connectivity to your VM. Ensure the information
entered for step 5 is accurate before proceeding.
Click OK to close out the TCP/IP settings and then OK again to close the adapter settings. Your RDP
connection is re-established.
6. From a command prompt, type ipconfig /all. All IP addresses you added are shown and DHCP is turned off.
Validation (Windows)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, once you have added it correctly using steps above, use the following command:
NOTE
For secondary IP configurations, you can only ping to the Internet if the configuration has a public IP address associated
with it. For primary IP configurations, a public IP address is not required to ping to the Internet.
Linux (Ubuntu)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
3. Update the configuration file of the network interface (assuming eth0).
Keep the existing line item for dhcp. The primary IP address remains configured as it was previously.
Add a configuration for an additional static IP address with the following commands:
cd /etc/network/interfaces.d/
ls
auto eth0
iface eth0 inet dhcp
5. Add the following lines after the lines that exist in this file:
:wq
IMPORTANT
Run both ifdown and ifup in the same line if using a remote connection.
8. Verify the IP address is added to the network interface with the following command:
You should see the IP address you added as part of the list.
Linux (Redhat, CentOS, and others)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
3. Enter your password and follow instructions as prompted. Once you are the root user, navigate to the
network scripts folder with the following command:
cd /etc/sysconfig/network-scripts
4. List the related ifcfg files using the following command:
ls ifcfg-*
touch ifcfg-eth0:0
vi ifcfg-eth0:0
7. Add content to the file, eth0:0 in this case, with the following command. Be sure to update information
based on your IP address.
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.101.101
NETMASK=255.255.255.0
:wq
9. Restart the network services and make sure the changes are successful by running the following
commands:
/etc/init.d/network restart
ifconfig
You should see the IP address you added, eth0:0, in the list returned.
Validation (Linux)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, use the following command:
NOTE
For secondary IP configurations, you can only ping to the Internet if the configuration has a public IP address associated
with it. For primary IP configurations, a public IP address is not required to ping to the Internet.
For Linux VMs, when trying to validate outbound connectivity from a secondary NIC, you may need to add
appropriate routes. There are many ways to do this. Please see appropriate documentation for your Linux
distribution. The following is one method to accomplish this:
echo 150 custom >> /etc/iproute2/rt_tables
Be sure to replace:
10.0.0.5 with the private IP address that has a public IP address associated to it
10.0.0.1 to your default gateway
eth2 to the name of your secondary NIC
Assign multiple IP addresses to virtual machines
using an Azure Resource Manager template
6/27/2017 12 min to read Edit Online
An Azure Virtual Machine (VM) has one or more network interfaces (NIC) attached to it. Any NIC can have one or
more static or dynamic public and private IP addresses assigned to it. Assigning multiple IP addresses to a VM
enables the following capabilities:
Hosting multiple websites or services with different IP addresses and SSL certificates on a single server.
Serve as a network virtual appliance, such as a firewall or load balancer.
The ability to add any of the private IP addresses for any of the NICs to an Azure Load Balancer back-end pool.
In the past, only the primary IP address for the primary NIC could be added to a back-end pool. To learn more
about how to load balance multiple IP configurations, read the Load balancing multiple IP configurations article.
Every NIC attached to a VM has one or more IP configurations associated to it. Each configuration is assigned one
static or dynamic private IP address. Each configuration may also have one public IP address resource associated
to it. A public IP address resource has either a dynamic or static public IP address assigned to it. To learn more
about IP addresses in Azure, read the IP addresses in Azure article.
There is a limit to how many private IP addresses can be assigned to a NIC. There is also a limit to how many
public IP addresses that can be used in an Azure subscription. See the Azure limits article for details.
This article explains how to create a virtual machine (VM) through the Azure Resource Manager deployment model
using a Resource Manager template. Multiple public and private IP addresses cannot be assigned to the same NIC
when deploying a VM through the classic deployment model. To learn more about Azure deployment models, read
the Understand deployment models article.
Scenario
A VM with a single NIC is created and connected to a virtual network. The VM requires three different private IP
addresses and two public IP addresses. The IP addresses are assigned to the following IP configurations:
IPConfig-1: Assigns a static private IP address and a static public IP address.
IPConfig-2: Assigns a static private IP address and a static public IP address.
IPConfig-3: Assigns a static private IP address and no public IP address.
The IP configurations are associated to the NIC when the NIC is created and the NIC is attached to the VM when
the VM is created. The types of IP addresses used for the scenario are for illustration. You can assign whatever IP
address and assignment types you require.
NOTE
Though the steps in this article assigns all IP configurations to a single NIC, you can also assign multiple IP configurations to
any NIC in a multi-NIC VM. To learn how to create a VM with multiple NICs, read the Create a VM with multiple NICs article.
Template description
Deploying a template enables you to quickly and consistently create Azure resources with different configuration
values. Read the Resource Manager template walkthrough article if you're not familiar with Azure Resource
Manager templates. The Deploy a VM with multiple IP addresses template is utilized in this article.
Deploying the template creates the following resources:
Public IP address resource 2 are created: myPublicIP and These resources are assigned static
myPublicIP2 public IP addresses and are assigned to
the IPConfig-1 and IPConfig-2 IP
configurations described in the scenario.
When deploying the template, you must specify values for the following parameters:
NAME DESCRIPTION
OSVersion The Windows/Linux version for the VM. The operating system
is a fully patched image of the given Windows/Linux version
selected.
Each of the resources deployed by the template is configured with several default settings. You can view these
settings through either of the following methods:
View the template on GitHub: If you're familiar with templates, you can view the settings within the
template.
View the settings after deploying: If you're not familiar with templates, you can deploy the template using
steps in one of the following sections and then view the settings after deployment.
You can use the Azure portal, PowerShell, or the Azure command-line interface (CLI) to deploy the template. All
methods produce the same result. To deploy the template, complete the steps in one of the following sections :
Directly: Click the following button to open the template directly in the portal:
Regardless of the method you choose, you'll need to supply values for the parameters listed previously in this
article. After the VM is deployed, connect to the VM and add the private IP addresses to the operating system you
deployed by completing the steps in the Add IP addresses to a VM operating system section of this article. Do not
add the public IP addresses to the operating system.
TIP
If you're not sure whether a dnslabelprefix is available, enter the
Test-AzureRmDnsAvailability -DomainNameLabel <name-you-want-to-use> -Location <location> command to
find out. If it is available, the command will return True .
2. After the VM is deployed, connect to the VM and add the private IP addresses to the operating system you
deployed by completing the steps in the Add IP addresses to a VM operating system section of this article.
Do not add the public IP addresses to the operating system.
WARNING
If you do not follow the steps above correctly, you may lose connectivity to your VM. Ensure the information
entered for step 5 is accurate before proceeding.
Click OK to close out the TCP/IP settings and then OK again to close the adapter settings. Your RDP
connection is re-established.
6. From a command prompt, type ipconfig /all. All IP addresses you added are shown and DHCP is turned off.
Validation (Windows)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, once you have added it correctly using steps above, use the following command:
NOTE
For secondary IP configurations, you can only ping to the Internet if the configuration has a public IP address associated
with it. For primary IP configurations, a public IP address is not required to ping to the Internet.
Linux (Ubuntu)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
cd /etc/network/interfaces.d/
ls
5. Add the following lines after the lines that exist in this file:
:wq
IMPORTANT
Run both ifdown and ifup in the same line if using a remote connection.
8. Verify the IP address is added to the network interface with the following command:
You should see the IP address you added as part of the list.
Linux (Redhat, CentOS, and others)
1. Open a terminal window.
2. Make sure you are the root user. If you are not, enter the following command:
sudo -i
3. Enter your password and follow instructions as prompted. Once you are the root user, navigate to the
network scripts folder with the following command:
cd /etc/sysconfig/network-scripts
ls ifcfg-*
touch ifcfg-eth0:0
6. Open the ifcfg-eth0:0 file with the following command:
vi ifcfg-eth0:0
7. Add content to the file, eth0:0 in this case, with the following command. Be sure to update information
based on your IP address.
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.101.101
NETMASK=255.255.255.0
:wq
9. Restart the network services and make sure the changes are successful by running the following
commands:
/etc/init.d/network restart
ifconfig
You should see the IP address you added, eth0:0, in the list returned.
Validation (Linux)
To ensure you are able to connect to the internet from your secondary IP configuration via the public IP associated
it, use the following command:
NOTE
For secondary IP configurations, you can only ping to the Internet if the configuration has a public IP address associated
with it. For primary IP configurations, a public IP address is not required to ping to the Internet.
For Linux VMs, when trying to validate outbound connectivity from a secondary NIC, you may need to add
appropriate routes. There are many ways to do this. Please see appropriate documentation for your Linux
distribution. The following is one method to accomplish this:
Be sure to replace:
10.0.0.5 with the private IP address that has a public IP address associated to it
10.0.0.1 to your default gateway
eth2 to the name of your secondary NIC
Create a virtual machine with Accelerated
Networking
7/26/2017 17 min to read Edit Online
In this tutorial, you learn how to create an Azure Virtual Machine (VM) with Accelerated Networking. Accelerated
Networking is GA for Windows and in a Public Preview for specific Linux distributions. Accelerated networking
enables single root I/O virtualization (SR-IOV) to a VM, greatly improving its networking performance. This high-
performance path bypasses the host from the datapath reducing latency, jitter, and CPU utilization, for use with the
most demanding network workloads on supported VM types. The following picture shows communication between
two virtual machines (VM) with and without accelerated networking:
Without accelerated networking, all networking traffic in and out of the VM must traverse the host and the virtual
switch. The virtual switch provides all policy enforcement, such as network security groups, access control lists,
isolation, and other network virtualized services to network traffic. To learn more about virtual switches, read the
Hyper-V network virtualization and virtual switch article.
With accelerated networking, network traffic arrives at the VM's network interface (NIC), and is then forwarded to
the VM. All network policies that the virtual switch applies without accelerated networking are offloaded and
applied in hardware. Applying policy in hardware enables the NIC to forward network traffic directly to the VM,
bypassing the host and the virtual switch, while maintaining all the policy it applied in the host.
The benefits of accelerated networking only apply to the VM that it is enabled on. For the best results, it is ideal to
enable this feature on at least two VMs connected to the same Azure Virtual Network (VNet). When communicating
across VNets or connecting on-premises, this feature has minimal impact to overall latency.
WARNING
This Linux Public Preview may not have the same level of availability and reliability as features that are in general availability
release. The feature is not supported, may have constrained capabilities, and may not be available in all Azure locations. For
the most up-to-date notifications on availability and status of this feature, check the Azure Virtual Network updates page.
Benefits
Lower Latency / Higher packets per second (pps): Removing the virtual switch from the datapath removes
the time packets spend in the host for policy processing and increases the number of packets that can be
processed inside the VM.
Reduced jitter: Virtual switch processing depends on the amount of policy that needs to be applied and the
workload of the CPU that is doing the processing. Offloading the policy enforcement to the hardware removes
that variability by delivering packets directly to the VM, removing the host to VM communication and all
software interrupts and context switches.
Decreased CPU utilization: Bypassing the virtual switch in the host leads to less CPU utilization for processing
network traffic.
Limitations
The following limitations exist when using this capability:
Network interface creation: Accelerated networking can only be enabled for a new NIC. It cannot be enabled
for an existing NIC.
VM creation: A NIC with accelerated networking enabled can only be attached to a VM when the VM is created.
The NIC cannot be attached to an existing VM.
Regions: Windows VMs with accelerated networking are offered in most Azure regions. Linux VMs with
accelerated networking are offered in multiple regions. The regions this capability is available in is expanding.
Please see the Azure Virtual Networking Updates blog below for the latest information.
Supported operating systems: Windows: Microsoft Windows Server 2012 R2 Datacenter and Windows
Server 2016. Linux: Ubuntu Server 16.04 LTS with kernel 4.4.0-77 or higher, SLES 12 SP2, RHEL 7.3 and CentOS
7.3 (Published by Rogue Wave Software).
VM Size: General purpose and compute-optimized instance sizes with eight or more cores. For more
information, see the Windows and Linux VM sizes articles. The set of supported VM instance sizes will expand in
the future.
Deployment through Azure Resource Manager (ARM) only: Accelerated Networking is not available for
deployment through ASM/RDFE.
Changes to these limitations are announced through the Azure Virtual Networking updates page.
Create a Windows VM
You can use the Azure portal or Azure PowerShell to create the VM.
Portal
1. From an Internet browser, open the Azure portal and sign in with your Azure account. If you don't already have
an account, you can sign up for a free trial.
2. In the portal, click + New > Compute > Windows Server 2016 Datacenter.
3. In the Windows Server 2016 Datacenter blade that appears, leave Resource Manager selected under Select a
deployment model, and click Create.
4. In the Basics blade that appears, enter the following values, leave the remaining default options or select or
enter your own values, and click the OK button:
SETTING VALUE
Name MyVm
Location West US 2
If you're new to Azure, learn more about Resource groups, subscriptions, and locations (which are also
referred to as regions).
5. In the Choose a size blade that appears, enter 8 in the Minimum cores box, then click View all.
6. Click DS4_V2 Standard, or any supported VM, then click the Select button.
7. In the Settings blade that appears, leave all settings as-is, except click Enabled under Accelerated
networking, then click the OK button. Note: If, in previous steps, you selected values for VM size, operating
system, or location that aren't listed in the Limitations section of this article, Accelerated networking isn't
visible.
8. In the Summary blade that appears, click the OK button. Azure starts creating the VM. VM creation takes a few
minutes.
9. To install the accelerated networking driver for Windows, complete the steps in the Configure Windows section
of this article.
PowerShell
1. Install the latest version of the Azure PowerShell AzureRm module. If you're new to Azure PowerShell, read the
Azure PowerShell overview article.
2. Start a PowerShell session by clicking the Windows Start button, typing powershell, then clicking PowerShell
from the search results.
3. In your PowerShell window, enter the login-azurermaccount command to sign in with your Azure account. If you
don't already have an account, you can sign up for a free trial.
4. In your browser, copy the following script:
$RgName="MyResourceGroup"
$Location="westus2"
# Create a subnet
$Subnet = New-AzureRmVirtualNetworkSubnetConfig `
-Name MySubnet `
-AddressPrefix 10.0.0.0/24
# Define a credential object for the VM. PowerShell prompts you for a username and password.
$Cred = Get-Credential
5. In your PowerShell window, right-click to paste the script and start executing it. You are prompted for a
username and password. Use these credentials to log in to the VM when connecting to it in the next step. If the
script fails, and you changed values in the script before executing it, confirm the values you used for VM size,
operating system, and location are listed in the Limitations section of this article.
6. To install the accelerated networking driver for Windows, complete the steps in the Configure Windows section
of this article.
Configure Windows
Once you create the VM in Azure, you must install the accelerated networking driver for Windows. Before
completing the following steps, you must have created a Windows VM with accelerated networking using either the
portal or PowerShell steps in this article.
1. From an Internet browser, open the Azure portal and sign in with your Azure account. If you don't already have
an account, you can sign up for a free trial.
2. In the box that contains the text Search resources at the top of the Azure portal, type MyVm. When MyVm
appears in the search results, click it.
3. In the MyVm blade that appears, click the Connect button in the top left corner of the blade. Note: If Creating
is visible under the Connect button, Azure has not yet finished creating the VM. Click Connect only after you no
longer see Creating under the Connect button.
4. Allow your browser to download the MyVm.rdp file. Once downloaded, click the file to open it.
5. Click the Connect button in the Remote Desktop Connection box that appears, notifying you that the
publisher of the remote connection can't be identified.
6. In the Windows Security box that appears, click More choices, then click Use a different account. Enter the
username and password you entered in step 4, then click the OK button.
7. Click the Yes button in the Remote Desktop Connection box that appears, notifying you that the identity of the
remote computer cannot be verified.
8. Right-click the Windows Start button and click Device Manager. Expand the Network adapters node.
Confirm that the Mellanox ConnectX-3 Virtual Function Ethernet Adapter appears, as shown in the
following picture:
9. Accelerated Networking is now enabled for your VM.
Create a Linux VM
You can use the Azure portal or Azure PowerShell to create an Ubuntu or SLES VM. For RHEL and CentOS VMs
there is a different workflow. Please see the instructions below.
Portal
1. Register for the accelerated networking for Linux preview by completing steps 1-5 of the Create a Linux VM -
PowerShell section of this article. You cannot register for the preview in the portal.
2. Complete steps 1-8 in the Create a Windows VM - portal section of this article. In step 2, click Ubuntu Server
16.04 LTS instead of Windows Server 2016 Datacenter. For this tutorial, choose to use a password, rather
than an SSH key, though for production deployments, you can use either. If Accelerated networking does not
appear when you complete step 7 of the Create a Windows VM - portal section of this article, it's likely for one of
the following reasons:
You are not yet registered for the preview. Confirm that your registration state is Registered, as
explained in step 4 of the Create a Linux VM - Powershell section of this article. Note: If you participated
in the Accelerated networking for Windows VMs preview (it's no longer necessary to register to use
Accelerated networking for Windows VMs), you are not automatically registered for the Accelerated
networking for Linux VMs preview. You must register for the Accelerated networking for Linux VMs
preview to participate in it.
You have not selected a VM size, operating system, or location listed in the Limitations section of this
article.
3. To install the accelerated networking driver for Linux, complete the steps in the Configure Linux section of this
article.
PowerShell
WARNING
If you create Linux VMs with accelerated networking in a subscription, and then attempt to create a Windows VM with
accelerated networking in the same subscription, the Windows VM creation may fail. During this preview, it's recommended
that you test Linux and Windows VMs with accelerated networking in separate subscriptions.
1. Install the latest version of the Azure PowerShell AzureRm module. If you're new to Azure PowerShell, read the
Azure PowerShell overview article.
2. Start a PowerShell session by clicking the Windows Start button, typing powershell, then clicking PowerShell
from the search results.
3. In your PowerShell window, enter the login-azurermaccount command to sign in with your Azure account. If you
don't already have an account, you can sign up for a free trial.
4. Register for the accelerated networking for Azure preview by completing the following steps:
Send an email to axnpreview@microsoft.com with your Azure subscription ID and intended use. Please
wait for an email confirmation from Microsoft about your subscription being enabled.
Enter the following command to confirm you are registered for the preview:
Do not continue with step 5 until Registered appears in the output after you enter the previous
command. Your output must look like the following output before continuing:
NOTE
If you participated in the Accelerated networking for Windows VMs preview (it's no longer necessary to
register to use Accelerated networking for Windows VMs), you are not automatically registered for the
Accelerated networking for Linux VMs preview. You must register for the Accelerated networking for Linux
VMs preview to participate in it.
5. In your browser, copy the following script substituting Ubuntu or SLES as desired. Again, Redhat and CentOS
have a different workflow outlined below:
$RgName="MyResourceGroup"
$Location="westus2"
# Create a subnet
$Subnet = New-AzureRmVirtualNetworkSubnetConfig `
-Name MySubnet `
-AddressPrefix 10.0.0.0/24
# Create a new Storage account and define the new VMs OSDisk name and its URI
# Must end with ".vhd" extension
$OSDiskName = "MyOsDiskName.vhd"
# Storage account name must be between 3 and 24 characters in length and use numbers and lower-case
letters only.
$OSDiskSAName = "thestorageaccountname"
$StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $RgName -Name $OSDiskSAName -Type
"Standard_GRS" -Location $Location
$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName
# Define a credential object for the VM. PowerShell prompts you for a username and password.
$Cred = Get-Credential
6. In your PowerShell window, right-click to paste the script and start executing it. You are prompted for a
username and password. Use these credentials to log in to the VM when connecting to it in the next step. If
the script fails, confirm that:
You are registered for the preview, as explained in step 4
If you changed VM size, operating system type, or location values in the script before executing it, that the
values are listed in the Limitations section of this article.
7. To install the accelerated networking driver for Linux, complete the steps in the Configure Linux section of this
article.
Configure Linux
Once you create the VM in Azure, you must install the accelerated networking driver for Linux. Before completing
the following steps, you must have created a Linux VM with accelerated networking using either the portal or
PowerShell steps in this article.
1. From an Internet browser, open the Azure portal and sign in with your Azure account. If you don't already have
an account, you can sign up for a free trial.
2. At the top of the portal, to the right of the Search resources bar, click the >_ icon to start a Bash cloud shell
(Preview). The Bash cloud shell pane appears at the bottom of the portal and after a few seconds, presents a
username@Azure:~$ prompt. Though you can SSH to the VM from your computer, rather than the cloud shell,
the instructions in this tutorial assume you're using the cloud shell.
3. At the top of the portal, in the box that contains the text Search resources, type MyVm. When MyVm appears in
the search results, click it.
4. In the MyVm blade that appears, click the Connect button in the top left corner of the blade. Note: If Creating
is visible under the Connect button, Azure has not yet finished creating the VM. Click Connect only after you no
longer see Creating under the Connect button.
5. Azure opens a box telling you to enter the ssh adminuser@<ipaddress> . Enter this command in the cloud shell (or
copy it from the box that appeared in step 4 and paste it in to the cloud shell), then press Enter.
6. Enter yes to the question asking you if you want to continue connecting, then press Enter.
7. Enter the password you entered when creating the VM. Once successfully logged in to the VM, you see an
adminuser@MyVm:~$ prompt. You are now logged in to the VM through the cloud shell session. Note: Cloud
shell sessions time out after 10 minutes of inactivity.
At this point, the instructions vary based on the distribution you are using.
Ubuntu/SLES
1. At the prompt, enter uname -r and confirm the version for:
Ubuntu is "4.4.0-77-generic," or greater
SLES is "4.4.59-92.20-default" or greater
2. Create a bond between the standard networking vNIC and the accelerated networking vNIC by running the
commands that follow. Network traffic uses the higher performing accelerated networking vNIC, while the
bond ensures that networking traffic is not interrupted across certain configuration changes.
wget https://raw.githubusercontent.com/LIS/lis-next/master/tools/sriov/configure_hv_sriov.sh
chmod +x ./configure_hv_sriov.sh
sudo ./configure_hv_sriov.sh
3. After running the script, the VM will restart after a 60 second pause.
4. Once the VM is restarted, reconnect to it by completing steps 5-7 again.
5. Run the ifconfig command and confirm that bond0 has come up and the interface is showing as UP.
NOTE
Applications using accelerated networking must communicate over the bond0 interface, not eth0. The interface name
may change before accelerated networking reaches general availability.
RHEL/CentOS
Creating a Red Hat Enterprise Linux or CentOS 7.3 VM requires some extra steps to load the latest drivers needed
for SR-IOV and the Virtual Function (VF) driver for the network card. The first phase of the instructions prepares an
image that can be used to make one or more virtual machines that have the drivers pre-loaded.
P h a se o n e : p r e p a r e a R e d H a t En t e r p r i se L i n u x o r C e n t O S 7.3 b a se i m a g e .
wget http://download.microsoft.com/download/6/8/F/68FE11B8-FAA4-4F8D-8C7D-74DA7F2CFC8C/lis-rpms-4.2.2-
2.tar.gz
tar -xvf lis-rpms-4.2.2-2.tar.gz
cd LISISO && sudo ./install.sh
cd /etc/udev/rules.d/
sudo wget https://raw.githubusercontent.com/LIS/lis-next/master/tools/sriov/60-hyperv-vf-name.rules
cd /usr/sbin/
sudo wget https://raw.githubusercontent.com/LIS/lis-next/master/tools/sriov/hv_vf_name
sudo chmod +x hv_vf_name
cd /etc/sysconfig/network-scripts/
sudo wget https://raw.githubusercontent.com/LIS/lis-next/master/tools/sriov/ifcfg-vf1
4. Deprovision this VM
5. From Azure portal, stop this VM; and go to VMs "Disks", capture the OSDisks VHD URI. This URI contains
the base images VHD name and its storage account.
P h a se t w o : P r o v i si o n n e w V M s o n A z u r e
1. Provision new VMs based with New-AzureRMVMConfig using the base image VHD captured in phase one,
with AcceleratedNetworking enabled on the vNIC:
$RgName="MyResourceGroup"
$Location="westus2"
# Create a subnet
$Subnet = New-AzureRmVirtualNetworkSubnetConfig `
-Name MySubnet `
-AddressPrefix 10.0.0.0/24
# Specify the base image's VHD URI (from phase one step 5).
# Note: The storage account of this base image vhd should have "Storage service encryption" disabled
# See more from here: https://docs.microsoft.com/en-us/azure/storage/storage-service-encryption
# This is just an example URI, you will need to replace this when running this script
$sourceUri="https://myexamplesa.blob.core.windows.net/vhds/CentOS73-Base-Test120170629111341.vhd"
# Specify a URI for the location from which the new image binary large object (BLOB) is copied to start
the virtual machine.
# Must end with ".vhd" extension
$OsDiskName = "MyOsDiskName.vhd"
$destOsDiskUri = "https://myexamplesa.blob.core.windows.net/vhds/" + $OsDiskName
# Define a credential object for the VM. PowerShell prompts you for a username and password.
$Cred = Get-Credential
2. After VMs boot up, check the VF device by "lspci" and check the Mellanox entry. For example, we should see
this item in the lspci output:
sudo bondvf.sh
sudo reboot
The VM should start with bond0 configured and the Accelerated Networking path enabled. Run ifconfig to
confirm.
Configure a VNet-to-VNet VPN gateway connection
using PowerShell
8/31/2017 15 min to read Edit Online
This article shows you how to create a VPN gateway connection between virtual networks. The virtual networks can
be in the same or different regions, and from the same or different subscriptions. When connecting VNets from
different subscriptions, the subscriptions do not need to be associated with the same Active Directory tenant.
The steps in this article apply to the Resource Manager deployment model and use PowerShell. You can also create
this configuration using a different deployment tool or deployment model by selecting a different option from the
following list:
Connecting a virtual network to another virtual network (VNet-to-VNet) is similar to connecting a VNet to an on-
premises site location. Both connectivity types use a VPN gateway to provide a secure tunnel using IPsec/IKE. If
your VNets are in the same region, you may want to consider connecting them using VNet Peering. VNet peering
does not use a VPN gateway. For more information, see VNet peering.
VNet-to-VNet communication can be combined with multi-site configurations. This lets you establish network
topologies that combine cross-premises connectivity with inter-virtual network connectivity, as shown in the
following diagram:
$Sub1 = "Replace_With_Your_Subcription_Name"
$RG1 = "TestRG1"
$Location1 = "East US"
$VNetName1 = "TestVNet1"
$FESubName1 = "FrontEnd"
$BESubName1 = "Backend"
$GWSubName1 = "GatewaySubnet"
$VNetPrefix11 = "10.11.0.0/16"
$VNetPrefix12 = "10.12.0.0/16"
$FESubPrefix1 = "10.11.0.0/24"
$BESubPrefix1 = "10.12.0.0/24"
$GWSubPrefix1 = "10.12.255.0/27"
$GWName1 = "VNet1GW"
$GWIPName1 = "VNet1GWIP"
$GWIPconfName1 = "gwipconf1"
$Connection14 = "VNet1toVNet4"
$Connection15 = "VNet1toVNet5"
2. Connect to your account. Use the following example to help you connect:
Login-AzureRmAccount
Get-AzureRmSubscription
4. Create the subnet configurations for TestVNet1. This example creates a virtual network named TestVNet1
and three subnets, one called GatewaySubnet, one called FrontEnd, and one called Backend. When
substituting values, it's important that you always name your gateway subnet specifically GatewaySubnet. If
you name it something else, your gateway creation fails.
The following example uses the variables that you set earlier. In this example, the gateway subnet is using a
/27. While it is possible to create a gateway subnet as small as /29, we recommend that you create a larger
subnet that includes more addresses by selecting at least /28 or /27. This will allow for enough addresses to
accommodate possible additional configurations that you may want in the future.
5. Create TestVNet1.
6. Request a public IP address to be allocated to the gateway you will create for your VNet. Notice that the
AllocationMethod is Dynamic. You cannot specify the IP address that you want to use. It's dynamically
allocated to your gateway.
7. Create the gateway configuration. The gateway configuration defines the subnet and the public IP address to
use. Use the example to create your gateway configuration.
8. Create the gateway for TestVNet1. In this step, you create the virtual network gateway for your TestVNet1.
VNet-to-VNet configurations require a RouteBased VpnType. Creating a gateway can often take 45 minutes
or more, depending on the selected gateway SKU.
4. Create TestVNet4.
7. Create the TestVNet4 gateway. Creating a gateway can often take 45 minutes or more, depending on the
selected gateway SKU.
2. Create the TestVNet1 to TestVNet4 connection. In this step, you create the connection from TestVNet1 to
TestVNet4. You'll see a shared key referenced in the examples. You can use your own values for the shared
key. The important thing is that the shared key must match for both connections. Creating a connection can
take a short while to complete.
3. Create the TestVNet4 to TestVNet1 connection. This step is similar to the one above, except you are creating
the connection from TestVNet4 to TestVNet1. Make sure the shared keys match. The connection will be
established after a few minutes.
4. Verify your connection. See the section How to verify your connection.
In this scenario, we connect TestVNet1 and TestVNet5. TestVNet1 and TestVNet5 reside in a different subscription.
The subscriptions do not need to be associated with the same Active Directory tenant. The difference between
these steps and the previous set is that some of the configuration steps need to be performed in a separate
PowerShell session in the context of the second subscription. Especially when the two subscriptions belong to
different organizations.
Step 5 - Create and configure TestVNet1
You must complete Step 1 and Step 2 from the previous section to create and configure TestVNet1 and the VPN
Gateway for TestVNet1. For this configuration, you are not required to create TestVNet4 from the previous section,
although if you do create it, it will not conflict with these steps. Once you complete Step 1 and Step 2, continue with
Step 6 to create TestVNet5.
Step 6 - Verify the IP address ranges
It is important to make sure that the IP address space of the new virtual network, TestVNet5, does not overlap with
any of your VNet ranges or local network gateway ranges. In this example, the virtual networks may belong to
different organizations. For this exercise, you can use the following values for the TestVNet5:
Values for TestVNet5:
VNet Name: TestVNet5
Resource Group: TestRG5
Location: Japan East
TestVNet5: 10.51.0.0/16 & 10.52.0.0/16
FrontEnd: 10.51.0.0/24
BackEnd: 10.52.0.0/24
GatewaySubnet: 10.52.255.0.0/27
GatewayName: VNet5GW
Public IP: VNet5GWIP
VPNType: RouteBased
Connection: VNet5toVNet1
ConnectionType: VNet2VNet
Step 7 - Create and configure TestVNet5
This step must be done in the context of the new subscription. This part may be performed by the administrator in
a different organization that owns the subscription.
1. Declare your variables. Be sure to replace the values with the ones that you want to use for your
configuration.
$Sub5 = "Replace_With_the_New_Subcription_Name"
$RG5 = "TestRG5"
$Location5 = "Japan East"
$VnetName5 = "TestVNet5"
$FESubName5 = "FrontEnd"
$BESubName5 = "Backend"
$GWSubName5 = "GatewaySubnet"
$VnetPrefix51 = "10.51.0.0/16"
$VnetPrefix52 = "10.52.0.0/16"
$FESubPrefix5 = "10.51.0.0/24"
$BESubPrefix5 = "10.52.0.0/24"
$GWSubPrefix5 = "10.52.255.0/27"
$GWName5 = "VNet5GW"
$GWIPName5 = "VNet5GWIP"
$GWIPconfName5 = "gwipconf5"
$Connection51 = "VNet5toVNet1"
2. Connect to subscription 5. Open your PowerShell console and connect to your account. Use the following
sample to help you connect:
Login-AzureRmAccount
Get-AzureRmSubscription
5. Create TestVNet5.
Copy the output of the following elements and send these to the administrator of Subscription 5 via email
or another method.
$vnet1gw.Name
$vnet1gw.Id
These two elements will have values similar to the following example output:
PS D:\> $vnet1gw.Name
VNet1GW
PS D:\> $vnet1gw.Id
/subscriptions/b636ca99-6f88-4df4-a7c3-
2f8dc4545509/resourceGroupsTestRG1/providers/Microsoft.Network/virtualNetworkGateways/VNet1GW
2. [Subscription 5] Get the virtual network gateway for Subscription 5. Log in and connect to Subscription 5
before running the following example:
$vnet5gw = Get-AzureRmVirtualNetworkGateway -Name $GWName5 -ResourceGroupName $RG5
Copy the output of the following elements and send these to the administrator of Subscription 1 via email
or another method.
$vnet5gw.Name
$vnet5gw.Id
These two elements will have values similar to the following example output:
PS C:\> $vnet5gw.Name
VNet5GW
PS C:\> $vnet5gw.Id
/subscriptions/66c8e4f1-ecd6-47ed-9de7-
7e530de23994/resourceGroups/TestRG5/providers/Microsoft.Network/virtualNetworkGateways/VNet5GW
3. [Subscription 1] Create the TestVNet1 to TestVNet5 connection. In this step, you create the connection
from TestVNet1 to TestVNet5. The difference here is that $vnet5gw cannot be obtained directly because it is
in a different subscription. You will need to create a new PowerShell object with the values communicated
from Subscription 1 in the steps above. Use the example below. Replace the Name, Id, and shared key with
your own values. The important thing is that the shared key must match for both connections. Creating a
connection can take a short while to complete.
Connect to Subscription 1 before running the following example:
4. [Subscription 5] Create the TestVNet5 to TestVNet1 connection. This step is similar to the one above,
except you are creating the connection from TestVNet5 to TestVNet1. The same process of creating a
PowerShell object based on the values obtained from Subscription 1 applies here as well. In this step, be
sure that the shared keys match.
Connect to Subscription 5 before running the following example:
You can verify that your connection succeeded by using the 'Get-AzureRmVirtualNetworkGatewayConnection'
cmdlet, with or without '-Debug'.
1. Use the following cmdlet example, configuring the values to match your own. If prompted, select 'A' in order
to run 'All'. In the example, '-Name' refers to the name of the connection that you want to test.
2. After the cmdlet has finished, view the values. In the example below, the connection status shows as
'Connected' and you can see ingress and egress bytes.
"connectionStatus": "Connected",
"ingressBytesTransferred": 33509044,
"egressBytesTransferred": 4142431
VNet-to-VNet FAQ
The VNet-to-VNet FAQ applies to VPN Gateway connections. If you are looking for VNet Peering, see Virtual
Network Peering
Does Azure charge for traffic between VNets?
VNet-to-VNet traffic within the same region is free for both directions when using a VPN gateway connection.
Cross region VNet-to-VNet egress traffic is charged with the outbound inter-VNet data transfer rates based on the
source regions. Refer to the VPN Gateway pricing page for details. If you are connecting your VNets using VNet
Peering, rather than VPN Gateway, see the Virtual Network pricing page.
Does VNet-to -VNet traffic travel across the Internet?
No. VNet-to-VNet traffic travels across the Microsoft Azure backbone, not the Internet.
Is VNet-to -VNet traffic secure?
Yes, it is protected by IPsec/IKE encryption.
Do I need a VPN device to connect VNets together?
No. Connecting multiple Azure virtual networks together doesn't require a VPN device unless cross-premises
connectivity is required.
Do my VNets need to be in the same region?
No. The virtual networks can be in the same or different Azure regions (locations).
If the VNets are not in the same subscription, do the subscriptions need to be associated with the same AD
tenant?
No.
Can I use VNet-to -VNet to connect virtual networks in separate Azure instances?
No. VNet-to-VNet supports connecting virtual networks within the same Azure instance. For example, you cant
create a connection between public Azure and the Chinese / German / US Gov Azure instances. For these scenarios,
consider using a Site-to-Site VPN connection.
Can I use VNet-to -VNet along with multi-site connections?
Yes. Virtual network connectivity can be used simultaneously with multi-site VPNs.
How many on-premises sites and virtual networks can one virtual network connect to?
See Gateway requirements table.
Can I use VNet-to -VNet to connect VMs or cloud services outside of a VNet?
No. VNet-to-VNet supports connecting virtual networks. It does not support connecting virtual machines or cloud
services that are not in a virtual network.
Can a cloud service or a load balancing endpoint span VNets?
No. A cloud service or a load balancing endpoint can't span across virtual networks, even if they are connected
together.
Can I used a PolicyBased VPN type for VNet-to -VNet or Multi-Site connections?
No. VNet-to-VNet and Multi-Site connections require Azure VPN gateways with RouteBased (previously called
Dynamic Routing) VPN types.
Can I connect a VNet with a RouteBased VPN Type to another VNet with a PolicyBased VPN type?
No, both virtual networks MUST be using route-based (previously called Dynamic Routing) VPNs.
Do VPN tunnels share bandwidth?
Yes. All VPN tunnels of the virtual network share the available bandwidth on the Azure VPN gateway and the same
VPN gateway uptime SLA in Azure.
Are redundant tunnels supported?
Redundant tunnels between a pair of virtual networks are supported when one virtual network gateway is
configured as active-active.
Can I have overlapping address spaces for VNet-to -VNet configurations?
No. You can't have overlapping IP address ranges.
Can there be overlapping address spaces among connected virtual networks and on-premises local sites?
No. You can't have overlapping IP address ranges.
Next steps
Once your connection is complete, you can add virtual machines to your virtual networks. See the Virtual
Machines documentation for more information.
For information about BGP, see the BGP Overview and How to configure BGP.
Connect virtual networks from different deployment
models using the portal
8/31/2017 19 min to read Edit Online
This article shows you how to connect classic VNets to Resource Manager VNets to allow the resources located in
the separate deployment models to communicate with each other. The steps in this article primarily use the Azure
portal, but you can also create this configuration using the PowerShell by selecting the article from this list.
Connecting a classic VNet to a Resource Manager VNet is similar to connecting a VNet to an on-premises site
location. Both connectivity types use a VPN gateway to provide a secure tunnel using IPsec/IKE. You can create a
connection between VNets that are in different subscriptions and in different regions. You can also connect VNets
that already have connections to on-premises networks, as long as the gateway that they have been configured
with is dynamic or route-based. For more information about VNet-to-VNet connections, see the VNet-to-VNet FAQ
at the end of this article.
If your VNets are in the same region, you may want to instead consider connecting them using VNet Peering. VNet
peering does not use a VPN gateway. For more information, see VNet peering.
Before you begin
These steps assume that both VNets have already been created. If you are using this article as an exercise and
don't have VNets, there are links in the steps to help you create them.
Verify that the address ranges for the VNets do not overlap with each other, or overlap with any of the ranges
for other connections that the gateways may be connected to.
Install the latest PowerShell cmdlets for both Resource Manager and Service Management (classic). In this
article, we use both the Azure portal and PowerShell. PowerShell is required to create the connection from the
classic VNet to the Resource Manager VNet. For more information, see How to install and configure Azure
PowerShell.
Example settings
You can use these values to create a test environment, or refer to them to better understand the examples in this
article.
Classic VNet
VNet name = ClassicVNet
Address space = 10.0.0.0/24
Subnet-1 = 10.0.0.0/27
Resource Group = ClassicRG
Location = West US
GatewaySubnet = 10.0.0.32/28
Local site = RMVNetLocal
Resource Manager VNet
VNet name = RMVNet
Address space = 192.168.0.0/16
Subnet-1 = 192.168.1.0/24
GatewaySubnet = 192.168.0.0/26
Resource Group = RG1
Location = East US
Virtual network gateway name = RMGateway
Gateway type = VPN
VPN type = Route-based
Gateway Public IP address name = rmgwpip
Local network gateway = ClassicVNetLocal
Connection name = RMtoClassic
Connection overview
For this configuration, you create a VPN gateway connection over an IPsec/IKE VPN tunnel between the virtual
networks. Make sure that none of your VNet ranges overlap with each other, or with any of the local networks that
they connect to.
The following table shows an example of how the example VNets and local sites are defined:
CONNECTS TO LOCAL
VIRTUAL NETWORK ADDRESS SPACE REGION NETWORK SITE
2. Click Subnet - Configure required settings to open the Add subnet blade. The Name is already configured
with the required value GatewaySubnet.
3. The Address range refers to the range for the gateway subnet. Although you can create a gateway subnet with
a /29 address range (3 addresses), we recommend creating a gateway subnet that contains more IP addresses.
This will accommodate future configurations that may require more available IP addresses. If possible, use /27
or /28. If you are using these steps as an exercise, you can refer to the Example values. Click OK to create the
gateway subnet.
4. On the Gateway configuration blade, Size refers to the gateway SKU. Select the gateway SKU for your VPN
gateway.
5. Verify the Routing Type is Dynamic, then click OK to return to the New VPN Connection blade.
6. On the New VPN Connection blade, click OK to begin creating your VPN gateway. Creating a VPN gateway
can take up to 45 minutes to complete.
3. Copy the virtual network gateway Public IP address
After the virtual network gateway has been created, you can view the gateway IP address.
1. Navigate to your classic VNet, and click Overview.
2. Click VPN connections to open the VPN connections blade. On the VPN connections blade, you can view the
Public IP address. This is the Public IP address assigned to your virtual network gateway.
3. Write down or copy the IP address. You use it in later steps when you work with your Resource Manager local
network gateway configuration settings. You can also view the status of your gateway connections. Notice the
local network site you created is listed as 'Connecting'. The status will change after you have created your
connections.
4. Close the blade after copying the gateway IP address.
IMPORTANT
When working with gateway subnets, avoid associating a network security group (NSG) to the gateway subnet. Associating a
network security group to this subnet may cause your VPN gateway to stop functioning as expected. For more information
about network security groups, see What is a network security group?
1. In the portal, navigate to the Resource Manager virtual network for which you want to create a virtual network
gateway.
2. In the Settings section of your VNet page, click Subnets to expand the Subnets page.
3. On the Subnets page, click +Gateway subnet to open the Add subnet page.
4. The Name for your subnet is automatically filled in with the value 'GatewaySubnet'. This value is required in
order for Azure to recognize the subnet as the gateway subnet. Adjust the auto-filled Address range values
to match your configuration requirements, then click OK at the bottom of the page to create the subnet.
3. Name: Name your gateway. The name of your gateway is not the same as naming a gateway subnet. It's the
name of the gateway object you are creating.
4. Gateway type: Select VPN. VPN gateways use the virtual network gateway type VPN.
5. VPN type: Select the VPN type that is specified for your configuration. Most configurations require a Route-
based VPN type.
6. SKU: Select the gateway SKU from the dropdown. The SKUs listed in the dropdown depend on the VPN type
you select.
7. Location: Adjust the Location field to point to the location where your virtual network is located. If the location
is not pointing to the region where your virtual network resides, the virtual network doesn't appear in the
'Choose a virtual network' dropdown.
8. Choose the virtual network to which you want to add a gateway. Click Virtual network to open the Choose a
virtual network page. Select the VNet. If you don't see your VNet, make sure the Location field is pointing to
the region in which your virtual network is located.
9. Public IP address: Create a public IP address object to which a public IP address will be dynamically assigned.
Click Public IP address to open the Choose public IP address page. Click +Create New to open the Create
public IP address page. Input a name for your public IP address. Click OK to save your changes. The IP address
is dynamically assigned when the VPN gateway is created. VPN Gateway currently only supports Dynamic
Public IP address allocation. However, it doesn't mean that the IP address changes after it has been assigned to
your VPN gateway. The only time the Public IP address changes is when the gateway is deleted and re-created. It
doesn't change across resizing, resetting, or other internal maintenance/upgrades of your VPN gateway.
10. Subscription: Verify that the correct subscription is selected.
11. Resource group: The Resource Group setting is determined by the Virtual Network that you select.
12. Don't adjust the Location after you've specified the previous settings.
13. Verify the settings. If you want your gateway to appear on the dashboard, you can select Pin to dashboard at
the bottom of the page.
14. Click Create to begin creating the gateway. The settings are validated and the gateway deploys. Creating a
gateway can take up to 45 minutes.
15. After the gateway is created, view the IP address that has been assigned to it by looking at the virtual network
page. The gateway appears as a connected device. You can click the connected device (your virtual network
gateway) to view more information.
3. Create a local network gateway
The local network gateway specifies the address range and the Public IP address associated with your classic VNet
and its virtual network gateway.
If you are doing these steps as an exercise, refer to these settings:
1. In the portal, from All resources, click +Add. In the Everything blade search box, type Local network
gateway, then click to return a list of resources. Click Local network gateway to open the blade, then click
Create to open the Create local network gateway blade.
2. On the Create local network gateway blade, specify a Name for your local network gateway object. If
possible, use something intuitive, such as ClassicVNetLocal or TestVNet1Local. This makes it easier for
you to identify the local network gateway in the portal.
3. Specify a valid Public IP address for the VPN device or virtual network gateway to which you want to connect.
If this local network represents an on-premises location: Specify the Public IP address of the VPN device
that you want to connect to. It cannot be behind NAT and has to be reachable by Azure.
If this local network represents another VNet: Specify the Public IP address that was assigned to the virtual
network gateway for that VNet.
If you don't yet have the IP address: You can make up a valid placeholder IP address, and then come back
and modify this setting before connecting.
4. Address Space refers to the address ranges for the network that this local network represents. You can add
multiple address space ranges. Make sure that the ranges you specify here do not overlap with ranges of other
networks to which you connect.
5. For Subscription, verify that the correct subscription is showing.
6. For Resource Group, select the resource group that you want to use. You can either create a new resource
group, or select one that you have already created.
7. For Location, select the location in which this resource will be created. You may want to select the same
location that your VNet resides in, but you are not required to do so.
8. Click Create to create the local network gateway.
4. On the Site-to-site VPN connections blade, click the name of the site.
5. On the connection blade for your local site, click the name of the local site to open the Local site blade.
6. On the Local site blade, replace the VPN gateway IP address with the IP address of the Resource Manager
gateway.
7. Click OK to update the IP address.
Login-AzureRmAccount
Get a list of your Azure subscriptions if you have more than one subscription.
Get-AzureRmSubscription
Add your Azure Account to use the classic PowerShell cmdlets (SM). To do so, you can use the following command:
Add-AzureAccount
Open the file with a text editor and view the name for your classic VNet. Use the names in the network
configuration file when running your PowerShell cmdlets.
VNet names are listed as VirtualNetworkSite name =
Site names are listed as LocalNetworkSite name=
3. Create the connection
Set the shared key and create the connection from the classic VNet to the Resource Manager VNet. You cannot set
the shared key using the portal. Make sure you run these steps while logged in using the classic version of the
PowerShell cmdlets. To do so, use Add-AzureAccount. Otherwise, you will not be able to set the '-
AzureVNetGatewayKey'.
In this example, -VNetName is the name of the classic VNet as found in your network configuration file.
The -LocalNetworkSiteName is the name you specified for the local site, as found in your network
configuration file.
The -SharedKey is a value that you generate and specify. For this example, we used abc123, but you can
generate something more complex. The important thing is that the value you specify here must be the same
value that you specified when creating your Resource Manager to classic connection.
4. On the Site-to-site VPN connections blade, view the information about your site.
5. To view more information about the connection, click the name of the connection to open the Site-to-site
VPN Connection blade.
To verify the connection from your Resource Manager VNet to your classic VNet
In the Azure portal, you can view the connection status of a Resource Manager VPN Gateway by navigating to the
connection. The following steps show one way to navigate to your connection and verify.
1. In the Azure portal, click All resources and navigate to your virtual network gateway.
2. On the blade for your virtual network gateway, click Connections. You can see the status of each connection.
3. Click the name of the connection that you want to verify to open Essentials. In Essentials, you can view
more information about your connection. The Status is 'Succeeded' and 'Connected' when you have made a
successful connection.
VNet-to-VNet FAQ
The VNet-to-VNet FAQ applies to VPN Gateway connections. If you are looking for VNet Peering, see Virtual
Network Peering
Does Azure charge for traffic between VNets?
VNet-to-VNet traffic within the same region is free for both directions when using a VPN gateway connection.
Cross region VNet-to-VNet egress traffic is charged with the outbound inter-VNet data transfer rates based on the
source regions. Refer to the VPN Gateway pricing page for details. If you are connecting your VNets using VNet
Peering, rather than VPN Gateway, see the Virtual Network pricing page.
Does VNet-to -VNet traffic travel across the Internet?
No. VNet-to-VNet traffic travels across the Microsoft Azure backbone, not the Internet.
Is VNet-to -VNet traffic secure?
Yes, it is protected by IPsec/IKE encryption.
Do I need a VPN device to connect VNets together?
No. Connecting multiple Azure virtual networks together doesn't require a VPN device unless cross-premises
connectivity is required.
Do my VNets need to be in the same region?
No. The virtual networks can be in the same or different Azure regions (locations).
If the VNets are not in the same subscription, do the subscriptions need to be associated with the same AD
tenant?
No.
Can I use VNet-to -VNet to connect virtual networks in separate Azure instances?
No. VNet-to-VNet supports connecting virtual networks within the same Azure instance. For example, you cant
create a connection between public Azure and the Chinese / German / US Gov Azure instances. For these scenarios,
consider using a Site-to-Site VPN connection.
Can I use VNet-to -VNet along with multi-site connections?
Yes. Virtual network connectivity can be used simultaneously with multi-site VPNs.
How many on-premises sites and virtual networks can one virtual network connect to?
See Gateway requirements table.
Can I use VNet-to -VNet to connect VMs or cloud services outside of a VNet?
No. VNet-to-VNet supports connecting virtual networks. It does not support connecting virtual machines or cloud
services that are not in a virtual network.
Can a cloud service or a load balancing endpoint span VNets?
No. A cloud service or a load balancing endpoint can't span across virtual networks, even if they are connected
together.
Can I used a PolicyBased VPN type for VNet-to -VNet or Multi-Site connections?
No. VNet-to-VNet and Multi-Site connections require Azure VPN gateways with RouteBased (previously called
Dynamic Routing) VPN types.
Can I connect a VNet with a RouteBased VPN Type to another VNet with a PolicyBased VPN type?
No, both virtual networks MUST be using route-based (previously called Dynamic Routing) VPNs.
Do VPN tunnels share bandwidth?
Yes. All VPN tunnels of the virtual network share the available bandwidth on the Azure VPN gateway and the same
VPN gateway uptime SLA in Azure.
Are redundant tunnels supported?
Redundant tunnels between a pair of virtual networks are supported when one virtual network gateway is
configured as active-active.
Can I have overlapping address spaces for VNet-to -VNet configurations?
No. You can't have overlapping IP address ranges.
Can there be overlapping address spaces among connected virtual networks and on-premises local sites?
No. You can't have overlapping IP address ranges.
Create a Site-to-Site connection in the Azure portal
8/15/2017 16 min to read Edit Online
This article shows you how to use the Azure portal to create a Site-to-Site VPN gateway connection from your on-
premises network to the VNet. The steps in this article apply to the Resource Manager deployment model. You can
also create this configuration using a different deployment tool or deployment model by selecting a different
option from the following list:
A Site-to-Site VPN gateway connection is used to connect your on-premises network to an Azure virtual network
over an IPsec/IKE (IKEv1 or IKEv2) VPN tunnel. This type of connection requires a VPN device located on-premises
that has an externally facing public IP address assigned to it. For more information about VPN gateways, see
About VPN gateway.
4. The Name for your subnet is automatically filled in with the value 'GatewaySubnet'. The GatewaySubnet
value is required in order for Azure to recognize the subnet as the gateway subnet. Adjust the auto-filled
Address range values to match your configuration requirements.
3. On the Create local network gateway blade, specify the values for your local network gateway.
Name: Specify a name for your local network gateway object.
IP address: This is the public IP address of the VPN device that you want Azure to connect to. Specify a
valid public IP address. The IP address cannot be behind NAT and has to be reachable by Azure. If you
don't have the IP address right now, you can use the values shown in the screen shot, but you'll need to
go back and replace your placeholder IP address with the public IP address of your VPN device.
Otherwise, Azure will not be able to connect.
Address Space refers to the address ranges for the network that this local network represents. You can
add multiple address space ranges. Make sure that the ranges you specify here do not overlap with
ranges of other networks that you want to connect to. Azure will route the address range that you
specify to the on-premises VPN device IP address. Use your own values here, not the values shown in
the screenshot.
Subscription: Verify that the correct subscription is showing.
Resource Group: Select the resource group that you want to use. You can either create a new resource
group, or select one that you have already created.
Location: Select the location that this object will be created in. You may want to select the same location
that your VNet resides in, but you are not required to do so.
4. When you have finished specifying the values, click Create at the bottom of the blade to create the local
network gateway.
3. On the Add connection blade, fill in the values to create your connection.
Name: Name your connection. We use VNet1toSite2 in our example.
Connection type: Select Site-to-site(IPSec).
Virtual network gateway: The value is fixed because you are connecting from this gateway.
Local network gateway: Click Choose a local network gateway and select the local network
gateway that you want to use. In our example, we use Site2.
Shared Key: the value here must match the value that you are using for your local on-premises VPN
device. In the example, we used 'abc123', but you can (and should) use something more complex. The
important thing is that the value you specify here must be the same value that you specified when
configuring your VPN device.
The remaining values for Subscription, Resource Group, and Location are fixed.
4. Click OK to create your connection. You'll see Creating Connection flash on the screen.
5. You can view the connection in the Connections blade of the virtual network gateway. The Status will go from
Unknown to Connecting, and then to Succeeded.
$VMs = Get-AzureRmVM
$Nics = Get-AzureRmNetworkInterface | Where VirtualMachine -ne $null
foreach($Nic in $Nics)
{
$VM = $VMs | Where-Object -Property Id -eq $Nic.VirtualMachine.Id
$Prv = $Nic.IpConfigurations | Select-Object -ExpandProperty PrivateIpAddress
$Alloc = $Nic.IpConfigurations | Select-Object -ExpandProperty PrivateIpAllocationMethod
Write-Output "$($VM.Name): $Prv,$Alloc"
}
2. Verify that you are connected to your VNet using the VPN connection.
3. Open Remote Desktop Connection by typing "RDP" or "Remote Desktop Connection" in the search box on
the taskbar, then select Remote Desktop Connection. You can also open Remote Desktop Connection using the
'mstsc' command in PowerShell.
4. In Remote Desktop Connection, enter the private IP address of the VM. You can click "Show Options" to adjust
additional settings, then connect.
To troubleshoot an RDP connection to a VM
If you are having trouble connecting to a virtual machine over your VPN connection, check the following:
Verify that your VPN connection is successful.
Verify that you are connecting to the private IP address for the VM.
If you can connect to the VM using the private IP address, but not the computer name, verify that you have
configured DNS properly. For more information about how name resolution works for VMs, see Name
Resolution for VMs.
For more information about RDP connections, see Troubleshoot Remote Desktop connections to a VM.
How to reset a VPN gateway
Resetting an Azure VPN gateway is helpful if you lose cross-premises VPN connectivity on one or more Site-to-
Site VPN tunnels. In this situation, your on-premises VPN devices are all working correctly, but are not able to
establish IPsec tunnels with the Azure VPN gateways. For steps, see Reset a VPN gateway.
Next steps
For information about BGP, see the BGP Overview and How to configure BGP.
For information about Forced Tunneling, see About Forced Tunneling.
For information about Highly Available Active-Active connections, see Highly Available cross-premises and
VNet-to-VNet connectivity.
Connect a virtual network to an ExpressRoute circuit
7/27/2017 4 min to read Edit Online
This article helps you link virtual networks (VNets) to Azure ExpressRoute circuits by using the Resource Manager
deployment model and the Azure portal. Virtual networks can either be in the same subscription, or they can be
part of another subscription.
NOTE
BGP configuration information will not show up if the layer 3 provider configured your peerings. If your circuit is in a
provisioned state, you should be able to create connections.
1. Ensure that your ExpressRoute circuit and Azure private peering have been configured successfully. Follow
the instructions in Create an ExpressRoute circuit and Configure routing. Your ExpressRoute circuit should
look like the following image:
2. You can now start provisioning a connection to link your virtual network gateway to your ExpressRoute
circuit. Click Connection > Add to open the Add connection blade, and then configure the values.
3. After your connection has been successfully configured, your connection object will show the information
for the connection.
To delete a connection
You can delete a connection by selecting the Delete icon on the blade for your connection.
NOTE
Connectivity and bandwidth charges for the dedicated circuit will be applied to the ExpressRoute circuit owner. All
virtual networks share the same bandwidth.
2. Search for "Connection" in the Marketplace, select it, and click Create.
3. Make sure the Connection type is set to "ExpressRoute".
4. Fill in the details, then click OK in the Basics blade.
5. In the Settings blade, Select the Virtual network gateway and check the Redeem authorization check
box.
6. Enter the Authorization key and the Peer circuit URI and give the connection a name. Click OK.
7. Review the information in the Summary blade and click OK.
To release a connection authorization
You can release an authorization by deleting the connection that links the ExpressRoute circuit to the virtual
network.
Next steps
For more information about ExpressRoute, see the ExpressRoute FAQ.
1 min to read
Edit O nline
Virtual appliance scenario
6/27/2017 8 min to read Edit Online
A common scenario among larger Azure customer is the need to provide a two-tiered application exposed to the
Internet, while allowing access to the back tier from an on-premises datacenter. This document will walk you
through a scenario using User Defined Routes (UDR), a VPN Gateway, and network virtual appliances to deploy a
two-tier environment that meets the following requirements:
Web application must be accessible from the public Internet only.
Web server hosting the application must be able to access a backend application server.
All traffic from the Internet to the web application must go through a firewall virtual appliance. This virtual
appliance will be used for Internet traffic only.
All traffic going to the application server must go through a firewall virtual appliance. This virtual appliance will
be used for access to the backend end server, and access coming in from the on-premises network via a VPN
Gateway.
Administrators must be able to manage the firewall virtual appliances from their on-premises computers, by
using a third firewall virtual appliance used exclusively for management purposes.
This is a standard DMZ scenario with a DMZ and a protected network. Such scenario can be constructed in Azure by
using NSGs, firewall virtual appliances, or a combination of both. The table below shows some of the pros and cons
between NSGs and firewall virtual appliances.
PROS CONS
The solution below uses firewall virtual appliances to implement a DMZ/protected network scenario.
Considerations
You can deploy the environment explained above in Azure using different features available today, as follows.
Virtual network (VNet). An Azure VNet acts in similar fashion to an on-premises network, and can be
segmented into one or more subnets to provide traffic isolation, and separation of concerns.
Virtual appliance. Several partners provide virtual appliances in the Azure Marketplace that can be used for the
three firewalls described above.
User Defined Routes (UDR). Route tables can contain UDRs used by Azure networking to control the flow of
packets within a VNet. These route tables can be applied to subnets. One of the newest features in Azure is the
ability to apply a route table to the GatewaySubnet, providing the ability to forward all traffic coming into the
Azure VNet from a hybrid connection to a virtual appliance.
IP Forwarding. By default, the Azure networking engine forward packets to virtual network interface cards
(NICs) only if the packet destination IP address matches the NIC IP address. Therefore, if a UDR defines that a
packet must be sent to a given virtual appliance, the Azure networking engine would drop that packet. To ensure
the packet is delivered to a VM (in this case a virtual appliance) that is not the actual destination for the packet,
you need to enable IP Forwarding for the virtual appliance.
Network Security Groups (NSGs). The example below does not make use of NSGs, but you could use NSGs
applied to the subnets and/or NICs in this solution to further filter the traffic in and out of those subnets and
NICs.
azsn2udr
DESTINATION NEXT HOP EXPLANATION
azsn3udr
DESTINATION NEXT HOP EXPLANATION
You also need to create route tables for the subnets in onpremvnet to mimic the on-premises datacenter.
onpremsn1udr
DESTINATION NEXT HOP EXPLANATION
onpremsn2udr
DESTINATION NEXT HOP EXPLANATION
IP Forwarding
UDR and IP Forwarding are features that you can use in combination to allow virtual appliances to be used to
control traffic flow in an Azure VNet. A virtual appliance is nothing more than a VM that runs an application used to
handle network traffic in some way, such as a firewall or a NAT device.
This virtual appliance VM must be able to receive incoming traffic that is not addressed to itself. To allow a VM to
receive traffic addressed to other destinations, you must enable IP Forwarding for the VM. This is an Azure setting,
not a setting in the guest operating system. Your virtual appliance still needs to run some type of application to
handle the incoming traffic, and route it appropriately.
To learn more about IP Forwarding, visit What are User Defined Routes and IP Forwarding.
As an example, imagine you have the following setup in an Azure vnet:
Subnet onpremsn1 contains a VM named onpremvm1.
Subnet onpremsn2 contains a VM named onpremvm2.
A virtual appliance named OPFW is connected to onpremsn1 and onpremsn2.
A user defined route linked to onpremsn1 specifies that all traffic to onpremsn2 must be sent to OPFW.
At this point, if onpremvm1 tries to establish a connection with onpremvm2, the UDR will be used and traffic will
be sent to OPFW as the next hop. Keep in mind that the actual packet destination is not being changed, it still says
onpremvm2 is the destination.
Without IP Forwarding enabled for OPFW, the Azure virtual networking logic will drop the packets, since it only
allows packets to be sent to a VM if the VMs IP address is the destination for the packet.
With IP Forwarding, the Azure virtual network logic will forward the packets to OPFW, without changing its original
destination address. OPFW must handle the packets and determine what to do with them.
For the scenario above to work, you must enable IP Forwarding on the NICs for OPFW, AZF1, AZF2, and AZF3 that
are used for routing (all NICs except the ones linked to the management subnet).
Firewall Rules
As described above, IP Forwarding only ensures packets are sent to the virtual appliances. Your appliance still needs
to decide what to do with those packets. In the scenario above, you will need to create the following rules in your
appliances:
OPFW
OPFW represents an on-premises device containing the following rules:
Route: All traffic to 10.0.0.0/16 (azurevnet) must be sent through tunnel ONPREMAZURE.
Policy: Allow all bidirectional traffic between port2 and ONPREMAZURE.
AZF1
AZF1 represents an Azure virtual appliance containing the following rules:
Policy: Allow all bidirectional traffic between port1 and port2.
AZF2
AZF2 represents an Azure virtual appliance containing the following rules:
Route: All traffic to 10.0.0.0/16 (onpremvnet) must be sent to the Azure gateway IP address (i.e. 10.0.0.1)
through port1.
Policy: Allow all bidirectional traffic between port1 and port2.
Microsoft cloud services deliver hyper-scale services and infrastructure, enterprise-grade capabilities, and many
choices for hybrid connectivity. Customers can choose to access these services either via the Internet or with Azure
ExpressRoute, which provides private network connectivity. The Microsoft Azure platform allows customers to
seamlessly extend their infrastructure into the cloud and build multi-tier architectures. Additionally, third parties
can enable enhanced capabilities by offering security services and virtual appliances. This white paper provides an
overview of security and architectural issues that customers should consider when using Microsoft cloud services
accessed via ExpressRoute. It also covers creating more secure services in Azure virtual networks.
Fast start
The following logic chart can direct you to a specific example of the many security techniques available with the
Azure platform. For quick reference, find the example that best fits your case. For expanded explanations, continue
reading through the paper.
Example 1: Build a perimeter network (also known as DMZ, demilitarized zone, or screened subnet) to help protect
applications with network security groups (NSGs).
Example 2: Build a perimeter network to help protect applications with a firewall and NSGs.
Example 3: Build a perimeter network to help protect networks with a firewall, user-defined route (UDR), and NSG.
Example 4: Add a hybrid connection with a site-to-site, virtual appliance virtual private network (VPN).
Example 5: Add a hybrid connection with a site-to-site, Azure VPN gateway.
Example 6: Add a hybrid connection with ExpressRoute.
Examples for adding connections between virtual networks, high availability, and service chaining will be added to
this document over the next few months.
This approach provides a more secure foundation for customers to deploy their services in the Microsoft cloud.
The next step is for customers to design and create a security architecture to protect these services.
Inbound from the Internet, Azure DDoS helps protect against large-scale attacks against Azure. The next layer is
customer-defined public IP addresses (endpoints), which are used to determine which traffic can pass through the
cloud service to the virtual network. Native Azure virtual network isolation ensures complete isolation from all
other networks and that traffic only flows through user configured paths and methods. These paths and methods
are the next layer, where NSGs, UDR, and network virtual appliances can be used to create security boundaries to
protect the application deployments in the protected network.
The next section provides an overview of Azure virtual networks. These virtual networks are created by customers,
and are what their deployed workloads are connected to. Virtual networks are the basis of all the network security
features required to establish a perimeter network to protect customer deployments in Azure.
NOTE
Traffic isolation refers only to traffic inbound to the virtual network. By default outbound traffic from the VNet to the
internet is allowed, but can be prevented if desired by NSGs.
Multi-tier topology: Virtual networks allow customers to define multi-tier topology by allocating subnets and
designating separate address spaces for different elements or tiers of their workloads. These logical
groupings and topologies enable customers to define different access policy based on the workload types, and
also control traffic flows between the tiers.
Cross-premises connectivity: Customers can establish cross-premises connectivity between a virtual network
and multiple on-premises sites or other virtual networks in Azure. To construct a connection, customers can use
VNet Peering, Azure VPN Gateways, third-party network virtual appliances, or ExpressRoute. Azure supports
site-to-site (S2S) VPNs using standard IPsec/IKE protocols and ExpressRoute private connectivity.
NSG allows customers to create rules (ACLs) at the desired level of granularity: network interfaces, individual
VMs, or virtual subnets. Customers can control access by permitting or denying communication between the
workloads within a virtual network, from systems on customers networks via cross-premises connectivity, or
direct Internet communication.
UDR and IP Forwarding allow customers to define the communication paths between different tiers within a
virtual network. Customers can deploy a firewall, IDS/IPS, and other virtual appliances, and route network
traffic through these security appliances for security boundary policy enforcement, auditing, and inspection.
Network virtual appliances in the Azure Marketplace: Security appliances such as firewalls, load balancers,
and IDS/IPS are available in the Azure Marketplace and the VM Image Gallery. Customers can deploy these
appliances into their virtual networks, and specifically, at their security boundaries (including the perimeter
network subnets) to complete a multi-tiered secure network environment.
With these features and capabilities, one example of how a perimeter network architecture could be constructed in
Azure is the following diagram:
TIP
Keep the following two groups separate: the individuals authorized to access the perimeter network security gear and the
individuals authorized as application development, deployment, or operations administrators. Keeping these groups separate
allows for a segregation of duties and prevents a single person from bypassing both applications security and network
security controls.
TIP
Use the smallest number of boundaries that satisfy the security requirements for a given situation. With more boundaries,
operations and troubleshooting can be more difficult, as well as the management overhead involved with managing the
multiple boundary policies over time. However, insufficient boundaries increase risk. Finding the balance is critical.
The preceding figure shows a high-level view of a three security boundary network. The boundaries are between
the perimeter network and the Internet, the Azure front-end and back-end private subnets, and the Azure back-end
subnet and the on-premises corporate network.
2) Where are the boundaries located?
Once the number of boundaries are decided, where to implement them is the next decision point. There are
generally three choices:
Using an Internet-based intermediary service (for example, a cloud-based Web application firewall, which is not
discussed in this document)
Using native features and/or network virtual appliances in Azure
Using physical devices on the on-premises network
On purely Azure networks, the options are native Azure features (for example, Azure Load Balancers) or network
virtual appliances from the rich partner ecosystem of Azure (for example, Check Point firewalls).
If a boundary is needed between Azure and an on-premises network, the security devices can reside on either side
of the connection (or both sides). Thus a decision must be made on the location to place security gear.
In the previous figure, the Internet-to-perimeter network and the front-to-back-end boundaries are entirely
contained within Azure, and must be either native Azure features or network virtual appliances. Security devices on
the boundary between Azure (back-end subnet) and the corporate network could be either on the Azure side or
the on-premises side, or even a combination of devices on both sides. There can be significant advantages and
disadvantages to either option that must be seriously considered.
For example, using existing physical security gear on the on-premises network side has the advantage that no new
gear is needed. It just needs reconfiguration. The disadvantage, however, is that all traffic must come back from
Azure to the on-premises network to be seen by the security gear. Thus Azure-to-Azure traffic could incur
significant latency, and affect application performance and user experience, if it was forced back to the on-
premises network for security policy enforcement.
3) How are the boundaries implemented?
Each security boundary will likely have different capability requirements (for example, IDS and firewall rules on the
Internet side of the perimeter network, but only ACLs between the perimeter network and back-end subnet).
Deciding on which device (or how many devices) to use depends on the scenario and security requirements. In the
following section, examples 1, 2, and 3 discuss some options that could be used. Reviewing the Azure native
network features and the devices available in Azure from the partner ecosystem shows the myriad options
available to solve virtually any scenario.
Another key implementation decision point is how to connect the on-premises network with Azure. Should you
use the Azure virtual gateway or a network virtual appliance? These options are discussed in greater detail in the
following section (examples 4, 5, and 6).
Additionally, traffic between virtual networks within Azure may be needed. These scenarios will be added in the
future.
Once you know the answers to the previous questions, the Fast Start section can help identify which examples are
most appropriate for a given scenario.
Environment description
In this example, there is a subscription that contains the following resources:
A single resource group
A virtual network with two subnets: FrontEnd and BackEnd
A Network Security Group that is applied to both subnets
A Windows server that represents an application web server (IIS01)
Two Windows servers that represent application back-end servers (AppVM01, AppVM02)
A Windows server that represents a DNS server (DNS01)
A public IP associated with the application web server
For scripts and an Azure Resource Manager template, see the detailed build instructions.
NSG description
In this example, an NSG group is built and then loaded with six rules.
TIP
Generally speaking, you should create your specific Allow rules first, followed by the more generic Deny rules. The given
priority dictates which rules are evaluated first. Once traffic is found to apply to a specific rule, no further rules are evaluated.
NSG rules can apply in either the inbound or outbound direction (from the perspective of the subnet).
Declaratively, the following rules are being built for inbound traffic:
1. Internal DNS traffic (port 53) is allowed.
2. RDP traffic (port 3389) from the Internet to any Virtual Machine is allowed.
3. HTTP traffic (port 80) from the Internet to web server (IIS01) is allowed.
4. Any traffic (all ports) from IIS01 to AppVM1 is allowed.
5. Any traffic (all ports) from the Internet to the entire virtual network (both subnets) is denied.
6. Any traffic (all ports) from the front-end subnet to the back-end subnet is denied.
With these rules bound to each subnet, if an HTTP request was inbound from the Internet to the web server, both
rules 3 (allow) and 5 (deny) would apply. But because rule 3 has a higher priority, only it would apply, and rule 5
would not come into play. Thus the HTTP request would be allowed to the web server. If that same traffic was
trying to reach the DNS01 server, rule 5 (deny) would be the first to apply, and the traffic would not be allowed to
pass to the server. Rule 6 (deny) blocks the front-end subnet from talking to the back-end subnet (except for
allowed traffic in rules 1 and 4). This rule-set protects the back-end network in case an attacker compromises the
web application on the front end. The attacker would have limited access to the back-end protected network
(only to resources exposed on the AppVM01 server).
There is a default outbound rule that allows traffic out to the Internet. For this example, were allowing outbound
traffic and not modifying any outbound rules. To lock down traffic in both directions, user-defined routing is
required (see example 3).
Conclusion
This example is a relatively simple and straightforward way of isolating the back-end subnet from inbound traffic.
For more information, see the detailed build instructions. These instructions include:
How to build this perimeter network with classic PowerShell scripts.
How to build this perimeter network with an Azure Resource Manager template.
Detailed descriptions of each NSG command.
Detailed traffic flow scenarios, showing how traffic is allowed or denied in each layer.
Example 2 Build a perimeter network to help protect applications with a firewall and NSGs
Back to Fast start | Detailed build instructions for this example
Environment description
In this example, there is a subscription that contains the following resources:
A single resource group
A virtual network with two subnets: FrontEnd and BackEnd
A Network Security Group that is applied to both subnets
A network virtual appliance, in this case a firewall, connected to the front-end subnet
A Windows server that represents an application web server (IIS01)
Two Windows servers that represent application back-end servers (AppVM01, AppVM02)
A Windows server that represents a DNS server (DNS01)
For scripts and an Azure Resource Manager template, see the detailed build instructions.
NSG description
In this example, an NSG group is built and then loaded with six rules.
TIP
Generally speaking, you should create your specific Allow rules first, followed by the more generic Deny rules. The given
priority dictates which rules are evaluated first. Once traffic is found to apply to a specific rule, no further rules are evaluated.
NSG rules can apply in either the inbound or outbound direction (from the perspective of the subnet).
Declaratively, the following rules are being built for inbound traffic:
1. Internal DNS traffic (port 53) is allowed.
2. RDP traffic (port 3389) from the Internet to any Virtual Machine is allowed.
3. Any Internet traffic (all ports) to the network virtual appliance (firewall) is allowed.
4. Any traffic (all ports) from IIS01 to AppVM1 is allowed.
5. Any traffic (all ports) from the Internet to the entire virtual network (both subnets) is denied.
6. Any traffic (all ports) from the front-end subnet to the back-end subnet is denied.
With these rules bound to each subnet, if an HTTP request was inbound from the Internet to the firewall, both rules
3 (allow) and 5 (deny) would apply. But because rule 3 has a higher priority, only it would apply, and rule 5 would
not come into play. Thus the HTTP request would be allowed to the firewall. If that same traffic was trying to reach
the IIS01 server, even though its on the front-end subnet, rule 5 (deny) would apply, and the traffic would not be
allowed to pass to the server. Rule 6 (deny) blocks the front-end subnet from talking to the back-end subnet
(except for allowed traffic in rules 1 and 4). This rule-set protects the back-end network in case an attacker
compromises the web application on the front end. The attacker would have limited access to the back-end
protected network (only to resources exposed on the AppVM01 server).
There is a default outbound rule that allows traffic out to the Internet. For this example, were allowing outbound
traffic and not modifying any outbound rules. To lock down traffic in both directions, user-defined routing is
required (see example 3).
Firewall rule description
On the firewall, forwarding rules should be created. Since this example only routes Internet traffic in-bound to the
firewall and then to the web server, only one forwarding network address translation (NAT) rule is needed.
The forwarding rule accepts any inbound source address that hits the firewall trying to reach HTTP (port 80 or 443
for HTTPS). It's sent out of the firewalls local interface and redirected to the web server with the IP Address of
10.0.1.5.
Conclusion
This example is a relatively straightforward way of protecting your application with a firewall and isolating the
back-end subnet from inbound traffic. For more information, see the detailed build instructions. These instructions
include:
How to build this perimeter network with classic PowerShell scripts.
How to build this example with an Azure Resource Manager template.
Detailed descriptions of each NSG command and firewall rule.
Detailed traffic flow scenarios, showing how traffic is allowed or denied in each layer.
Example 3 Build a perimeter network to help protect networks with a firewall and UDR and NSG
Back to Fast start | Detailed build instructions for this example
Environment description
In this example, there is a subscription that contains the following resources:
A single resource group
A virtual network with three subnets: SecNet, FrontEnd, and BackEnd
A network virtual appliance, in this case a firewall, connected to the SecNet subnet
A Windows server that represents an application web server (IIS01)
Two Windows servers that represent application back-end servers (AppVM01, AppVM02)
A Windows server that represents a DNS server (DNS01)
For scripts and an Azure Resource Manager template, see the detailed build instructions.
UDR description
By default, the following system routes are defined as:
Effective routes :
Address Prefix Next hop type Next hop IP address Status Source
-------------- ------------- ------------------- ------ ------
{10.0.0.0/16} VNETLocal Active Default
{0.0.0.0/0} Internet Active Default
{10.0.0.0/8} Null Active Default
{100.64.0.0/10} Null Active Default
{172.16.0.0/12} Null Active Default
{192.168.0.0/16} Null Active Default
The VNETLocal is always one or more defined address prefixes that make up the virtual network for that specific
network (that is, it changes from virtual network to virtual network, depending on how each specific virtual
network is defined). The remaining system routes are static and default as indicated in the table.
In this example, two routing tables are created, one each for the front-end and back-end subnets. Each table is
loaded with static routes appropriate for the given subnet. In this example, each table has three routes that direct
all traffic (0.0.0.0/0) through the firewall (Next hop = Virtual Appliance IP address):
1. Local subnet traffic with no Next Hop defined to allow local subnet traffic to bypass the firewall.
2. Virtual network traffic with a Next Hop defined as firewall. This next hop overrides the default rule that allows
local virtual network traffic to route directly.
3. All remaining traffic (0/0) with a Next Hop defined as the firewall.
TIP
Not having the local subnet entry in the UDR breaks local subnet communications.
In our example, 10.0.1.0/24 pointing to VNETLocal is critical! Without it, packet leaving the Web Server (10.0.1.4)
destined to another local server (for example) 10.0.1.25 will fail as they will be sent to the NVA. The NVA will send it to
the subnet, and the subnet will resend it to the NVA in an infinite loop.
The chances of a routing loop are typically higher on appliances with multiple NICs that are connected to separate
subnets, which is often of traditional, on-premises appliances.
Once the routing tables are created, they must be bound to their subnets. The front-end subnet routing table, once
created and bound to the subnet, would look like this output:
Effective routes :
Address Prefix Next hop type Next hop IP address Status Source
-------------- ------------- ------------------- ------ ------
{10.0.1.0/24} VNETLocal Active
{10.0.0.0/16} VirtualAppliance 10.0.0.4 Active
{0.0.0.0/0} VirtualAppliance 10.0.0.4 Active
NOTE
UDR can now be applied to the gateway subnet on which the ExpressRoute circuit is connected.
Examples of how to enable your perimeter network with ExpressRoute or site-to-site networking are shown in examples 3
and 4.
IP Forwarding description
IP Forwarding is a companion feature to UDR. IP Forwarding is a setting on a virtual appliance that allows it to
receive traffic not specifically addressed to the appliance, and then forward that traffic to its ultimate destination.
For example, if AppVM01 makes a request to the DNS01 server, UDR would route this traffic to the firewall. With
IP Forwarding enabled, the traffic for the DNS01 destination (10.0.2.4) is accepted by the appliance (10.0.0.4) and
then forwarded to its ultimate destination (10.0.2.4). Without IP Forwarding enabled on the firewall, traffic would
not be accepted by the appliance even though the route table has the firewall as the next hop. To use a virtual
appliance, its critical to remember to enable IP Forwarding along with UDR.
NSG description
In this example, an NSG group is built and then loaded with a single rule. This group is then bound only to the
front-end and back-end subnets (not the SecNet). Declaratively the following rule is being built:
Any traffic (all ports) from the Internet to the entire virtual network (all subnets) is denied.
Although NSGs are used in this example, its main purpose is as a secondary layer of defense against manual
misconfiguration. The goal is to block all inbound traffic from the Internet to either the front-end or back-end
subnets. Traffic should only flow through the SecNet subnet to the firewall (and then, if appropriate, on to the
front-end or back-end subnets). Plus, with the UDR rules in place, any traffic that did make it into the front-end or
back-end subnets would be directed out to the firewall (thanks to UDR). The firewall would see this traffic as an
asymmetric flow and would drop the outbound traffic. Thus there are three layers of security protecting the
subnets:
No Public IP addresses on any FrontEnd or BackEnd NICs.
NSGs denying traffic from the Internet.
The firewall dropping asymmetric traffic.
One interesting point regarding the NSG in this example is that it contains only one rule, which is to deny Internet
traffic to the entire virtual network, including the Security subnet. However, since the NSG is only bound to the
front-end and back-end subnets, the rule isnt processed on traffic inbound to the Security subnet. As a result,
traffic flows to the Security subnet.
Firewall rules
On the firewall, forwarding rules should be created. Since the firewall is blocking or forwarding all inbound,
outbound, and intra-virtual network traffic, many firewall rules are needed. Also, all inbound traffic hits the
Security Service public IP address (on different ports), to be processed by the firewall. A best practice is to diagram
the logical flows before setting up the subnets and firewall rules, to avoid rework later. The following figure is a
logical view of the firewall rules for this example:
NOTE
Based on the Network Virtual Appliance used, the management ports vary. In this example, a Barracuda NextGen Firewall is
referenced, which uses ports 22, 801, and 807. Consult the appliance vendor documentation to find the exact ports used for
management of the device being used.
TIP
On the second application traffic rule, to simplify this example, any port is allowed. In a real scenario, the most specific port
and address ranges should be used to reduce the attack surface of this rule.
Once the previous rules are created, its important to review the priority of each rule to ensure traffic is allowed or
denied as desired. For this example, the rules are in priority order.
Conclusion
This example is a more complex but complete way of protecting and isolating the network than the previous
examples. (Example 2 protects just the application, and Example 1 just isolates subnets). This design allows for
monitoring traffic in both directions, and protects not just the inbound application server but enforces network
security policy for all servers on this network. Also, depending on the appliance used, full traffic auditing and
awareness can be achieved. For more information, see the detailed build instructions. These instructions include:
How to build this example perimeter network with classic PowerShell scripts.
How to build this example with an Azure Resource Manager template.
Detailed descriptions of each UDR, NSG command, and firewall rule.
Detailed traffic flow scenarios, showing how traffic is allowed or denied in each layer.
Example 4 Add a hybrid connection with a site -to -site, virtual appliance VPN
Back to Fast start | Detailed build instructions available soon
Environment description
Hybrid networking using a network virtual appliance (NVA) can be added to any of the perimeter network types
described in examples 1, 2, or 3.
As shown in the previous figure, a VPN connection over the Internet (site-to-site) is used to connect an on-
premises network to an Azure virtual network via an NVA.
NOTE
If you use ExpressRoute with the Azure Public Peering option enabled, a static route should be created. This static route
should route to the NVA VPN IP address out your corporate Internet and not via the ExpressRoute connection. The NAT
required on the ExpressRoute Azure Public Peering option can break the VPN session.
Once the VPN is in place, the NVA becomes the central hub for all networks and subnets. The firewall forwarding
rules determine which traffic flows are allowed, are translated via NAT, are redirected, or are dropped (even for
traffic flows between the on-premises network and Azure).
Traffic flows should be considered carefully, as they can be optimized or degraded by this design pattern,
depending on the specific use case.
Using the environment built in example 3, and then adding a site-to-site VPN hybrid network connection,
produces the following design:
The on-premises router, or any other network device that is compatible with your NVA for VPN, would be the VPN
client. This physical device would be responsible for initiating and maintaining the VPN connection with your NVA.
Logically to the NVA, the network looks like four separate security zones with the rules on the NVA being the
primary director of traffic between these zones:
Conclusion
The addition of a site-to-site VPN hybrid network connection to an Azure virtual network can extend the on-
premises network into Azure in a secure manner. In using a VPN connection, your traffic is encrypted and routes
via the Internet. The NVA in this example provides a central location to enforce and manage the security policy. For
more information, see the detailed build instructions (forthcoming). These instructions include:
How to build this example perimeter network with PowerShell scripts.
How to build this example with an Azure Resource Manager template.
Detailed traffic flow scenarios, showing how traffic flows through this design.
Example 5 Add a hybrid connection with a site -to -site, Azure VPN gateway
Back to Fast start | Detailed build instructions available soon
Environment description
Hybrid networking using an Azure VPN gateway can be added to either perimeter network type described in
examples 1 or 2.
As shown in the preceding figure, a VPN connection over the Internet (site-to-site) is used to connect an on-
premises network to an Azure virtual network via an Azure VPN gateway.
NOTE
If you use ExpressRoute with the Azure Public Peering option enabled, a static route should be created. This static route
should route to the NVA VPN IP address out your corporate Internet and not via the ExpressRoute WAN. The NAT required
on the ExpressRoute Azure Public Peering option can break the VPN session.
The following figure shows the two network edges in this example. On the first edge, the NVA and NSGs control
traffic flows for intra-Azure networks and between Azure and the Internet. The second edge is the Azure VPN
gateway, which is a separate and isolated network edge between on-premises and Azure.
Traffic flows should be considered carefully, as they can be optimized or degraded by this design pattern,
depending on the specific use case.
Using the environment built in example 1, and then adding a site-to-site VPN hybrid network connection,
produces the following design:
Conclusion
The addition of a site-to-site VPN hybrid network connection to an Azure virtual network can extend the on-
premises network into Azure in a secure manner. Using the native Azure VPN gateway, your traffic is IPSec
encrypted and routes via the Internet. Also, using the Azure VPN gateway can provide a lower-cost option (no
additional licensing cost as with third-party NVAs). This option is most economical in example 1, where no NVA is
used. For more information, see the detailed build instructions (forthcoming). These instructions include:
How to build this example perimeter network with PowerShell scripts.
How to build this example with an Azure Resource Manager template.
Detailed traffic flow scenarios, showing how traffic flows through this design.
Example 6 Add a hybrid connection with ExpressRoute
Back to Fast start | Detailed build instructions available soon
Environment description
Hybrid networking using an ExpressRoute private peering connection can be added to either perimeter network
type described in examples 1 or 2.
As shown in the preceding figure, ExpressRoute private peering provides a direct connection between your on-
premises network and the Azure virtual network. Traffic transits only the service provider network and the
Microsoft Azure network, never touching the Internet.
TIP
Using ExpressRoute keeps corporate network traffic off the Internet. It also allows for service level agreements from your
ExpressRoute provider. The Azure Gateway can pass up to 10 Gbps with ExpressRoute, whereas with site-to-site VPNs, the
Azure Gateway maximum throughput is 200 Mbps.
As seen in the following diagram, with this option the environment now has two network edges. The NVA and
NSG control traffic flows for intra-Azure networks and between Azure and the Internet, while the gateway is a
separate and isolated network edge between on-premises and Azure.
Traffic flows should be considered carefully, as they can be optimized or degraded by this design pattern,
depending on the specific use case.
Using the environment built in example 1, and then adding an ExpressRoute hybrid network connection, produces
the following design:
Conclusion
The addition of an ExpressRoute Private Peering network connection can extend the on-premises network into
Azure in a secure, lower latency, higher performing manner. Also, using the native Azure Gateway, as in this
example, provides a lower-cost option (no additional licensing as with third-party NVAs). For more information,
see the detailed build instructions (forthcoming). These instructions include:
How to build this example perimeter network with PowerShell scripts.
How to build this example with an Azure Resource Manager template.
Detailed traffic flow scenarios, showing how traffic flows through this design.
References
Helpful websites and documentation
Access Azure with Azure Resource Manager:
Accessing Azure with PowerShell: https://docs.microsoft.com/powershell/azureps-cmdlets-docs/
Virtual networking documentation: https://docs.microsoft.com/azure/virtual-network/
Network security group documentation: https://docs.microsoft.com/azure/virtual-network/virtual-networks-
nsg
User-defined routing documentation: https://docs.microsoft.com/azure/virtual-network/virtual-networks-udr-
overview
Azure virtual gateways: https://docs.microsoft.com/azure/vpn-gateway/
Site-to-Site VPNs: https://docs.microsoft.com/azure/vpn-gateway/vpn-gateway-create-site-to-site-rm-
powershell
ExpressRoute documentation (be sure to check out the Getting Started and How To sections):
https://docs.microsoft.com/azure/expressroute/
Example 1 Build a simple DMZ using NSGs with
classic PowerShell
6/27/2017 20 min to read Edit Online
Environment description
In this example a subscription contains the following resources:
Two cloud services: FrontEnd001 and BackEnd001
A Virtual Network, CorpNetwork, with two subnets; FrontEnd and BackEnd
A Network Security Group that is applied to both subnets
A Windows Server that represents an application web server (IIS01)
Two windows servers that represent application back-end servers (AppVM01, AppVM02)
A Windows server that represents a DNS server (DNS01)
In the references section, there is a PowerShell script that builds most of the environment described in this example.
Building the VMs and Virtual Networks, although are done by the example script, are not described in detail in this
document.
To build the environment;
1. Save the network config xml file included in the references section (updated with names, location, and IP
addresses to match the given scenario)
2. Update the user variables in the script to match the environment the script is to be run against (subscriptions,
service names, etc.)
3. Execute the script in PowerShell
NOTE
The region signified in the PowerShell script must match the region signified in the network configuration xml file.
Once the script runs successfully additional optional steps may be taken, in the references section are two scripts to
set up the web server and app server with a simple web application to allow testing with this DMZ configuration.
The following sections provide a detailed description of Network Security Groups and how they function for this
example by walking through key lines of the PowerShell script.
TIP
Generally speaking, you should create your specific Allow rules first and then the more generic Deny rules last. The
assigned priority dictates which rules are evaluated first. Once traffic is found to apply to a specific rule, no further rules are
evaluated. NSG rules can apply in either in the inbound or outbound direction (from the perspective of the subnet).
Declaratively, the following rules are being built for inbound traffic:
1. Internal DNS traffic (port 53) is allowed
2. RDP traffic (port 3389) from the Internet to any VM is allowed
3. HTTP traffic (port 80) from the Internet to web server (IIS01) is allowed
4. Any traffic (all ports) from IIS01 to AppVM1 is allowed
5. Any traffic (all ports) from the Internet to the entire VNet (both subnets) is Denied
6. Any traffic (all ports) from the Frontend subnet to the Backend subnet is Denied
With these rules bound to each subnet, if an HTTP request was inbound from the Internet to the web server, both
rules 3 (allow) and 5 (deny) would apply, but since rule 3 has a higher priority only it would apply and rule 5 would
not come into play. Thus the HTTP request would be allowed to the web server. If that same traffic was trying to
reach the DNS01 server, rule 5 (Deny) would be the first to apply and the traffic would not be allowed to pass to the
server. Rule 6 (Deny) blocks the Frontend subnet from talking to the Backend subnet (except for allowed traffic in
rules 1 and 4), this rule-set protects the Backend network in case an attacker compromises the web application on
the Frontend, the attacker would have limited access to the Backend protected network (only to resources
exposed on the AppVM01 server).
There is a default outbound rule that allows traffic out to the internet. For this example, were allowing outbound
traffic and not modifying any outbound rules. To lock down traffic in both directions, User Defined Routing is
required and is explored in Example 3 on the Security Boundary Best Practices Page.
Each rule is discussed in more detail as follows (Note: any item in the following list beginning with a dollar sign
(for example: $NSGName) is a user-defined variable from the script in the reference section of this document):
1. First a Network Security Group must be built to hold the rules:
New-AzureNetworkSecurityGroup -Name $NSGName `
-Location $DeploymentLocation `
-Label "Security group for $VNetName subnets in $DeploymentLocation"
2. The first rule in this example allows DNS traffic between all internal networks to the DNS server on the
backend subnet. The rule has some important parameters:
Type signifies in which direction of traffic flow this rule takes effect. The direction is from the
perspective of the subnet or Virtual Machine (depending on where this NSG is bound). Thus if Type is
Inbound and traffic is entering the subnet, the rule would apply and traffic leaving the subnet would not
be affected by this rule.
Priority sets the order in which a traffic flow is evaluated. The lower the number the higher the priority.
When a rule applies to a specific traffic flow, no further rules are processed. Thus if a rule with priority 1
allows traffic, and a rule with priority 2 denies traffic, and both rules apply to traffic then the traffic would
be allowed to flow (since rule 1 had a higher priority it took effect and no further rules were applied).
Action signifies if traffic affected by this rule is blocked or allowed.
3. This rule allows RDP traffic to flow from the internet to the RDP port on any server on the bound subnet.
This rule uses two special types of address prefixes; VIRTUAL_NETWORK and INTERNET. These tags are
an easy way to address a larger category of address prefixes.
4. This rule allows inbound internet traffic to hit the web server. This rule does not change the routing behavior.
The rule only allows traffic destined for IIS01 to pass. Thus if traffic from the Internet had the web server as
its destination this rule would allow it and stop processing further rules. (In the rule at priority 140 all other
inbound internet traffic is blocked). If you're only processing HTTP traffic, this rule could be further restricted
to only allow Destination Port 80.
5. This rule allows traffic to pass from the IIS01 server to the AppVM01 server, a later rule blocks all other
Frontend to Backend traffic. To improve this rule, if the port is known that should be added. For example, if
the IIS server is hitting only SQL Server on AppVM01, the Destination Port Range should be changed from
* (Any) to 1433 (the SQL port) thus allowing a smaller inbound attack surface on AppVM01 should the
web application ever be compromised.
6. This rule denies traffic from the internet to any servers on the network. With the rules at priority 110 and
120, the effect is to allow only inbound internet traffic to the firewall and RDP ports on servers and blocks
everything else. This rule is a "fail-safe" rule to block all unexpected flows.
7. The final rule denies traffic from the Frontend subnet to the Backend subnet. Since this rule is an Inbound
only rule, reverse traffic is allowed (from the Backend to the Frontend).
Traffic scenarios
(Allowed) Internet to web server
1. An internet user requests an HTTP page from FrontEnd001.CloudApp.Net (Internet Facing Cloud Service)
2. Cloud service passes traffic through open endpoint on port 80 towards IIS01 (the web server)
3. Frontend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 3 (Internet to IIS01) does apply, traffic is allowed, stop rule processing
4. Traffic hits internal IP address of the web server IIS01 (10.0.1.5)
5. IIS01 is listening for web traffic, receives this request and starts processing the request
6. IIS01 asks the SQL Server on AppVM01 for information
7. Since there are no outbound rules on Frontend subnet, traffic is allowed
8. The Backend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 3 (Internet to Firewall) doesnt apply, move to next rule
d. NSG Rule 4 (IIS01 to AppVM01) does apply, traffic is allowed, stop rule processing
9. AppVM01 receives the SQL Query and responds
10. Since there are no outbound rules on the Backend subnet, the response is allowed
11. Frontend subnet begins inbound rule processing:
a. There is no NSG rule that applies to Inbound traffic from the Backend subnet to the Frontend subnet, so
none of the NSG rules apply
b. The default system rule allowing traffic between subnets would allow this traffic so the traffic is allowed.
12. The IIS server receives the SQL response and completes the HTTP response and sends to the requestor
13. Since there are no outbound rules on the Frontend subnet the response is allowed, and the internet User
receives the web page requested.
(Allowed) RDP to backend
1. Server Admin on internet requests RDP session to AppVM01 on BackEnd001.CloudApp.Net:xxxxx where xxxxx is
the randomly assigned port number for RDP to AppVM01 (the assigned port can be found on the Azure portal
or via PowerShell)
2. Backend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) does apply, traffic is allowed, stop rule processing
3. With no outbound rules, default rules apply and return traffic is allowed
4. RDP session is enabled
5. AppVM01 prompts for the user name and password
(Allowed) Web server DNS look-up on DNS server
1. Web Server, IIS01, needs a data feed at www.data.gov, but needs to resolve the address.
2. The network configuration for the VNet lists DNS01 (10.0.2.4 on the Backend subnet) as the primary DNS
server, IIS01 sends the DNS request to DNS01
3. No outbound rules on Frontend subnet, traffic is allowed
4. Backend subnet begins inbound rule processing:
NSG Rule 1 (DNS) does apply, traffic is allowed, stop rule processing
5. DNS server receives the request
6. DNS server doesnt have the address cached and asks a root DNS server on the internet
7. No outbound rules on Backend subnet, traffic is allowed
8. Internet DNS server responds, since this session was initiated internally, the response is allowed
9. DNS server caches the response, and responds to the initial request back to IIS01
10. No outbound rules on Backend subnet, traffic is allowed
11. Frontend subnet begins inbound rule processing:
a. There is no NSG rule that applies to Inbound traffic from the Backend subnet to the Frontend subnet, so
none of the NSG rules apply
b. The default system rule allowing traffic between subnets would allow this traffic so the traffic is allowed
12. IIS01 receives the response from DNS01
(Allowed) Web server access file on AppVM01
1. IIS01 asks for a file on AppVM01
2. No outbound rules on Frontend subnet, traffic is allowed
3. The Backend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 3 (Internet to IIS01) doesnt apply, move to next rule
d. NSG Rule 4 (IIS01 to AppVM01) does apply, traffic is allowed, stop rule processing
4. AppVM01 receives the request and responds with file (assuming access is authorized)
5. Since there are no outbound rules on the Backend subnet, the response is allowed
6. Frontend subnet begins inbound rule processing:
a. There is no NSG rule that applies to Inbound traffic from the Backend subnet to the Frontend subnet, so
none of the NSG rules apply
b. The default system rule allowing traffic between subnets would allow this traffic so the traffic is allowed.
7. The IIS server receives the file
(Denied) Web to backend server
1. An internet user tries to access a file on AppVM01 through the BackEnd001.CloudApp.Net service
2. Since there are no endpoints open for file share, this traffic would not pass the Cloud Service and wouldnt reach
the server
3. If the endpoints were open for some reason, NSG rule 5 (Internet to VNet) would block this traffic
(Denied) Web DNS look-up on DNS server
1. An internet user tries to look up an internal DNS record on DNS01 through the BackEnd001.CloudApp.Net
service
2. Since there are no endpoints open for DNS, this traffic would not pass the Cloud Service and wouldnt reach the
server
3. If the endpoints were open for some reason, NSG rule 5 (Internet to VNet) would block this traffic (Note: that
Rule 1 (DNS) would not apply for two reasons, first the source address is the internet, this rule only applies to
the local VNet as the source, also this rule is an Allow rule, so it would never deny traffic)
(Denied) Web to SQL access through firewall
1. An internet user requests SQL data from FrontEnd001.CloudApp.Net (Internet Facing Cloud Service)
2. Since there are no endpoints open for SQL, this traffic would not pass the Cloud Service and wouldnt reach the
firewall
3. If endpoints were open for some reason, the Frontend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 3 (Internet to IIS01) does apply, traffic is allowed, stop rule processing
4. Traffic hits internal IP address of the IIS01 (10.0.1.5)
5. IIS01 isn't listening on port 1433, so no response to the request
Conclusion
This example is a relatively simple and straight forward way of isolating the back-end subnet from inbound traffic.
More examples and an overview of network security boundaries can be found here.
References
Main script and network config
Save the Full Script in a PowerShell script file. Save the Network Config into a file named NetworkConf1.xml.
Modify the user-defined variables as needed and run the script.
Full script
This script will, based on the user-defined variables;
1. Connect to an Azure subscription
2. Create a storage account
3. Create a VNet and two subnets as defined in the Network Config file
4. Build four windows server VMs
5. Configure NSG including:
Creating an NSG
Populating it with rules
Binding the NSG to the appropriate subnets
This PowerShell script should be run locally on an internet connected PC or server.
IMPORTANT
When this script is run, there may be warnings or other informational messages that pop in PowerShell. Only error messages
in red are cause for concern.
<#
.SYNOPSIS
Example of Network Security Groups in an isolated network (Azure only, no hybrid connections)
.DESCRIPTION
This script will build out a sample DMZ setup containing:
- A default storage account for VM disks
- Two new cloud services
- Two Subnets (FrontEnd and BackEnd subnets)
- One server on the FrontEnd Subnet
- Three Servers on the BackEnd Subnet
- Network Security Groups to allow/deny traffic patterns as declared
.Notes
Security requirements are different for each use case and can be addressed in a
myriad of ways. Please be sure that any sensitive data or applications are behind
the appropriate layer(s) of protection. This script serves as an example of some
of the techniques that can be used, but should not be used for all scenarios. You
are responsible to assess your security needs and the appropriate protections
needed, and then effectively implement those protections.
#>
# Fixed Variables
$LocalAdminPwd = Read-Host -Prompt "Enter Local Admin Password to be used for all VMs"
$VMName = @()
$ServiceName = @()
$VMFamily = @()
$img = @()
$size = @()
$SubnetName = @()
$VMIP = @()
# Service Details
$FrontEndService = "FrontEnd001"
$BackEndService = "BackEnd001"
# Network Details
$VNetName = "CorpNetwork"
$FESubnet = "FrontEnd"
$FEPrefix = "10.0.1.0/24"
$BESubnet = "BackEnd"
$BEPrefix = "10.0.2.0/24"
$NetworkConfigFile = "C:\Scripts\NetworkConf1.xml"
# NSG Details
$NSGName = "MyVNetSG"
# ----------------------------- #
# ----------------------------- #
# No User-Defined Variables or #
# Configuration past this point #
# ----------------------------- #
# Validation
$FatalError = $false
If ($FatalError) {
Write-Host "A fatal error has occurred, please see the above messages for more information." -
ForegroundColor Red
Return}
Else { Write-Host "Validation passed, now building the environment." -ForegroundColor Green}
# Create VNET
Write-Host "Creating VNET" -ForegroundColor Cyan
Set-AzureVNetConfig -ConfigurationPath $NetworkConfigFile -ErrorAction Stop
# Create Services
Write-Host "Creating Services" -ForegroundColor Cyan
New-AzureService -Location $DeploymentLocation -ServiceName $FrontEndService -ErrorAction Stop
New-AzureService -Location $DeploymentLocation -ServiceName $BackEndService -ErrorAction Stop
# Build VMs
$i=0
$VMName | Foreach {
Write-Host "Building $($VMName[$i])" -ForegroundColor Cyan
New-AzureVMConfig -Name $VMName[$i] -ImageName $img[$i] InstanceSize $size[$i] | `
Add-AzureProvisioningConfig -Windows -AdminUsername $LocalAdmin -Password $LocalAdminPwd | `
Set-AzureSubnet SubnetNames $SubnetName[$i] | `
Set-AzureStaticVNetIP -IPAddress $VMIP[$i] | `
Set-AzureVMMicrosoftAntimalwareExtension -AntimalwareConfiguration '{"AntimalwareEnabled" : true}'
| `
Remove-AzureEndpoint -Name "PowerShell" | `
New-AzureVM ServiceName $ServiceName[$i] -VNetName $VNetName -Location $DeploymentLocation
# Note: A Remote Desktop endpoint is automatically created when each VM is created.
$i++
}
# Add HTTP Endpoint for IIS01
Get-AzureVM -ServiceName $ServiceName[0] -Name $VMName[0] | Add-AzureEndpoint -Name HTTP -Protocol tcp -
LocalPort 80 -PublicPort 80 | Update-AzureVM
# Configure NSG
Write-Host "Configuring the Network Security Group (NSG)" -ForegroundColor Cyan
Next steps
Update and save XML file
Run the PowerShell script to build the environment
Install the sample application
Test different traffic flows through this DMZ
Example 2 Build a DMZ to protect applications with
a Firewall and NSGs
6/27/2017 22 min to read Edit Online
Environment Description
In this example there is a subscription that contains the following:
Two cloud services: FrontEnd001 and BackEnd001
A Virtual Network CorpNetwork, with two subnets: FrontEnd and BackEnd
A single Network Security Group that is applied to both subnets
A network virtual appliance, in this example a Barracuda NextGen Firewall, connected to the Frontend subnet
A Windows Server that represents an application web server (IIS01)
Two windows servers that represent application back end servers (AppVM01, AppVM02)
A Windows server that represents a DNS server (DNS01)
NOTE
Although this example uses a Barracuda NextGen Firewall, many of the different Network Virtual Appliances could be used for
this example.
In the references section below there is a PowerShell script that will build most of the environment described above.
Building the VMs and Virtual Networks, although are done by the example script, are not described in detail in this
document.
To build the environment:
1. Save the network config xml file included in the references section (updated with names, location, and IP
addresses to match the given scenario)
2. Update the user variables in the script to match the environment the script is to be run against (subscriptions,
service names, etc)
3. Execute the script in PowerShell
Note: The region signified in the PowerShell script must match the region signified in the network configuration
xml file.
Once the script runs successfully the following post-script steps may be taken:
1. Set up the firewall rules, this is covered in the section below titled: Firewall Rules.
2. Optionally in the references section are two scripts to set up the web server and app server with a simple web
application to allow testing with this DMZ configuration.
The next section explains most of the scripts statements relative to Network Security Groups.
TIP
Generally speaking, you should create your specific Allow rules first and then the more generic Deny rules last. The
assigned priority dictates which rules are evaluated first. Once traffic is found to apply to a specific rule, no further rules are
evaluated. NSG rules can apply in either in the inbound or outbound direction (from the perspective of the subnet).
Declaratively, the following rules are being built for inbound traffic:
1. Internal DNS traffic (port 53) is allowed
2. RDP traffic (port 3389) from the Internet to any VM is allowed
3. HTTP traffic (port 80) from the Internet to the NVA (firewall) is allowed
4. Any traffic (all ports) from IIS01 to AppVM1 is allowed
5. Any traffic (all ports) from the Internet to the entire VNet (both subnets) is Denied
6. Any traffic (all ports) from the Frontend subnet to the Backend subnet is Denied
With these rules bound to each subnet, if a HTTP request was inbound from the Internet to the web server, both
rules 3 (allow) and 5 (deny) would apply, but since rule 3 has a higher priority only it would apply and rule 5 would
not come into play. Thus the HTTP request would be allowed to the firewall. If that same traffic was trying to reach
the DNS01 server, rule 5 (Deny) would be the first to apply and the traffic would not be allowed to pass to the
server. Rule 6 (Deny) blocks the Frontend subnet from talking to the Backend subnet (except for allowed traffic in
rules 1 and 4), this protects the Backend network in case an attacker compromises the web application on the
Frontend, the attacker would have limited access to the Backend protected network (only to resources exposed on
the AppVM01 server).
There is a default outbound rule that allows traffic out to the internet. For this example, were allowing outbound
traffic and not modifying any outbound rules. To lock down traffic in both directions, User Defined Routing is
required, this is explored in a different example that can found in the main security boundary document.
The above discussed NSG rules are very similar to the NSG rules in Example 1 - Build a Simple DMZ with NSGs.
Please review the NSG Description in that document for a detailed look at each NSG rule and it's attributes.
Firewall Rules
A management client will need to be installed on a PC to manage the firewall and create the configurations needed.
See the documentation from your firewall (or other NVA) vendor on how to manage the device. The remainder of
this section will describe the configuration of the firewall itself, through the vendors management client (i.e. not the
Azure portal or PowerShell).
Instructions for client download and connecting to the Barracuda used in this example can be found here: Barracuda
NG Admin
On the firewall, forwarding rules will need to be created. Since this example only routes internet traffic in-bound to
the firewall and then to the web server, only one forwarding NAT rule is needed. On the Barracuda NextGen Firewall
used in this example the rule would be a Destination NAT rule (Dst NAT) to pass this traffic.
To create the following rule (or verify existing default rules), starting from the Barracuda NG Admin client
dashboard, navigate to the configuration tab, in the Operational Configuration section click Ruleset. A grid called,
Main Rules will show the existing active and deactivated rules on the firewall. In the upper right corner of this grid
is a small, green + button, click this to create a new rule (Note: your firewall may be locked for changes, if you
see a button marked Lock and you are unable to create or edit rules, click this button to unlock the ruleset and
allow editing). If you wish to edit an existing rule, select that rule, right-click and select Edit Rule.
Create a new rule and provide a name, such as "WebTraffic".
Here any inbound address that hits the Firewall trying to reach HTTP (port 80 or 443 for HTTPS) will be sent out the
Firewalls DHCP1 Local IP interface and redirected to the Web Server with the IP Address of 10.0.1.5. Since the
traffic is coming in on port 80 and going to the web server on port 80 no port change was needed. However, the
Target List could have been 10.0.1.5:8080 if our Web Server listened on port 8080 thus translating the inbound port
80 on the firewall to inbound port 8080 on the web server.
A Connection Method should also be signified, for the Destination Rule from the Internet, "Dynamic SNAT" is most
appropriate.
Although only one rule has been created it's important that its priority is set correctly. If in the grid of all rules on
the firewall this new rule is on the bottom (below the "BLOCKALL" rule) it will never come into play. Ensure the
newly created rule for web traffic is above the BLOCKALL rule.
Once the rule is created, it must be pushed to the firewall and then activated, if this is not done the rule change will
not take effect. The push and activation process is described in the next section.
Rule Activation
With the ruleset modified to add this rule, the ruleset must be uploaded to the firewall and activated.
In the upper right hand corner of the management client are a cluster of buttons. Click the Send Changes button
to send the modified rules to the firewall, then click the Activate button.
With the activation of the firewall ruleset this example environment build is complete. Optionally, the post build
scripts in the References section can be run to add an application to this environment to test the below traffic
scenarios.
IMPORTANT
It is critical to realize that you will not hit the web server directly. When a browser requests an HTTP page from
FrontEnd001.CloudApp.Net, the HTTP endpoint (port 80) passes this traffic to the firewall not the web server. The firewall
then, according to the rule created above, NATs that request to the Web Server.
Traffic Scenarios
(Allowed) Web to Web Server through Firewall
1. Internet user requests HTTP page from FrontEnd001.CloudApp.Net (Internet Facing Cloud Service)
2. Cloud service passes traffic through open endpoint on port 80 to firewall local interface on 10.0.1.4:80
3. Frontend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 3 (Internet to Firewall) does apply, traffic is allowed, stop rule processing
4. Traffic hits internal IP address of the firewall (10.0.1.4)
5. Firewall forwarding rule see this is port 80 traffic, redirects it to the web server IIS01
6. IIS01 is listening for web traffic, receives this request and starts processing the request
7. IIS01 asks the SQL Server on AppVM01 for information
8. No outbound rules on Frontend subnet, traffic is allowed
9. The Backend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 3 (Internet to Firewall) doesnt apply, move to next rule
d. NSG Rule 4 (IIS01 to AppVM01) does apply, traffic is allowed, stop rule processing
10. AppVM01 receives the SQL Query and responds
11. Since there are no outbound rules on the Backend subnet the response is allowed
12. Frontend subnet begins inbound rule processing:
a. There is no NSG rule that applies to Inbound traffic from the Backend subnet to the Frontend subnet, so
none of the NSG rules apply
b. The default system rule allowing traffic between subnets would allow this traffic so the traffic is allowed.
13. The IIS server receives the SQL response and completes the HTTP response and sends to the requestor
14. Since this is a NAT session from the firewall, the response destination (initially) is for the Firewall
15. The firewall receives the response from the Web Server and forwards back to the Internet User
16. Since there are no outbound rules on the Frontend subnet the response is allowed, and the Internet User
receives the web page requested.
(Allowed) RDP to Backend
1. Server Admin on internet requests RDP session to AppVM01 on BackEnd001.CloudApp.Net:xxxxx where xxxxx is
the randomly assigned port number for RDP to AppVM01 (the assigned port can be found on the Azure Portal
or via PowerShell)
2. Since the Firewall is only listening on the FrontEnd001.CloudApp.Net address, it is not involved with this traffic
flow
3. Backend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) does apply, traffic is allowed, stop rule processing
4. With no outbound rules, default rules apply and return traffic is allowed
5. RDP session is enabled
6. AppVM01 prompts for user name password
(Allowed) Web Server DNS lookup on DNS server
1. Web Server, IIS01, needs a data feed at www.data.gov, but needs to resolve the address.
2. The network configuration for the VNet lists DNS01 (10.0.2.4 on the Backend subnet) as the primary DNS server,
IIS01 sends the DNS request to DNS01
3. No outbound rules on Frontend subnet, traffic is allowed
4. Backend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) does apply, traffic is allowed, stop rule processing
5. DNS server receives the request
6. DNS server doesnt have the address cached and asks a root DNS server on the internet
7. No outbound rules on Backend subnet, traffic is allowed
8. Internet DNS server responds, since this session was initiated internally, the response is allowed
9. DNS server caches the response, and responds to the initial request back to IIS01
10. No outbound rules on Backend subnet, traffic is allowed
11. Frontend subnet begins inbound rule processing:
a. There is no NSG rule that applies to Inbound traffic from the Backend subnet to the Frontend subnet, so
none of the NSG rules apply
b. The default system rule allowing traffic between subnets would allow this traffic so the traffic is allowed
12. IIS01 receives the response from DNS01
(Allowed) Web Server access file on AppVM01
1. IIS01 asks for a file on AppVM01
2. No outbound rules on Frontend subnet, traffic is allowed
3. The Backend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 3 (Internet to Firewall) doesnt apply, move to next rule
d. NSG Rule 4 (IIS01 to AppVM01) does apply, traffic is allowed, stop rule processing
4. AppVM01 receives the request and responds with file (assuming access is authorized)
5. Since there are no outbound rules on the Backend subnet the response is allowed
6. Frontend subnet begins inbound rule processing:
a. There is no NSG rule that applies to Inbound traffic from the Backend subnet to the Frontend subnet, so
none of the NSG rules apply
b. The default system rule allowing traffic between subnets would allow this traffic so the traffic is allowed.
7. The IIS server receives the file
(Denied) Web direct to Web Server
Since the Web Server, IIS01, and the Firewall are in the same Cloud Service they share the same public facing IP
address. Thus any HTTP traffic would be directed to the firewall. While the request would be successfully served, it
cannot go directly to the Web Server, it passed, as designed, through the Firewall first. See the first Scenario in this
section for the traffic flow.
(Denied) Web to Backend Server
1. Internet user tries to access a file on AppVM01 through the BackEnd001.CloudApp.Net service
2. Since there are no endpoints open for file share, this would not pass the Cloud Service and wouldnt reach the
server
3. If the endpoints were open for some reason, NSG rule 5 (Internet to VNet) would block this traffic
(Denied) Web DNS lookup on DNS server
1. Internet user tries to lookup an internal DNS record on DNS01 through the BackEnd001.CloudApp.Net service
2. Since there are no endpoints open for DNS, this would not pass the Cloud Service and wouldnt reach the server
3. If the endpoints were open for some reason, NSG rule 5 (Internet to VNet) would block this traffic (Note: that
Rule 1 (DNS) would not apply for two reasons, first the source address is the internet, this rule only applies to
the local VNet as the source, also this is an Allow rule, so it would never deny traffic)
(Denied) Web to SQL access through Firewall
1. Internet user requests SQL data from FrontEnd001.CloudApp.Net (Internet Facing Cloud Service)
2. Since there are no endpoints open for SQL, this would not pass the Cloud Service and wouldnt reach the
firewall
3. If endpoints were open for some reason, the Frontend subnet begins inbound rule processing:
a. NSG Rule 1 (DNS) doesnt apply, move to next rule
b. NSG Rule 2 (RDP) doesnt apply, move to next rule
c. NSG Rule 2 (Internet to Firewall) does apply, traffic is allowed, stop rule processing
4. Traffic hits internal IP address of the firewall (10.0.1.4)
5. Firewall has no forwarding rules for SQL and drops the traffic
Conclusion
This is a relatively straight forward way of protecting your application with a firewall and isolating the back end
subnet from inbound traffic.
More examples and an overview of network security boundaries can be found here.
References
Main Script and Network Config
Save the Full Script in a PowerShell script file. Save the Network Config into a file named NetworkConf2.xml.
Modify the user defined variables as needed. Run the script, then follow the Firewall rule setup instruction above.
Full Script
This script will, based on the user defined variables:
1. Connect to an Azure subscription
2. Create a new storage account
3. Create a new VNet and two subnets as defined in the Network Config file
4. Build 4 windows server VMs
5. Configure NSG including:
Creating a NSG
Populating it with rules
Binding the NSG to the appropriate subnets
This PowerShell script should be run locally on an internet connected PC or server.
IMPORTANT
When this script is run, there may be warnings or other informational messages that pop in PowerShell. Only error messages
in red are cause for concern.
<#
.SYNOPSIS
Example of DMZ and Network Security Groups in an isolated network (Azure only, no hybrid connections)
.DESCRIPTION
This script will build out a sample DMZ setup containing:
- A default storage account for VM disks
- Two new cloud services
- Two Subnets (FrontEnd and BackEnd subnets)
- A Network Virtual Appliance (NVA), in this case a Barracuda NextGen Firewall
- One server on the FrontEnd Subnet (plus the NVA on the FrontEnd subnet)
- Three Servers on the BackEnd Subnet
- Network Security Groups to allow/deny traffic patterns as declared
.Notes
Security requirements are different for each use case and can be addressed in a
myriad of ways. Please be sure that any sensitive data or applications are behind
the appropriate layer(s) of protection. This script serves as an example of some
of the techniques that can be used, but should not be used for all scenarios. You
are responsible to assess your security needs and the appropriate protections
needed, and then effectively implement those protections.
#>
# Fixed Variables
$LocalAdminPwd = Read-Host -Prompt "Enter Local Admin Password to be used for all VMs"
$VMName = @()
$ServiceName = @()
$VMFamily = @()
$img = @()
$size = @()
$SubnetName = @()
$VMIP = @()
# Service Details
$FrontEndService = "FrontEnd001"
$BackEndService = "BackEnd001"
# Network Details
$VNetName = "CorpNetwork"
$FESubnet = "FrontEnd"
$FEPrefix = "10.0.1.0/24"
$BESubnet = "BackEnd"
$BEPrefix = "10.0.2.0/24"
$NetworkConfigFile = "C:\Scripts\NetworkConf2.xml"
# NSG Details
$NSGName = "MyVNetSG"
# ----------------------------- #
# No User Defined Varibles or #
# Configuration past this point #
# ----------------------------- #
# Validation
$FatalError = $false
If ($FatalError) {
Write-Host "A fatal error has occured, please see the above messages for more information." -
ForegroundColor Red
Return}
Else { Write-Host "Validation passed, now building the environment." -ForegroundColor Green}
# Create VNET
Write-Host "Creating VNET" -ForegroundColor Cyan
Set-AzureVNetConfig -ConfigurationPath $NetworkConfigFile -ErrorAction Stop
# Create Services
Write-Host "Creating Services" -ForegroundColor Cyan
New-AzureService -Location $DeploymentLocation -ServiceName $FrontEndService -ErrorAction Stop
New-AzureService -Location $DeploymentLocation -ServiceName $BackEndService -ErrorAction Stop
# Build VMs
$i=0
$VMName | Foreach {
Write-Host "Building $($VMName[$i])" -ForegroundColor Cyan
If ($VMFamily[$i] -eq "Firewall")
{
New-AzureVMConfig -Name $VMName[$i] -ImageName $img[$i] InstanceSize $size[$i] | `
Add-AzureProvisioningConfig -Linux -LinuxUser $LocalAdmin -Password $LocalAdminPwd | `
Set-AzureSubnet SubnetNames $SubnetName[$i] | `
Set-AzureStaticVNetIP -IPAddress $VMIP[$i] | `
New-AzureVM ServiceName $ServiceName[$i] -VNetName $VNetName -Location $DeploymentLocation
# Set up all the EndPoints we'll need once we're up and running
# Note: Web traffic goes through the firewall, so we'll need to set up a HTTP endpoint.
# Also, the firewall will be redirecting web traffic to a new IP and Port in a
# forwarding rule, so the HTTP endpoint here will have the same public and local
# port and the firewall will do the NATing and redirection as declared in the
# firewall rule.
Add-AzureEndpoint -Name "MgmtPort1" -Protocol tcp -PublicPort 801 -LocalPort 801 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "MgmtPort2" -Protocol tcp -PublicPort 807 -LocalPort 807 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "HTTP" -Protocol tcp -PublicPort 80 -LocalPort 80 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
# Note: A SSH endpoint is automatically created on port 22 when the appliance is created.
}
Else
{
New-AzureVMConfig -Name $VMName[$i] -ImageName $img[$i] InstanceSize $size[$i] | `
Add-AzureProvisioningConfig -Windows -AdminUsername $LocalAdmin -Password $LocalAdminPwd | `
Set-AzureSubnet SubnetNames $SubnetName[$i] | `
Set-AzureStaticVNetIP -IPAddress $VMIP[$i] | `
Set-AzureVMMicrosoftAntimalwareExtension -AntimalwareConfiguration '{"AntimalwareEnabled" :
true}' | `
Remove-AzureEndpoint -Name "PowerShell" | `
New-AzureVM ServiceName $ServiceName[$i] -VNetName $VNetName -Location $DeploymentLocation
# Note: A Remote Desktop endpoint is automatically created when each VM is created.
}
$i++
}
# Configure NSG
Write-Host "Configuring the Network Security Group (NSG)" -ForegroundColor Cyan
Environment Setup
In this example there is a subscription that contains the following:
Three cloud services: SecSvc001, FrontEnd001, and BackEnd001
A Virtual Network CorpNetwork, with three subnets: SecNet, FrontEnd, and BackEnd
A network virtual appliance, in this example a firewall, connected to the SecNet subnet
A Windows Server that represents an application web server (IIS01)
Two windows servers that represent application back end servers (AppVM01, AppVM02)
A Windows server that represents a DNS server (DNS01)
In the references section below there is a PowerShell script that will build most of the environment described above.
Building the VMs and Virtual Networks, although are done by the example script, are not described in detail in this
document.
To build the environment:
1. Save the network config xml file included in the references section (updated with names, location, and IP
addresses to match the given scenario)
2. Update the user variables in the script to match the environment the script is to be run against (subscriptions,
service names, etc)
3. Execute the script in PowerShell
Note: The region signified in the PowerShell script must match the region signified in the network configuration
xml file.
Once the script runs successfully the following post-script steps may be taken:
1. Set up the firewall rules, this is covered in the section below titled: Firewall Rule Description.
2. Optionally in the references section are two scripts to set up the web server and app server with a simple web
application to allow testing with this DMZ configuration.
Once the script runs successfully the firewall rules will need to be completed, this is covered in the section titled:
Firewall Rules.
Effective routes :
Address Prefix Next hop type Next hop IP address Status Source
-------------- ------------- ------------------- ------ ------
{10.0.0.0/16} VNETLocal Active Default
{0.0.0.0/0} Internet Active Default
{10.0.0.0/8} Null Active Default
{100.64.0.0/10} Null Active Default
{172.16.0.0/12} Null Active Default
{192.168.0.0/16} Null Active Default
The VNETLocal is always the defined address prefix(es) of the VNet for that specific network (ie it will change from
VNet to VNet depending on how each specific VNet is defined). The remaining system routes are static and default
as above.
As for priority, routes are processed via the Longest Prefix Match (LPM) method, thus the most specific route in the
table would apply to a given destination address.
Therefore, traffic (for example to the DNS01 server, 10.0.2.4) intended for the local network (10.0.0.0/16) would be
routed across the VNet to its destination due to the 10.0.0.0/16 route. In other words, for 10.0.2.4, the 10.0.0.0/16
route is the most specific route, even though the 10.0.0.0/8 and 0.0.0.0/0 also could apply, but since they are less
specific they dont affect this traffic. Thus the traffic to 10.0.2.4 would have a next hop of the local VNet and simply
route to the destination.
If traffic was intended for 10.1.1.1 for example, the 10.0.0.0/16 route wouldnt apply, but the 10.0.0.0/8 would be the
most specific, and this the traffic would be dropped (black holed) since the next hop is Null.
If the destination didnt apply to any of the Null prefixes or the VNETLocal prefixes, then it would follow the least
specific route, 0.0.0.0/0 and be routed out to the Internet as the next hop and thus out Azures internet edge.
If there are two identical prefixes in the route table, the following is the order of preference based on the routes
source attribute:
1. "VirtualAppliance" = A User Defined Route manually added to the table
2. VPNGateway = A Dynamic Route (BGP when used with hybrid networks), added by a dynamic network
protocol, these routes may change over time as the dynamic protocol automatically reflects changes in peered
network
3. Default = The System Routes, the local VNet and the static entries as shown in the route table above.
NOTE
You can now use User Defined Routing (UDR) with ExpressRoute and VPN Gateways to force outbound and inbound cross-
premises traffic to be routed to a network virtual appliance (NVA).
Effective routes :
Address Prefix Next hop type Next hop IP address Status Source
-------------- ------------- ------------------- ------ ------
{10.0.1.0/24} VNETLocal Active
{10.0.0.0/16} VirtualAppliance 10.0.0.4 Active
{0.0.0.0/0} VirtualAppliance 10.0.0.4 Active
For this example, the following commands are used to build the route table, add a user defined route, and then bind
the route table to a subnet (Note; any items below beginning with a dollar sign (e.g.: $BESubnet) are user defined
variables from the script in the reference section of this document):
1. First the base routing table must be created. This snippet shows the creation of the table for the Backend
subnet. In the script, a corresponding table is also created for the Frontend subnet.
New-AzureRouteTable -Name $BERouteTableName `
-Location $DeploymentLocation `
-Label "Route table for $BESubnet subnet"
2. Once the route table is created, specific user defined routes can be added. In this snipped, all traffic (0.0.0.0/0)
will be routed through the virtual appliance (a variable, $VMIP[0], is used to pass in the IP address assigned
when the virtual appliance was created earlier in the script). In the script, a corresponding rule is also created
in the Frontend table.
Get-AzureRouteTable $BERouteTableName | `
3. The above route entry will override the default "0.0.0.0/0" route, but the default 10.0.0.0/16 rule still existing
which would allow traffic within the VNet to route directly to the destination and not to the Network Virtual
Appliance. To correct this behavior the follow rule must be added.
Get-AzureRouteTable $BERouteTableName | `
Set-AzureRoute -RouteName "Internal traffic to FW" -AddressPrefix $VNetPrefix `
-NextHopType VirtualAppliance `
-NextHopIpAddress $VMIP[0]
4. At this point there is a choice to be made. With the above two routes all traffic will route to the firewall for
assessment, even traffic within a single subnet. This may be desired, however to allow traffic within a subnet
to route locally without involvement from the firewall a third, very specific rule can be added. This route
states that any address destine for the local subnet can just route there directly (NextHopType = VNETLocal).
Get-AzureRouteTable $BERouteTableName | `
Set-AzureRoute -RouteName "Allow Intra-Subnet Traffic" -AddressPrefix $BEPrefix `
-NextHopType VNETLocal
5. Finally, with the routing table created and populated with a user defined routes, the table must now be
bound to a subnet. In the script, the front end route table is also bound to the Frontend subnet. Here is the
binding script for the back end subnet.
Set-AzureSubnetRouteTable -VirtualNetworkName $VNetName `
-SubnetName $BESubnet `
-RouteTableName $BERouteTableName
IP Forwarding
A companion feature to UDR, is IP Forwarding. This is a setting on a Virtual Appliance that allows it to receive traffic
not specifically addressed to the appliance and then forward that traffic to its ultimate destination.
As an example, if traffic from AppVM01 makes a request to the DNS01 server, UDR would route this to the firewall.
With IP Forwarding enabled, the traffic for the DNS01 destination (10.0.2.4) will be accepted by the appliance
(10.0.0.4) and then forwarded to its ultimate destination (10.0.2.4). Without IP Forwarding enabled on the Firewall,
traffic would not be accepted by the appliance even though the route table has the firewall as the next hop.
IMPORTANT
Its critical to remember to enable IP Forwarding in conjunction with User Defined Routing.
Setting up IP Forwarding is a single command and can be done at VM creation time. For the flow of this example
the code snippet is towards the end of the script and grouped with the UDR commands:
1. Call the VM instance that is your virtual appliance, the firewall in this case, and enable IP Forwarding (Note;
any item in red beginning with a dollar sign (e.g.: $VMName[0]) is a user defined variable from the script in
the reference section of this document. The zero in brackets, [0], represents the first VM in the array of VMs,
for the example script to work without modification, the first VM (VM 0) must be the firewall):
Get-AzureVM -Name $VMName[0] -ServiceName $ServiceName[0] | `
Set-AzureIPForwarding -Enable
However, since the NSG is only bound to the Frontend and Backend subnets, the rule isnt processed on traffic
inbound to the Security subnet. As a result, even though the NSG rule says no Internet traffic to any address on the
VNet, because the NSG was never bound to the Security subnet, traffic will flow to the Security subnet.
Firewall Rules
On the firewall, forwarding rules will need to be created. Since the firewall is blocking or forwarding all inbound,
outbound, and intra-VNet traffic many firewall rules are needed. Also, all inbound traffic will hit the Security Service
public IP address (on different ports), to be processed by the firewall. A best practice is to diagram the logical flows
before setting up the subnets and firewall rules to avoid rework later. The following figure is a logical view of the
firewall rules for this example:
NOTE
Based on the Network Virtual Appliance used, the management ports will vary. In this example a Barracuda NextGen Firewall
is referenced which uses ports 22, 801, and 807. Please consult the appliance vendor documentation to find the exact ports
used for management of the device being used.
TIP
On the second application traffic rule, any port is allowed for easy of this example, in a real scenario the most specific port and
address ranges should be used to reduce the attack surface of this rule.
IMPORTANT
Once all of the above rules are created, its important to review the priority of each rule to ensure traffic will be allowed or
denied as desired. For this example, the rules are in priority order. It's easy to be locked out of the firewall due to mis-ordered
rules. At a minimum, ensure the management for the firewall itself is always the absolute highest priority rule.
Rule Prerequisites
One prerequisite for the Virtual Machine running the firewall are public endpoints. For the firewall to process traffic
the appropriate public endpoints must be open. There are three types of traffic in this example; 1) Management
traffic to control the firewall and firewall rules, 2) RDP traffic to control the windows servers, and 3) Application
Traffic. These are the three columns of traffic types in the upper half of logical view of the firewall rules above.
IMPORTANT
A key takeway here is to remember that all traffic will come through the firewall. So to remote desktop to the IIS01 server,
even though it's in the Front End Cloud Service and on the Front End subnet, to access this server we will need to RDP to the
firewall on port 8014, and then allow the firewall to route the RDP request internally to the IIS01 RDP Port. The Azure portal's
"Connect" button won't work because there is no direct RDP path to IIS01 (as far as the portal can see). This means all
connections from the internet will be to the Security Service and a Port, e.g. secscv001.cloudapp.net:xxxx (reference the above
diagram for the mapping of External Port and Internal IP and Port).
An endpoint can be opened either at the time of VM creation or post build as is done in the example script and
shown below in this code snippet (Note; any item beginning with a dollar sign (e.g.: $VMName[$i]) is a user defined
variable from the script in the reference section of this document. The $i in brackets, [$i], represents the array
number of a specific VM in an array of VMs):
This will create a named network for the FrontEnd subnet, a similar object should be created for the BackEnd subnet
as well. Now the subnets can be more easily referenced by name in the firewall rules.
For the DNS Server Object:
This single IP address reference will be utilized in a DNS rule later in the document.
The second prerequisite objects are Services objects. These will represent the RDP connection ports for each server.
Since the existing RDP service object is bound to the default RDP port, 3389, new Services can be created to allow
traffic from the external ports (8014-8026). The new ports could also be added to the existing RDP service, but for
ease of demonstration, an individual rule for each server can be created. To create a new RDP rule for a server;
starting from the Barracuda NG Admin client dashboard, navigate to the configuration tab, in the Operational
Configuration section click Ruleset, then click Services under the Firewall Objects menu, scroll down the list of
services and select the RDP service. Right-click and select copy, then right-click and select Paste. There is now a
RDP-Copy1 Service Object that can be edited. Right-click RDP-Copy1 and select Edit, the Edit Service Object
window will pop up as shown here:
The values can then be edited to represent the RDP service for a specific server. For AppVM01 the above default
RDP rule should be modified to reflect a new Service Name, Description, and external RDP Port used in the Figure 8
diagram (Note: the ports are changed from the RDP default of 3389 to the external port being used for this specific
server, in the case of AppVM01 the external Port is 8025) the modified service is shown below:
This process must be repeated to create RDP Services for the remaining servers; AppVM02, DNS01, and IIS01. The
creation of these Services will make the Rule creation simpler and more obvious in the next section.
NOTE
An RDP service for the Firewall is not needed for two reasons; 1) first the firewall VM is a Linux based image so SSH would be
used on port 22 for VM management instead of RDP, and 2) port 22, and two other management ports are allowed in the
first management rule described below to allow for management connectivity.
TIP
The source address space in this rule is Any, if the management IP address ranges are known, reducing this scope would also
reduce the attack surface to the management ports.
RDP Rules: These Destination NAT rules will allow management of the individual servers via RDP. There are
four critical fields needed to create this rule:
1. Source to allow RDP from anywhere, the reference Any is used in the Source field.
2. Service use the appropriate Service Object created earlier, in this case AppVM01 RDP, the external
ports redirect to the servers local IP address and to port 3386 (the default RDP port). This specific rule is
for RDP access to AppVM01.
3. Destination should be the local port on the firewall, DCHP 1 Local IP or eth0 if using static IPs. The
ordinal number (eth0, eth1, etc) may be different if your network appliance has multiple local interfaces.
This is the port the firewall is sending out from (may be the same as the receiving port), the actual routed
destination is in the Target List field.
4. Redirection this section tells the virtual appliance where to ultimately redirect this traffic. The
simplest redirection is to place the IP and Port (optional) in the Target List field. If no port is used the
destination port on the inbound request will be used (ie no translation), if a port is designated the port
will also be NATd along with the IP address.
A total of four RDP rules will need to be created:
TIP
Narrowing down the scope of the Source and Service fields will reduce the attack surface. The most limited scope that will
allow functionality should be used.
Application Traffic Rules: There are two Application Traffic Rules, the first for the front end web traffic, and
the second for the back end traffic (eg web server to data tier). These rules will depend on the network
architecture (where your servers are placed) and traffic flows (which direction the traffic flows, and which
ports are used).
First discussed is the front end rule for web traffic:
This Destination NAT rule allows the actual application traffic to reach the application server. While the other
rules allow for security, management, etc., Application Rules are what allow external users or services to
access the application(s). For this example, there is a single web server on port 80, thus the single firewall
application rule will redirect inbound traffic to the external IP, to the web servers internal IP address.
Note: that there is no port assigned in the Target List field, thus the inbound port 80 (or 443 for the Service
selected) will be used in the redirection of the web server. If the web server is listening on a different port, for
example port 8080, the Target List field could be updated to 10.0.1.4:8080 to allow for the Port redirection as
well.
The next Application Traffic Rule is the back end rule to allow the Web Server to talk to the AppVM01 server
(but not AppVM02) via Any service:
This Pass rule allows any IIS server on the Frontend subnet to reach the AppVM01 (IP Address 10.0.2.5) on
Any port, using any Protocol to access data needed by the web application.
In this screen shot an "<explicit-dest>" is used in the Destination field to signify 10.0.2.5 as the destination.
This could be either explicit as shown or a named Network Object (as was done in the prerequisites for the
DNS server). This is up to the administrator of the firewall as to which method will be used. To add 10.0.2.5
as an Explict Desitnation, double-click on the first blank row under <explicit-dest> and enter the address in
the window that pops up.
With this Pass Rule, no NAT is needed since this is internal traffic, so the Connection Method can be set to
"No SNAT".
Note: The Source network in this rule is any resource on the FrontEnd subnet, if there will only be one, or a
known specific number of web servers, a Network Object resource could be created to be more specific to
those exact IP addresses instead of the entire Frontend subnet.
TIP
This rule uses the service Any to make the sample application easier to setup and use, this will also allow ICMPv4 (ping) in a
single rule. However, this is not a recommended practice. The ports and protocols (Services) should be narrowed to the
minimum possible that allows application operation to reduce the attack surface across this boundary.
TIP
Although this rule shows an explicit-dest reference being used, a consistent approach should be used throughout the firewall
configuration. It is recommended that the named Network Object be used throughout for easier readability and
supportability. The explicit-dest is used here only to show an alternative reference method and is not generally recommended
(especially for complex configurations).
Outbound to Internet Rule: This Pass rule will allow traffic from any Source network to pass to the selected
Destination networks. This rule is a default rule usually already on the Barracuda NextGen firewall, but is in a
disabled state. Right-clicking on this rule can access the Activate Rule command. The rule shown here has
been modified to add the two local subnets that were created as references in the prerequisite section of this
document to the Source attribute of this rule.
DNS Rule: This Pass rule allows only DNS (port 53) traffic to pass to the DNS server. For this environment
most traffic from the FrontEnd to the BackEnd is blocked, this rule specifically allows DNS.
Note: In this screen shot the Connection Method is included. Because this rule is for internal IP to internal IP
address traffic, no NATing is required, this the Connection Method is set to No SNAT for this Pass rule.
Subnet to Subnet Rule: This Pass rule is a default rule that has been activated and modified to allow any
server on the back end subnet to connect to any server on the front end subnet. This rule is all internal traffic
so the Connection Method can be set to No SNAT.
Note: The Bi-directional checkbox is not checked (nor is it checked in most rules), this is significant for this
rule in that it makes this rule one directional, a connection can be initiated from the back end subnet to the
front end network, but not the reverse. If that checkbox was checked, this rule would enable bi-directional
traffic, which from our logical diagram is not desired.
Deny All Traffic Rule: This should always be the final rule (in terms of priority), and as such if a traffic flows
fails to match any of the preceding rules it will be dropped by this rule. This is a default rule and usually
activated, no modifications are generally needed.
IMPORTANT
Once all of the above rules are created, its important to review the priority of each rule to ensure traffic will be allowed or
denied as desired. For this example, the rules are in the order they should appear in the Main Grid of forwarding rules in the
Barracuda Management Client.
Rule Activation
With the ruleset modified to the specification of the logic diagram, the ruleset must be uploaded to the firewall and
then activated.
In the upper right hand corner of the management client are a cluster of buttons. Click the Send Changes button
to send the modified rules to the firewall, then click the Activate button.
With the activation of the firewall ruleset this example environment build is complete.
Traffic Scenarios
IMPORTANT
A key takeway is to remember that all traffic will come through the firewall. So to remote desktop to the IIS01 server, even
though it's in the Front End Cloud Service and on the Front End subnet, to access this server we will need to RDP to the
firewall on port 8014, and then allow the firewall to route the RDP request internally to the IIS01 RDP Port. The Azure portal's
"Connect" button won't work because there is no direct RDP path to IIS01 (as far as the portal can see). This means all
connections from the internet will be to the Security Service and a Port, e.g. secscv001.cloudapp.net:xxxx.
References
Main Script and Network Config
Save the Full Script in a PowerShell script file. Save the Network Config into a file named NetworkConf2.xml.
Modify the user defined variables as needed. Run the script, then follow the Firewall rule setup instruction above.
Full Script
This script will, based on the user defined variables:
1. Connect to an Azure subscription
2. Create a new storage account
3. Create a new VNet and three subnets as defined in the Network Config file
4. Build five virtual machines; 1 firewall and 4 windows server VMs
5. Configure UDR including:
a. Creating two new route tables
b. Add routes to the tables
c. Bind tables to appropriate subnets
6. Enable IP Forwarding on the NVA
7. Configure NSG including:
a. Creating a NSG
b. Adding a rule
c. Binding the NSG to the appropriate subnets
This PowerShell script should be run locally on an internet connected PC or server.
IMPORTANT
When this script is run, there may be warnings or other informational messages that pop in PowerShell. Only error messages
in red are cause for concern.
<#
.SYNOPSIS
Example of DMZ and User Defined Routing in an isolated network (Azure only, no hybrid connections)
.DESCRIPTION
This script will build out a sample DMZ setup containing:
- A default storage account for VM disks
- Three new cloud services
- Three Subnets (SecNet, FrontEnd, and BackEnd subnets)
- A Network Virtual Appliance (NVA), in this case a Barracuda NextGen Firewall
- One server on the FrontEnd Subnet
- Three Servers on the BackEnd Subnet
- IP Forwading from the FireWall out to the internet
- User Defined Routing FrontEnd and BackEnd Subnets to the NVA
.Notes
Everyone's security requirements are different and can be addressed in a myriad of ways.
Please be sure that any sensitive data or applications are behind the appropriate
layer(s) of protection. This script serves as an example of some of the techniques
that can be used, but should not be used for all scenarios. You are responsible to
assess your security needs and the appropriate protections needed, and then effectively
implement those protections.
#>
# Fixed Variables
$LocalAdminPwd = Read-Host -Prompt "Enter Local Admin Password to be used for all VMs"
$VMName = @()
$ServiceName = @()
$VMFamily = @()
$img = @()
$size = @()
$SubnetName = @()
$VMIP = @()
# Service Details
$SecureService = "SecSvc001"
$FrontEndService = "FrontEnd001"
$BackEndService = "BackEnd001"
# Network Details
$VNetName = "CorpNetwork"
$VNetPrefix = "10.0.0.0/16"
$SecNet = "SecNet"
$FESubnet = "FrontEnd"
$FEPrefix = "10.0.1.0/24"
$BESubnet = "BackEnd"
$BEPrefix = "10.0.2.0/24"
$NetworkConfigFile = "C:\Scripts\NetworkConf3.xml"
# UDR Details
$FERouteTableName = "FrontEndSubnetRouteTable"
$BERouteTableName = "BackEndSubnetRouteTable"
# NSG Details
$NSGName = "MyVNetSG"
# ----------------------------- #
# No User Defined Varibles or #
# Configuration past this point #
# ----------------------------- #
# Validation
$FatalError = $false
If ($FatalError) {
Write-Host "A fatal error has occured, please see the above messages for more information." -
ForegroundColor Red
Return}
Else { Write-Host "Validation passed, now building the environment." -ForegroundColor Green}
# Create VNET
Write-Host "Creating VNET" -ForegroundColor Cyan
Set-AzureVNetConfig -ConfigurationPath $NetworkConfigFile -ErrorAction Stop
# Create Services
Write-Host "Creating Services" -ForegroundColor Cyan
New-AzureService -Location $DeploymentLocation -ServiceName $SecureService -ErrorAction Stop
New-AzureService -Location $DeploymentLocation -ServiceName $FrontEndService -ErrorAction Stop
New-AzureService -Location $DeploymentLocation -ServiceName $BackEndService -ErrorAction Stop
# Build VMs
$i=0
$VMName | Foreach {
Write-Host "Building $($VMName[$i])" -ForegroundColor Cyan
If ($VMFamily[$i] -eq "Firewall")
{
New-AzureVMConfig -Name $VMName[$i] -ImageName $img[$i] InstanceSize $size[$i] | `
Add-AzureProvisioningConfig -Linux -LinuxUser $LocalAdmin -Password $LocalAdminPwd | `
Set-AzureSubnet SubnetNames $SubnetName[$i] | `
Set-AzureStaticVNetIP -IPAddress $VMIP[$i] | `
New-AzureVM ServiceName $ServiceName[$i] -VNetName $VNetName -Location $DeploymentLocation
# Set up all the EndPoints we'll need once we're up and running
# Note: All traffic goes through the firewall, so we'll need to set up all ports here.
# Also, the firewall will be redirecting traffic to a new IP and Port in a forwarding
# rule, so all of these endpoint have the same public and local port and the firewall
# will do the mapping, NATing, and/or redirection as declared in the firewall rules.
Add-AzureEndpoint -Name "MgmtPort1" -Protocol tcp -PublicPort 801 -LocalPort 801 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "MgmtPort2" -Protocol tcp -PublicPort 807 -LocalPort 807 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "HTTP" -Protocol tcp -PublicPort 80 -LocalPort 80 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "RDPWeb" -Protocol tcp -PublicPort 8014 -LocalPort 8014 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "RDPApp1" -Protocol tcp -PublicPort 8025 -LocalPort 8025 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "RDPApp2" -Protocol tcp -PublicPort 8026 -LocalPort 8026 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
Add-AzureEndpoint -Name "RDPDNS01" -Protocol tcp -PublicPort 8024 -LocalPort 8024 -VM (Get-AzureVM
-ServiceName $ServiceName[$i] -Name $VMName[$i]) | Update-AzureVM
# Note: A SSH endpoint is automatically created on port 22 when the appliance is created.
}
Else
{
New-AzureVMConfig -Name $VMName[$i] -ImageName $img[$i] InstanceSize $size[$i] | `
Add-AzureProvisioningConfig -Windows -AdminUsername $LocalAdmin -Password $LocalAdminPwd | `
Set-AzureSubnet SubnetNames $SubnetName[$i] | `
Set-AzureSubnet SubnetNames $SubnetName[$i] | `
Set-AzureStaticVNetIP -IPAddress $VMIP[$i] | `
Set-AzureVMMicrosoftAntimalwareExtension -AntimalwareConfiguration '{"AntimalwareEnabled" :
true}' | `
Remove-AzureEndpoint -Name "RemoteDesktop" | `
Remove-AzureEndpoint -Name "PowerShell" | `
New-AzureVM ServiceName $ServiceName[$i] -VNetName $VNetName -Location $DeploymentLocation
}
$i++
}
# Configure NSG
Write-Host "Configuring the Network Security Group (NSG)" -ForegroundColor Cyan
# Turn On ICMPv4
New-NetFirewallRule -Name Allow_ICMPv4 -DisplayName "Allow ICMPv4" `
-Protocol ICMPv4 -Enabled True -Profile Any -Action Allow
If you use the following scripts, this firewall rule addition is the first statement.
# Turn On ICMPv4
Write-Host "Creating ICMP Rule in Windows Firewall" -ForegroundColor Cyan
New-NetFirewallRule -Name Allow_ICMPv4 -DisplayName "Allow ICMPv4" -Protocol ICMPv4 -Enabled True -Profile
Any -Action Allow
# Install IIS
Write-Host "Installing IIS and .Net 4.5, this can take some time, like 15+ minutes..." -ForegroundColor
Cyan
add-windowsfeature Web-Server, Web-WebServer, Web-Common-Http, Web-Default-Doc, Web-Dir-Browsing, Web-
Http-Errors, Web-Static-Content, Web-Health, Web-Http-Logging, Web-Performance, Web-Stat-Compression, Web-
Security, Web-Filtering, Web-App-Dev, Web-ISAPI-Ext, Web-ISAPI-Filter, Web-Net-Ext, Web-Net-Ext45, Web-Asp-
Net45, Web-Mgmt-Tools, Web-Mgmt-Console
# Create Web App Pages
Write-Host "Creating Web page and Web.Config file" -ForegroundColor Cyan
$MainPage = '<%@ Page Language="vb" AutoEventWireup="false" %>
<%@ Import Namespace="System.IO" %>
<script language="vb" runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim FILENAME As String = "\\10.0.2.5\WebShare\Rand.txt"
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(FILENAME)
Dim contents As String = objStreamReader.ReadToEnd()
lblOutput.Text = contents
objStreamReader.Close()
lblTime.Text = Now()
End Sub
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DMZ Example App</title>
</head>
<body style="font-family: Optima,Segoe,Segoe UI,Candara,Calibri,Arial,sans-serif;">
<form id="frmMain" runat="server">
<div>
<h1>Looks like you made it!</h1>
This is a page from the inside (a web server on a private network),<br />
and it is making its way to the outside! (If you are viewing this from the internet)<br />
<br />
The following sections show:
<ul style="margin-top: 0px;">
<li> Local Server Time - Shows if this page is or isnt cached anywhere</li>
<li> File Output - Shows that the web server is reaching AppVM01 on the backend subnet and
successfully returning content</li>
<li> Image from the Internet - Doesnt really show anything, but it made me happy to see this when
the app worked</li>
</ul>
<div style="border: 2px solid #8AC007; border-radius: 25px; padding: 20px; margin: 10px; width:
650px;">
<b>Local Web Server Time</b>: <asp:Label runat="server" ID="lblTime" /></div>
<div style="border: 2px solid #8AC007; border-radius: 25px; padding: 20px; margin: 10px; width:
650px;">
<b>File Output from AppVM01</b>: <asp:Label runat="server" ID="lblOutput" /></div>
<div style="border: 2px solid #8AC007; border-radius: 25px; padding: 20px; margin: 10px; width:
650px;">
<b>Image File Linked from the Internet</b>:<br />
<br />
<img src="http://sd.keepcalm-o-matic.co.uk/i/keep-calm-you-made-it-7.png" alt="You made it!"
width="150" length="175"/></div>
</div>
</form>
</body>
</html>'
# Set App Pool to Clasic Pipeline to remote file access will work easier
Write-Host "Updaing IIS Settings" -ForegroundColor Cyan
c:\windows\system32\inetsrv\appcmd.exe set app "Default Web Site/" /applicationPool:".NET v4.5 Classic"
c:\windows\system32\inetsrv\appcmd.exe set config "Default Web Site/"
/section:system.webServer/security/authentication/anonymousAuthentication /userName:$theAdmin
/password:$thePassword /commit:apphost
Write-Host
Write-Host "Web App Creation Successfull!" -ForegroundColor Green
Write-Host
IMPORTANT
Best Practice: Never turn off IE Enhanced Security on a production server, plus it's generally a bad idea to surf the web from
a production server. Also, opening up file shares for anonymous access is a bad idea, but done here for simplicity.
This PowerShell script should be run locally while RDPd into AppVM01. PowerShell is required to be run as
Administrator to ensure successful execution.
# AppVM01 Server Post Build Config Script
# PowerShell must be run as Administrator for Net Share commands to work
# Turn On ICMPv4
New-NetFirewallRule -Name Allow_ICMPv4 -DisplayName "Allow ICMPv4" -Protocol ICMPv4 -Enabled True -Profile
Any -Action Allow
# Create Directory
New-Item "C:\WebShare" -ItemType Directory
Write-Host
Write-Host "File Server Set up Successfull!" -ForegroundColor Green
Write-Host
Next steps
Run the IIS01 script on an IIS server
Run File Server script on AppVM01
Browse to the Public IP on IIS01 to validate your build
Create a virtual network (classic) with multiple subnets
8/1/2017 5 min to read Edit Online
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends creating most new virtual networks through the
Resource Manager deployment model.
In this tutorial, learn how to create a basic Azure virtual network (classic) that has separate public and private
subnets. You can create Azure resources, like Virtual machines and Cloud services in a subnet. Resources created in
virtual networks (classic) can communicate with each other, and with resources in other networks connected to a
virtual network.
Learn more about all virtual network and subnet settings.
WARNING
Virtual networks (classic) are immediately deleted by Azure when a subscription is disabled. Virtual networks (classic) are
deleted regardless of whether resources exist in the virtual network. If you later re-enable the subscription, resources that
existed in the virtual network must be recreated.
You can create a virtual network (classic) by using the Azure portal, the Azure command-line interface (CLI) 1.0, or
PowerShell.
Portal
1. In an Internet browser, go to the Azure portal. Log in using your Azure account. If you don't have an Azure
account, you can sign up for a free trial.
2. Click +New in the portal.
3. Enter Virtual network in the Search the Marketplace box at the top of the New blade that appears. Click
Virtual network when it appears in the search results.
4. Select Classic in the Select a deployment model box in the Virtual Network blade that appears, then click
Create.
5. Enter the following values on the Create virtual network (classic) blade and then click Create:
SETTING VALUE
Name myVnet
If you're new to Azure, learn more about resource groups, subscriptions, and locations (also referred to as
regions).
6. In the portal, you can create only one subnet when you create a virtual network. In this tutorial, you create a
second subnet after you create the virtual network. You might later create Internet-accessible resources in the
Public subnet. You also might create resources that aren't accessible from the Internet in the Private subnet. To
create the second subnet, enter myVnet in the Search resources box at the top of the page. Click myVnet
when it appears in the search results.
7. Click Subnets (in the SETTINGS section) on the Create virtual network (classic) blade that appears.
8. Click +Add on the myVnet - Subnets blade that appears.
9. Enter Private for Name on the Add subnet blade. Enter 10.0.1.0/24 for Address range. Click OK.
10. On the myVnet - Subnets blade, you can see the Public and Private subnets that you created.
11. Optional: When you finish this tutorial, you might want to delete the resources that you created, so that you
don't incur usage charges:
Click Overview on the myVnet blade.
Click the Delete icon on the myVnet blade.
To confirm the deletion, click Yes in the Delete virtual network box.
Azure CLI
1. You can either install and configure the Azure CLI, or use the CLI within the Azure Cloud Shell. The Azure Cloud
Shell is a free Bash shell that you can run directly within the Azure portal. It has the Azure CLI preinstalled and
configured to use with your account. To get help for CLI commands, type azure <command> --help .
2. In a CLI session, log in to Azure with the command that follows. If you click Try it in the box below, a Cloud
Shell opens. You can log in to your Azure subscription, without entering the following command:
azure login
3. To ensure the CLI is in Service Management mode, enter the following command:
azure network vnet create --vnet myVnet --address-space 10.0.0.0 --cidr 16 --subnet-name Private --
subnet-start-ip 10.0.0.0 --subnet-cidr 24 --location "East US"
azure network vnet subnet create --name Public --vnet-name myVnet --address-prefix 10.0.1.0/24
NOTE
Though you can't specify a resource group to create a virtual network (classic) in using the CLI, Azure creates the virtual
network in a resource group named Default-Networking.
PowerShell
1. Install the latest version of the PowerShell Azure module. If you're new to Azure PowerShell, see Azure
PowerShell overview.
2. Start a PowerShell session.
3. In PowerShell, log in to Azure by entering the Add-AzureAccount command.
4. Change the following path and filename, as appropriate, then export your existing network configuration file:
5. To create a virtual network with public and private subnets, use any text editor to add the
VirtualNetworkSite element that follows to the network configuration file.
WARNING
Importing a changed network configuration file can cause changes to existing virtual networks (classic) in your
subscription. Ensure you only add the previous virtual network and that you don't change or remove any existing
virtual networks from your subscription.
8. Optional: You might want to delete the resources that you created when you finish this tutorial, so that you
don't incur usage charges. To delete the virtual network, complete steps 4-6 again, this time removing the
VirtualNetworkSite element you added in step 5.
NOTE
Though you can't specify a resource group to create a virtual network (classic) in using PowerShell, Azure creates the virtual
network in a resource group named Default-Networking.
Next steps
To learn about all virtual network and subnet settings, see Manage virtual networks and Manage virtual network
subnets. You have various options for using virtual networks and subnets in a production environment to meet
different requirements.
To filter inbound and outbound subnet traffic, create and apply network security groups to subnets.
Create a Windows or a Linux virtual machine, and then connect it to an existing virtual network.
To connect two virtual networks in the same Azure location, create a virtual network peering between the virtual
networks. You can peer a virtual network (Resource Manager) to a virtual network (classic), but you cannot
create a peering between two virtual networks (classic).
Connect the virtual network to an on-premises network by using a VPN Gateway or Azure ExpressRoute circuit.
Create a virtual network (classic) by using the Azure
portal
6/27/2017 2 min to read Edit Online
An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure
network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also
further segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in
the same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can
expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are
not familiar with VNets.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This document covers creating a VNet by using the classic deployment model. You can also create a virtual
network in the Resource Manager deployment model by using the Azure portal.
Scenario
To better illustrate how to create a VNet and subnets, this document will use the scenario below.
In this scenario you will create a VNet named TestVNet with a reserved CIDR block of 192.168.0.0./16. Your VNet
will contain the following subnets:
FrontEnd, using 192.168.1.0/24 as its CIDR block.
BackEnd, using 192.168.2.0/24 as its CIDR block.
3. On the Virtual network blade, type the Name of the VNet, and then click Address space. Configure your
address space settings for the VNet and its first subnet, then click OK. The figure below shows the CIDR
block settings for our scenario.
4. Click Resource Group and select a resource group to add the VNet to, or click Create new resource
group to add the VNet to a new resource group. The figure below shows the resource group settings for a
new resource group called TestRG. For more information about resource groups, visit Azure Resource
Manager Overview.
5. If necessary, change the Subscription and Location settings for your VNet.
6. If you do not want to see the VNet as a tile in the Startboard, disable Pin to Startboard.
7. Click Create and notice the tile named Creating Virtual network as shown in the figure below.
8. Wait for the VNet to be created, and when you see the tile below, click it to add more subnets.
9. You should see the Configuration for your VNet as shown below.
10. Click Subnets > Add, then type a Name and specify an Address range (CIDR block) for your subnet, and
then click OK. The figure below shows the settings for our current scenario.
Create a virtual network (classic) using a network
configuration file with PowerShell
6/27/2017 2 min to read Edit Online
An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure
network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also
further segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in
the same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can
expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are
not familiar with VNets.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure
Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure
resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This document covers creating a VNet by using the classic deployment model. You can also create a virtual
network in the Resource Manager deployment model.
Scenario
To better illustrate how to create a VNet and subnets, this document will use the scenario below.
In this scenario you will create a VNet named TestVNet with a reserved CIDR block of 192.168.0.0./16. Your
VNet will contain the following subnets:
FrontEnd, using 192.168.1.0/24 as its CIDR block.
BackEnd, using 192.168.2.0/24 as its CIDR block.
Expected output:
XMLConfiguration
----------------
<?xml version="1.0" encoding="utf-8"?>...
3. Open the file you saved in step 2 using any XML or text editor application, and look for the element. If you
have any networks already created, each network is displayed as its own element.
4. To create the virtual network described in this scenario, add the following XML just under the element:
Returned output:
If OperationStatus is not Succeeded in the returned output, check the xml file for errors and complete
step 6 again.
7. From the Azure PowerShell console, use the Get-AzureVnetSite cmdlet to verify that the new network
was added by running the following command:
AddressSpacePrefixes : {192.168.0.0/16}
Location : Central US
Name : TestVNet
State : Created
Subnets : {FrontEnd, BackEnd}
OperationDescription : Get-AzureVNetSite
OperationStatus : Succeeded
Create a virtual network (classic) by using the Azure
CLI
6/27/2017 3 min to read Edit Online
An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure
network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also
further segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in
the same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can
expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are
not familiar with VNets.
IMPORTANT
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models:
Azure Resource Manager and classic. Make sure you understand deployment models and tools before you work with any
Azure resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This document covers creating a VNet by using the classic deployment model. You can also create a virtual
network in the Resource Manager deployment model by using the Azure CLI.
Scenario
To better illustrate how to create a VNet and subnets, this document will use the scenario below.
In this scenario you will create a VNet named TestVNet with a reserved CIDR block of 192.168.0.0./16. Your
VNet will contain the following subnets:
FrontEnd, using 192.168.1.0/24 as its CIDR block.
BackEnd, using 192.168.2.0/24 as its CIDR block.
Expected output:
-t (or --vnet-name. Name of the VNet where the subnet will be created. For our scenario, TestVNet.
-n (or --name). Name of the new subnet. For our scenario, BackEnd.
-a (or --address-prefix). Subnet CIDR block. Four our scenario, 192.168.2.0/24.
4. Run the azure network vnet show command to view the properties of the new vnet, as shown below.
Learn how to add an existing network interface when creating a VM or add or remove network interfaces from an
existing VM in the stopped (deallocated) state. A network interface enables an Azure Virtual Machine (VM) to
communicate with Internet, Azure, and on-premises resources. A VM can have one or more network interfaces.
If you need to add, change, or remove IP addresses for a network interface, read the Manage network interface IP
addresses article. If you need to create, change, or delete network interfaces, read the Manage network interfaces
article.
Commands
TOOL COMMAND
CLI az vm create
PowerShell New-AzureRmVM
WARNING
If a network interface has a private IPv6 address assigned to it, it cannot be added to an existing virtual machine. You can
only add a network interface with an assigned private IPv6 address to a virtual machine when you create a virtual machine.
See Network interface IP addresses to learn more about assigning IP addresses to network interfaces.
TOOL COMMAND
TOOL COMMAND
CLI az vm show
PowerShell Get-AzureRmVM
TOOL COMMAND
Next steps
To create a VM with multiple network interfaces or IP addresses, read the following articles:
Commands
TASK TOOL
Create a single NIC VM with a private IPv6 address (behind an CLI, PowerShell, Azure Resource Manager template
Azure Load Balancer)
Name Resolution for VMs and Role Instances
6/27/2017 9 min to read Edit Online
Depending on how you use Azure to host IaaS, PaaS, and hybrid solutions, you may need to allow the VMs and
role instances that you create to communicate with each other. Although this communication can be done by
using IP addresses, it is much simpler to use names that can be easily remembered and do not change.
When role instances and VMs hosted in Azure need to resolve domain names to internal IP addresses, they can
use one of two methods:
Azure-provided name resolution
Name resolution using your own DNS server (which may forward queries to the Azure-provided DNS servers)
The type of name resolution you use depends on how your VMs and role instances need to communicate with
each other.
The following table illustrates scenarios and corresponding name resolution solutions:
Reverse DNS for internal IPs Name resolution using your own DNS n/a
server
Name resolution between VMs or role Not applicable. Connectivity between n/a
instances located in different cloud VMs and role instances in different
services, not in a virtual network cloud services is not supported outside
a virtual network.
NOTE
In the case of web and worker roles, you can also access the internal IP addresses of role instances based on the role name
and instance number using the Azure Service Management REST API. For more information, see Service Management REST
API Reference.
NOTE
The 'dnsmasq' package is only one of the many DNS caches available for Linux. Before using it, please check its suitability for
your particular needs and that no other cache is installed.
Client-side Retries:
DNS is primarily a UDP protocol. As the UDP protocol doesn't guarantee message delivery, retry logic is handled
in the DNS protocol itself. Each DNS client (operating system) can exhibit different retry logic depending on the
creators preference:
Windows operating systems retry after 1 second and then again after another 2, 4 and another 4 seconds.
The default Linux setup retries after 5 seconds. It is recommended to change this to retry 5 times at 1 second
intervals.
To check the current settings on a Linux VM, 'cat /etc/resolv.conf' and look at the 'options' line, e.g.:
The resolv.conf file is usually auto-generated and should not be edited. The specific steps for adding the 'options'
line vary by distro:
Ubuntu (uses resolvconf):
add the options line to '/etc/resolveconf/resolv.conf.d/head'
run 'resolvconf -u' to update
SUSE (uses netconf):
add 'timeout:1 attempts:5' to the NETCONFIG_DNS_RESOLVER_OPTIONS="" parameter in
'/etc/sysconfig/network/config'
run 'netconfig update' to update
OpenLogic (uses NetworkManager):
add 'echo "options timeout:1 attempts:5"' to '/etc/NetworkManager/dispatcher.d/11-dhclient'
run 'service network restart' to update
Name resolution using your own DNS server
There are a number of situations where your name resolution needs may go beyond the features provided by
Azure, for example when using Active Directory domains or when you require DNS resolution between virtual
networks (vnets). To cover these scenarios, Azure provides the ability for you to use your own DNS servers.
DNS servers within a virtual network can forward DNS queries to Azure's recursive resolvers to resolve
hostnames within that virtual network. For example, a Domain Controller (DC) running in Azure can respond to
DNS queries for its domains and forward all other queries to Azure. This allows VMs to see both your on-premises
resources (via the DC) and Azure-provided hostnames (via the forwarder). Access to Azure's recursive resolvers is
provided via the virtual IP 168.63.129.16.
DNS forwarding also enables inter-vnet DNS resolution and allows your on-premises machines to resolve Azure-
provided hostnames. In order to resolve a VM's hostname, the DNS server VM must reside in the same virtual
network and be configured to forward hostname queries to Azure. As the DNS suffix is different in each vnet, you
can use conditional forwarding rules to send DNS queries to the correct vnet for resolution. The following image
shows two vnets and an on-premises network doing inter-vnet DNS resolution using this method. An example
DNS forwarder is available in the Azure Quickstart Templates gallery and GitHub.
When using Azure-provided name resolution, an Internal DNS suffix (*.internal.cloudapp.net) is provided to each
VM using DHCP. This enables hostname resolution as the hostname records are in the internal.cloudapp.net zone.
When using your own name resolution solution, the IDNS suffix is not supplied to VMs because it interferes with
other DNS architectures (like domain-joined scenarios). Instead we provide a non-functioning placeholder
(reddog.microsoft.com).
If needed, the Internal DNS suffix can be determined using PowerShell or the API:
For virtual networks in Resource Manager deployment models, the suffix is available via the network interface
card resource or via the Get-AzureRmNetworkInterface cmdlet.
In classic deployment models, the suffix is available via the Get Deployment API call or via the Get-AzureVM -
Debug cmdlet.
If forwarding queries to Azure doesn't suit your needs, you will need to provide your own DNS solution. Your DNS
solution will need to:
Provide appropriate hostname resolution, e.g. via DDNS. Note, if using DDNS you may need to disable DNS
record scavenging as Azure's DHCP leases are very long and scavenging may remove DNS records
prematurely.
Provide appropriate recursive resolution to allow resolution of external domain names.
Be accessible (TCP and UDP on port 53) from the clients it serves and be able to access the internet.
Be secured against access from the internet, to mitigate threats posed by external agents.
NOTE
For best performance, when using Azure VMs as DNS servers, IPv6 should be disabled and an Instance-Level Public IP
should be assigned to each DNS server VM. If you choose to use Windows Server as your DNS server, this article provides
additional performance analysis and optimizations.
NOTE
Network connection properties, such as DNS server IPs, should not be edited directly within Windows VMs as they may get
erased during service heal when the virtual network adaptor gets replaced.
When using the Resource Manager deployment model, DNS servers can be specified in the Portal, API/Templates
(vnet, nic) or PowerShell (vnet, nic).
When using the classic deployment model, DNS servers for the virtual network can be specified in the Portal or
the Network Configuration file. For cloud services, the DNS servers are specified via the Service Configuration file
or in PowerShell (New-AzureVM).
NOTE
If you change the DNS settings for a virtual network/virtual machine that is already deployed, you need to restart each
affected VM for the changes to take effect.
Next steps
Resource Manager deployment model:
Create or update a virtual network
Create or update a network interface card
New-AzureRmVirtualNetwork
New-AzureRmNetworkInterface
Classic deployment model:
Azure Service Configuration Schema
Virtual Network Configuration Schema
Configure a Virtual Network by Using a Network Configuration File
Optimize network throughput for Azure virtual
machines
7/25/2017 3 min to read Edit Online
Azure virtual machines (VM) have default network settings that can be further optimized for network throughput.
This article describes how to optimize network throughput for Microsoft Azure Windows and Linux VMs, including
major distributions such as Ubuntu, CentOS and Red Hat.
Windows VM
If your Windows VM is supported with Accelerated Networking, enabling that feature would be the optimal
configuration for throughput. For all other Windows VMs, using Receive Side Scaling (RSS) can reach higher
maximal throughput than a VM without RSS. RSS may be disabled by default in a Windows VM. Complete the
following steps to determine whether RSS is enabled and to enable it if it's disabled.
1. Enter the Get-NetAdapterRss PowerShell command to see if RSS is enabled for a network adapter. In the
following example output returned from the Get-NetAdapterRss , RSS is not enabled.
Name : Ethernet
InterfaceDescription : Microsoft Hyper-V Network Adapter
Enabled : False
The previous command does not have an output. The command changed NIC settings, causing temporary
connectivity loss for about one minute. A Reconnecting dialog box appears during the connectivity loss.
Connectivity is typically restored after the third attempt.
3. Confirm that RSS is enabled in the VM by entering the Get-NetAdapterRss command again. If successful, the
following example output is returned:
Name :Ethernet
InterfaceDescription : Microsoft Hyper-V Network Adapter
Enabled : True
Linux VM
RSS is always enabled by default in an Azure Linux VM. Linux kernels released since January, 2017 include new
network optimization options that enable a Linux VM to achieve higher network throughput.
Ubuntu
In order to get the optimization, first update to the latest supported version, as of June 2017, which is:
"Publisher": "Canonical",
"Offer": "UbuntuServer",
"Sku": "16.04-LTS",
"Version": "latest"
After the update is complete, enter the following commands to get the latest kernel:
apt-get -f install
apt-get --fix-missing install
apt-get clean
apt-get -y update
apt-get -y upgrade
Optional command:
apt-get -y dist-upgrade
WARNING
This Azure Linux Preview kernel may not have the same level of availability and reliability as Marketplace images and kernels
that are in general availability release. The feature is not supported, may have constrained capabilities, and may not be as
reliable as the default kernel. Do not use this kernel for production workloads.
Significant throughput performance can be achieved by installing the proposed Azure Linux kernel. To try this
kernel, add this line to /etc/apt/sources.list
apt-get update
apt-get install "linux-azure"
reboot
CentOS
In order to get the optimization, first update to the latest supported version, as of July 2017, which is:
"Publisher": "OpenLogic",
"Offer": "CentOS",
"Sku": "7.3",
"Version": "latest"
After the update is complete, install the latest Linux Integration Services (LIS). The throughput optimization is in LIS,
starting from 4.2.2-2. Enter the following commands to install LIS:
Red Hat
In order to get the optimization, first update to the latest supported version, as of July 2017, which is:
"Publisher": "RedHat"
"Offer": "RHEL"
"Sku": "7.3"
"Version": "7.3.2017071923"
After the update is complete, install the latest Linux Integration Services (LIS). The throughput optimization is in LIS,
starting from 4.2. Enter the following commands to download and install LIS:
mkdir lis4.2.2-2
cd lis4.2.2-2
wget https://download.microsoft.com/download/6/8/F/68FE11B8-FAA4-4F8D-8C7D-74DA7F2CFC8C/lis-rpms-4.2.2-2.tar.gz
tar xvzf lis-rpms-4.2.2-2.tar.gz
cd LISISO
install.sh #or upgrade.sh if prior LIS was previously installed
Learn more about Linux Integration Services Version 4.2 for Hyper-V by viewing the download page.
Next steps
Now that the VM is optimized, see the result with Bandwidth/Throughput testing Azure VM for your scenario.
Learn more with Azure Virtual Network frequently asked questions (FAQ)
Viewing and modifying hostnames
6/27/2017 2 min to read Edit Online
To allow your role instances to be referenced by host name, you must set the value for the host name in the service
configuration file for each role. You do that by adding the desired host name to the vmName attribute of the Role
element. The value of the vmName attribute is used as a base for the host name of each role instance. For example,
if vmName is webrole and there are three instances of that role, the host names of the instances will be webrole0,
webrole1, and webrole2. You do not need to specify a host name for virtual machines in the configuration file,
because the host name for a virtual machine is populated based on the virtual machine name. For more information
about configuring a Microsoft Azure service, see Azure Service Configuration Schema (.cscfg File)
Viewing hostnames
You can view the host names of virtual machines and role instances in a cloud service by using any of the tools
below.
Azure Portal
You can use the Azure portal to view the host names for virtual machines on the overview blade for a virtual
machine. Keep in mind that the blade shows a value for Name and Host Name. Although they are initially the
same, changing the host name will not change the name of the virtual machine or role instance.
Role instances can also be viewed in the Azure portal, but when you list the instances in a cloud service, the host
name is not displayed. You will see a name for each instance, but that name does not represent the host name.
Service configuration file
You can download the service configuration file for a deployed service from the Configure blade of the service in
the Azure portal. You can then look for the vmName attribute for the Role name element to see the host name.
Keep in mind that this host name is used as a base for the host name of each role instance. For example, if
vmName is webrole and there are three instances of that role, the host names of the instances will be webrole0,
webrole1, and webrole2.
Remote Desktop
After you enable Remote Desktop (Windows), Windows PowerShell remoting (Windows), or SSH (Linux and
Windows) connections to your virtual machines or role instances, you can view the host name from an active
Remote Desktop connection in various ways:
Type hostname at the command prompt or SSH terminal.
Type ipconfig /all at the command prompt (Windows only).
View the computer name in the system settings (Windows only).
Azure Service Management REST API
From a REST client, follow these instructions:
1. Ensure that you have a client certificate to connect to the Azure portal. To obtain a client certificate, follow the
steps presented in How to: Download and Import Publish Settings and Subscription Information.
2. Set a header entry named x-ms-version with a value of 2013-11-01.
3. Send a request in the following format: https://management.core.windows.net/<subscrition-
id>/services/hostedservices/<service-name>?embed-detail=true
4. Look for the HostName element for each RoleInstance element.
WARNING
You can also view the internal domain suffix for your cloud service from the REST call response by checking the
InternalDnsSuffix element, or by running ipconfig /all from a command prompt in a Remote Desktop session (Windows), or
by running cat /etc/resolv.conf from an SSH terminal (Linux).
Modifying a hostname
You can modify the host name for any virtual machine or role instance by uploading a modified service
configuration file, or by renaming the computer from a Remote Desktop session.
Next steps
Name Resolution (DNS)
Azure Service Configuration Schema (.cscfg)
Azure Virtual Network Configuration Schema
Specify DNS settings using network configuration files
How to set up endpoints on a classic Windows virtual
machine in Azure
6/27/2017 4 min to read Edit Online
All Windows virtual machines that you create in Azure using the classic deployment model can automatically
communicate over a private network channel with other virtual machines in the same cloud service or virtual
network. However, computers on the Internet or other virtual networks require endpoints to direct the inbound
network traffic to a virtual machine. This article is also available for Linux virtual machines.
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and Classic. This
article covers using the Classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager model.
In the Resource Manager deployment model, endpoints are configured using Network Security Groups (NSGs).
For more information, see Allow external access to your VM using the Azure portal.
When you create a Windows virtual machine in the Azure portal, common endpoints like those for Remote
Desktop and Windows PowerShell Remoting are typically created for you automatically. You can configure
additional endpoints while creating the virtual machine or afterwards as needed.
Each endpoint has a public port and a private port:
The public port is used by the Azure load balancer to listen for incoming traffic to the virtual machine from the
Internet.
The private port is used by the virtual machine to listen for incoming traffic, typically destined to an application
or service running on the virtual machine.
Default values for the IP protocol and TCP or UDP ports for well-known network protocols are provided when you
create endpoints with the Azure portal. For custom endpoints, you'll need to specify the correct IP protocol (TCP or
UDP) and the public and private ports. To distribute incoming traffic randomly across multiple virtual machines,
you'll need to create a load-balanced set consisting of multiple endpoints.
After you create an endpoint, you can use an access control list (ACL) to define rules that permit or deny the
incoming traffic to the public port of the endpoint based on its source IP address. However, if the virtual machine is
in an Azure virtual network, you should use network security groups instead. For details, see About network
security groups.
NOTE
Firewall configuration for Azure virtual machines is done automatically for ports associated with remote connectivity
endpoints that Azure sets up automatically. For ports specified for all other endpoints, no configuration is done automatically
to the firewall of the virtual machine. When you create an endpoint for the virtual machine, you'll need to ensure that the
firewall of the virtual machine also allows the traffic for the protocol and private port corresponding to the endpoint
configuration. To configure the firewall, see the documentation or on-line help for the operating system running on the
virtual machine.
Create an endpoint
1. If you haven't already done so, sign in to the Azure portal.
2. Click Virtual Machines, and then click the name of the virtual machine that you want to configure.
3. Click Endpoints in the Settings group. The Endpoints page lists all the current endpoints for the virtual
machine. (This example is a Windows VM. A Linux VM will by default show an endpoint for SSH.)
NOTE
If the endpoint is part of a load-balanced set, any changes you make to the ACL on an endpoint are applied to all endpoints
in the set.
If the virtual machine is in an Azure virtual network, we recommend network security groups instead of ACLs. For
details, see About network security groups.
1. If you haven't already done so, sign in to the Azure portal.
2. Click Virtual Machines, and then click the name of the virtual machine that you want to configure.
3. Click Endpoints. From the list, select the appropriate endpoint. The ACL list is at the bottom of the page.
4. Use rows in the list to add, delete, or edit rules for an ACL and change their order. The Remote Subnet
value is an IP address range for incoming traffic from the Internet that the Azure load balancer uses to
permit or deny the traffic based on its source IP address. Be sure to specify the IP address range in CIDR
format, also known as address prefix format. An example is 10.1.0.0/8 .
You can use rules to allow only traffic from specific computers corresponding to your computers on the Internet or
to deny traffic from specific, known address ranges.
The rules are evaluated in order starting with the first rule and ending with the last rule. This means that rules
should be ordered from least restrictive to most restrictive. For examples and more information, see What is a
Network Access Control List.
Next steps
To use an Azure PowerShell cmdlet to set up a VM endpoint, see Add-AzureEndpoint.
To use an Azure PowerShell cmdlet to manage an ACL on an endpoint, see Managing access control lists (ACLs)
for endpoints by using PowerShell.
If you created a virtual machine in the Resource Manager deployment model, you can use Azure PowerShell to
create network security groups to control traffic to the VM.
Manage endpoint access control lists using
PowerShell in the classic deployment model
6/27/2017 3 min to read Edit Online
You can create and manage Network Access Control Lists (ACLs) for endpoints by using Azure PowerShell or in the
Management Portal. In this topic, you'll find procedures for ACL common tasks that you can complete using
PowerShell. For the list of Azure PowerShell cmdlets see Azure Management Cmdlets. For more information about
ACLs, see What is a Network Access Control List (ACL)?. If you want to manage your ACLs by using the
Management Portal, see How to Set Up Endpoints to a Virtual Machine.
Get-Help *AzureACL*
Get-Command -Noun AzureACLConfig
Create a Network ACL with rules that permit access from a remote subnet
The example below illustrates a way to create a new ACL that contains rules. This ACL is then applied to a virtual
machine endpoint. The ACL rules in the example below will allow access from a remote subnet. To create a new
Network ACL with permit rules for a remote subnet, open an Azure PowerShell ISE. Copy and paste the script
below, configuring the script with your own values, and then run the script.
1. Create the new network ACL object.
$acl1 = New-AzureAclConfig
2. Set a rule that permits access from a remote subnet. In the example below, you set rule 100 (which has
priority over rule 200 and higher) to allow the remote subnet 10.0.0.0/8 access to the virtual machine
endpoint. Replace the values with your own configuration requirements. The name "SharePoint ACL config"
should be replaced with the friendly name that you want to call this rule.
3. For additional rules, repeat the cmdlet, replacing the values with your own configuration requirements. Be
sure to change the rule number Order to reflect the order in which you want the rules to be applied. The
lower rule number takes precedence over the higher number.
4. Next, you can either create a new endpoint (Add) or set the ACL for an existing endpoint (Set). In this
example, we will add a new virtual machine endpoint called "web" and update the virtual machine endpoint
with the ACL settings.
5. Next, combine the cmdlets and run the script. For this example, the combined cmdlets would look like this:
$acl1 = New-AzureAclConfig
Set-AzureAclConfig AddRule ACL $acl1 Order 100 `
Action permit RemoteSubnet "10.0.0.0/8" `
Description "Sharepoint ACL config"
Set-AzureAclConfig AddRule ACL $acl1 Order 200 `
Action permit RemoteSubnet "157.0.0.0/8" `
Description "web frontend ACL config"
Get-AzureVM ServiceName $serviceName Name $vmName `
|Add-AzureEndpoint Name "web" Protocol tcp Localport 80 - PublicPort 80 ACL $acl1 `
|Update-AzureVM
Remove a Network ACL rule that permits access from a remote subnet
The example below illustrates a way to remove a network ACL rule. To remove a Network ACL rule with permit
rules for a remote subnet, open an Azure PowerShell ISE. Copy and paste the script below, configuring the script
with your own values, and then run the script.
1. First step is to get the Network ACL object for the virtual machine endpoint. You'll then remove the ACL
rule. In this case, we are removing it by rule ID. This will only remove the rule ID 0 from the ACL. It does not
remove the ACL object from the virtual machine endpoint.
2. Next, you must apply the Network ACL object to the virtual machine endpoint and update the virtual
machine.
Next steps
What is a Network Access Control List (ACL)?
Create, change, or delete a virtual network
8/14/2017 14 min to read Edit Online
Learn how to create and delete a virtual network and change settings, like DNS servers and IP address spaces, for
an existing virtual network.
A virtual network is a representation of your own network in the cloud. A virtual network is a logical isolation of
the Azure cloud that is dedicated to your Azure subscription. For each virtual network that you create, you can:
Choose an address space to assign. An address space consists of one or more address ranges that are defined
by using Classless Inter-Domain Routing (CIDR) notation, like 10.0.0.0/16.
Choose to use the Azure-provided DNS server, or use your own DNS server. All resources that are connected to
the virtual network are assigned this DNS server to resolve names within the virtual network.
Segment the virtual network into subnets, each with its own address range, within the address space of the
virtual network. To learn how to create, change, and delete subnets, see Add, change, or delete subnets.
This article explains how to create, change, and delete virtual networks by using the Azure Resource Manager
deployment model.
WARNING
If a virtual network has address spaces that overlap with another virtual network or on-premises network,
the two networks cannot be connected. Before you define an address space, consider whether you might
want to connect the virtual network to other virtual networks or on-premises networks in the future.
Subnet name: The subnet name must be unique within the virtual network. You cannot change the
subnet name after the subnet is created. The portal requires that you define one subnet when you
create a virtual network, even though a virtual network isn't required to have any subnets. In the
portal, you can define only one subnet when you create a virtual network. You can add more subnets
to the virtual network later, after the virtual network is created. To add a subnet to a virtual network,
see Create a subnet in Create, change, or delete subnets. You can create a virtual network that has
multiple subnets by using Azure CLI or PowerShell.
TIP
Sometimes, admins create different subnets to filter or control traffic routing between the subnets. Before
you define subnets, consider how you might want to filter and route traffic between your subnets. To learn
more about filtering traffic between subnets, see Network security groups. Azure automatically routes traffic
between subnets, but you can override Azure default routes. To learn how to override Azure default subnet
traffic routing, see User-defined routes.
Subnet address range: The range must be within the address space you entered for the virtual
network. The smallest range you can specify is /29, which provides eight IP addresses for the subnet.
Azure reserves the first and last address in each subnet for protocol conformance. Three additional
addresses are reserved for Azure service usage. As a result, a virtual network with a subnet address
range of /29 has only three usable IP addresses. If you plan to connect a virtual network to a VPN
gateway, you must create a gateway subnet. Learn more about specific address range considerations
for gateway subnets. You can change the address range after the subnet is created, under specific
conditions. To learn how to change a subnet address range, see Change subnet settings in Add,
change, or delete subnets.
Subscription: Select a subscription. You cannot use the same virtual network in more than one Azure
subscription. However, you can connect a virtual network in one subscription to virtual networks in other
subscriptions. To connect virtual networks in different subscriptions, use Azure VPN Gateway or virtual
network peering. Any Azure resource that you connect to the virtual network must be in the same
subscription as the virtual network.
Resource group: Select an existing resource group or create a new one. An Azure resource that you
connect to the virtual network can be in the same resource group as the virtual network or in a different
resource group.
Location: Select an Azure location, also known as a region. A virtual network can be in only one Azure
location. However, you can connect a virtual network in one location to a virtual network in another
location by using a VPN gateway. Any Azure resource that you connect to the virtual network must be in
the same location as the virtual network.
Commands
TOOL COMMAND
PowerShell New-AzureRmVirtualNetwork
TOOL COMMAND
PowerShell Get-AzureRmVirtualNetwork
TOOL COMMAND
PowerShell Set-AzureRmVirtualNetwork
Add, change, or remove a DNS server
All VMs that are connected to the virtual network register with the DNS servers that you specify for the virtual
network. They also use the specified DNS server for name resolution. Each network interface (NIC) in a VM can
have its own DNS server settings. If a NIC has its own DNS server settings, they override the DNS server settings
for the virtual network. To learn more about NIC DNS settings, see Network interface tasks and settings. To learn
more about name resolution for VMs and role instances in Azure Cloud Services, see Name resolution for VMs and
role instances. To add, change, or remove a DNS server:
1. Sign in to the portal with an account that is assigned permissions for the Network Contributor role (at a
minimum) for your subscription. To learn more about assigning roles and permissions to accounts, see Built-in
roles for Azure role-based access control.
2. In the portal search box, type virtual networks. In the search results, select Virtual networks.
3. On the Virtual networks blade, click the virtual network you want to change DNS settings for.
4. On the virtual network blade, under SETTINGS, click DNS servers.
5. Select one of the following options on the blade that lists DNS servers:
Default (Azure-provided): All resource names and private IP addresses are automatically registered to
the Azure DNS servers. You can resolve names between any resources that are connected to the same
virtual network. You cannot use this option to resolve names across virtual networks. To resolve names
across virtual networks, you must use a custom DNS server.
Custom: You can add one or more servers, up to the Azure limit for a virtual network. To learn more
about DNS server limits, see Azure limits. You have the following options:
Add an address: Adds the server to your virtual network DNS servers list. This option also
registers the DNS server with Azure. If you've already registered a DNS server with Azure, you can
select that DNS server in the list.
Remove an address: Next to the server that you want to remove, click X. Deleting the server
removes the server only from this virtual network list. The DNS server remains registered in
Azure for your other virtual networks to use.
Reorder DNS server addresses: It's important to verify that you list your DNS servers in the
correct order for your environment. DNS server lists are used in the order that they are specified.
They do not work as a round-robin setup. If the first DNS server in the list can be reached, the
client uses that DNS server, regardless of whether the DNS server is functioning properly.
Remove all the DNS servers that are listed, and then add them back in the order that you want.
Change an address: Highlight the DNS server in the list, and then enter the new name.
6. Click Save.
7. Restart the VMs that are connected to the virtual network, so they are assigned the new DNS server settings.
VMs continue to use their current DNS settings until they are restarted.
Commands
TOOL COMMAND
PowerShell Set-AzureRmVirtualNetwork
TOOL COMMAND
PowerShell Remove-AzureRmVirtualNetwork
Next steps
To create a VM and then connect it to a virtual network, see Create a virtual network and connect VMs.
To filter network traffic between subnets within a virtual network, see Create network security groups.
To peer a virtual network to another virtual network, see Create a virtual network peering.
To learn about options for connecting a virtual network to an on-premises network, see About VPN Gateway.
Add, change, or delete a virtual network subnet
8/1/2017 7 min to read Edit Online
Add a subnet
To add a subnet:
1. Sign in to the portal with an account that is assigned permissions for the Network Contributor role (at a
minimum) for your subscription. To learn more about assigning roles and permissions to accounts, see Built-in
roles for Azure role-based access control.
2. In the portal search box, enter virtual networks. In the search results, click Virtual networks.
3. On the Virtual networks blade, click the virtual network you want to add a subnet to.
4. On the virtual network blade, click Subnets.
5. Click +Subnet.
6. On the Add subnet blade, enter values for the following parameters:
Name: The name must be unique within the virtual network.
Address range: The range must be unique within the address space for the virtual network. The range
cannot overlap with other subnet address ranges within the virtual network. The address space must be
specified by using Classless Inter-Domain Routing (CIDR) notation. For example, in a virtual network
with address space 10.0.0.0/16, you might define a subnet address space of 10.0.0.0/24. The smallest
range you can specify is /29, which provides eight IP addresses for the subnet. Azure reserves the first
and last address in each subnet for protocol conformance. Three additional addresses are reserved for
Azure service usage. As a result, defining a subnet with a /29 address range results in three usable IP
addresses in the subnet. If you plan to connect a virtual network to a VPN gateway, you must create a
gateway subnet. Learn more about specific address range considerations for gateway subnets. You can
change the address range after the subnet is added, under specific conditions. To learn how to change a
subnet address range, see Change subnet settings in this article.
Network security group: Optionally, you can associate an existing network security group with the
subnet to control inbound and outbound network traffic filtering for the subnet. The network security
group must exist in the same subscription and location as the virtual network. It also must be created by
using the Resource Manager deployment model. To learn more about how to create a network security
group, see Network security groups.
Route table: Optionally, you can associate an existing route table with the subnet to control network
traffic routing to other networks. The route table must exist in the same subscription and location as the
virtual network. It also must be created by using the Resource Manager deployment model. To learn
more about how to create route tables, see User-defined routes.
Users: You can control access to the subnet by using built-in roles or your own custom roles. To learn
more about assigning roles and users to access the subnet, see Use role assignment to manage access
to your Azure resources.
7. To add the subnet to the virtual network that you selected, click OK.
Commands
TOOL COMMAND
TOOL COMMAND
PowerShell Set-AzureRmVirtualNetworkSubnetConfig
Delete a subnet
You can delete a subnet only if there are no resources in the subnet. If there are resources in the subnet, you must
delete the resources that are in the subnet before you can delete the subnet. The steps you take to delete a
resource vary depending on the resource. To learn how to delete resources that are in subnets, read the
documentation for each resource type that you want to delete. To delete a subnet:
1. Sign in to the portal with an account that is assigned permissions for the Network Contributor role (at a
minimum) for your subscription. To learn more about assigning roles and permissions to accounts, see Built-in
roles for Azure role-based access control.
2. In the portal search box, enter virtual networks. In the search results, click Virtual networks.
3. On the Virtual networks blade, click the virtual network you want to delete a subnet from.
4. On the virtual network blade, under SETTINGS, click Subnets.
5. In the list of subnets that appears on the subnets blade, right-click the subnet you want to delete, click Delete,
and then click Yes to delete the subnet.
Commands
TOOL COMMAND
PowerShell Remove-AzureRmVirtualNetworkSubnetConfig
Next steps
To create a virtual machine in a subnet, see Create a virtual network and deploy VMs in the subnet.
Create, change, or delete a virtual network peering
8/16/2017 14 min to read Edit Online
Learn how to create, change, or delete a virtual network peering. Virtual network peering enables you to connect
two virtual networks in the same Azure location through the Azure backbone network. Once peered, the two virtual
networks are still managed as separate resources. Resources in either virtual network communicate with the same
latency and bandwidth as if the resources were in the same virtual network. If you're not familiar with virtual
network peering, we recommend reading the Virtual network peering overview and completing the Create a virtual
network peering tutorial, before completing the tasks in this article.
Create a peering
NOTE
There are several requirements, constraints, and considerations to successfully create a virtual network peering. Before
creating a peering, ensure you've familiarized yourself with the requirements and constraints and required permissions.
1. Log in to the portal with an account that is assigned the necessary role or permissions.
2. In the box that contains the text Search resources at the top of the Azure portal, type virtual networks. When
Virtual networks appears in the search results, click it. Do not select Virtual networks (classic) if it appears in
the list, as you cannot create a peering from a virtual network deployed through the classic deployment model.
3. In the Virtual networks blade that appears, click the virtual network you want to create a peering for.
4. In the pane that appears for the virtual network you selected, click Peerings in the SETTINGS section.
5. Click + Add.
6. In the Add peering blade, enter or select values for the following settings:
Name: The name for the peering must be unique within the virtual network.
Virtual network deployment model: Select which deployment model the virtual network you want to
peer with was deployed through.
I know my resource ID: If you have read access to the virtual network you want to peer with, leave this
checkbox unchecked. If you don't have read access to the virtual network or subscription you want to
peer with, check this box. Enter the full resource ID of the virtual network you want to peer with in the
Resource ID box that appeared when you checked the box. The resource ID you enter must be for a
virtual network that exists in the same Azure location as this virtual network. The full resource ID looks
similar to /subscriptions//resourceGroups//providers/Microsoft.Network/virtualNetworks/. You can get
the resource ID for a virtual network by viewing the properties for a virtual network. To learn how to view
the properties for a virtual network, see Manage virtual networks.
Subscription: Select the subscription of the virtual network you want to peer with. One or more
subscriptions are listed, depending on how many subscriptions your account has read access to. If you
checked the Resource ID checkbox, this setting isn't available. You can peer virtual networks in different
subscriptions as long as both virtual networks were created through Resource Manager. The ability to
peer across subscriptions created through different deployment models is in preview release. Register for
the preview before creating a peering between virtual networks deployed through different deployment
models that exist in different subscriptions. Learn more about how to register for the preview and peer
virtual networks created through different deployment models in different subscriptions.
Virtual network: Select the virtual network you want to peer with. You can select a virtual network
created through either Azure deployment model, but the virtual network must be in the same location as
the virtual network you're initiating the peering from. You must have read access to the virtual network
for it to be visible in the list. If a virtual network is listed, but grayed out, it may be because the address
space for the virtual network overlaps with the address space for this virtual network. If virtual network
address spaces overlap, they cannot be peered. If you checked the Resource ID checkbox, this setting
isn't available.
Allow virtual network access: Select Enabled (default) if you want to enable communication between
the two virtual networks. Enabling communication between virtual networks allows resources connected
to either virtual network to communicate with each other with the same bandwidth and latency as if they
were connected to the same virtual network. All communication between resources in the two virtual
networks is over the Azure private network. The VirtualNetwork default tag for network security groups
encompasses the virtual network and peered virtual network. To learn more about network security
group default tags, read the Network security groups overview article. Select Disabled if you don't want
traffic to flow to the peered virtual network. You might select Disabled if you've peered a virtual network
with another virtual network, but occasionally want to disable traffic flow between the two virtual
networks. You may find enabling/disabling is more convenient than deleting and re-creating peerings.
When this setting is disabled, traffic doesn't flow between the peered virtual networks.
Allow forwarded traffic: Check this box to allow traffic forwarded to the peered virtual network (traffic
not originating in the peered virtual network) to flow to this virtual network. Traffic forwarding is
common when you've deployed a network virtual appliance in the virtual network you're peering with
and created user-defined routes to forward traffic through the network virtual appliance. If you leave this
box unchecked (default), traffic forwarded from the peered virtual network cannot flow to this virtual
network. While enabling this capability allows the forwarded traffic through the peering, it does not
create any user-defined routes or network virtual appliances. User-defined routes and network virtual
appliances are created separately. Learn about user-defined routes.
Allow gateway transit: Check this box if you have a virtual network gateway attached to this virtual
network and want to allow traffic from the peered virtual network to flow through the gateway. For
example, this virtual network may be attached to an on-premises network through a virtual network
gateway. Checking this box allows traffic from the peered virtual network to flow through the
gateway attached to this virtual network. If you check this box, the peered virtual network cannot have
a gateway configured. The peered virtual network must have the Use remote gateway checkbox
checked when setting up the peering from the other virtual network to this virtual network. If you
leave this box unchecked (default), traffic from the peered virtual network still flows to this virtual
network, but cannot flow through a virtual network gateway attached to this virtual network. Learn
more about virtual network gateways.
You cannot enable this option if you're peering a virtual network (Resource Manager) with a virtual
network (classic). Though the traffic flows between the two virtual networks, the virtual network
(classic) traffic cannot flow through a network gateway attached to the virtual network (Resource
Manager).
Use remote gateways: Check this box to allow traffic from this virtual network to flow through a
virtual network gateway attached to the virtual network you're peering with. For example, the virtual
network you're peering with has a VPN gateway attached that enables communication to an on-
premises network. Checking this box allows traffic from this virtual network to flow through the VPN
gateway attached to the peered virtual network. If you check this box, the peered virtual network must
have a virtual network gateway attached to it and must have the Allow gateway transit checkbox
checked. If you leave this box unchecked (default), traffic from the peered virtual network can still flow
to this virtual network, but cannot flow through a virtual network gateway attached to this virtual
network.
You cannot enable this option if you're peering a virtual network (Resource Manager) with a virtual
network (classic). Though the traffic flows between the two virtual networks, the virtual network
(Resource Manager) traffic cannot flow through a network gateway attached to the virtual network
(classic).
7. Click the OK button to add the subnet to the virtual network you selected.
Commands
TOOL COMMAND
PowerShell Add-AzureRmVirtualNetworkPeering
Scenarios
A virtual network peering is created between virtual networks created through the same, or different deployment
models that exist in the same, or different subscriptions. Complete a step-by-step tutorial for one of the following
scenarios:
Different
Different
NOTE
There are several requirements, constraints, and considerations to successfully create a virtual network peering. Before
creating a peering, ensure you've familiarized yourself with the requirements and constraints and required
permissions.
7. Click Save.
Commands
TOOL COMMAND
Delete a peering
When a peering is deleted, traffic from a virtual network no longer flows to the peered virtual network. When
virtual networks deployed through Resource Manager are peered, each virtual network has a peering to the other
virtual network. Though deleting the peering from one virtual network disables the communication between the
virtual networks, it does not delete the peering from the other virtual network. The peering status for the peering
that exists in the other virtual network is Disconnected. You cannot recreate the peering until you re-create the
peering in the first virtual network and the peering status for both virtual networks changes to Connected.
If you want virtual networks to communicate sometimes, but not always, rather than deleting a peering, you can set
the Allow virtual network access setting to Disabled instead. To learn how, read step 6 of the Create a peering
section of this article. You may find disabling and enabling network access easier than deleting and recreating
peerings.
1. Log in to the portal with an account that is assigned the necessary role or permissions.
2. In the box that contains the text Search resources at the top of the Azure portal, type virtual networks. When
Virtual networks appears in the search results, click it.
3. In the Virtual networks blade that appears, click the virtual network you want to delete a peering from.
4. In the blade that appears for the virtual network you selected, click Peerings under Settings.
5. In the list of peerings that appears in the peerings blade, right-click the peering you want to delete, click Delete,
then Yes to delete the peering from the first virtual network.
6. Complete the previous steps to delete the peering from the other virtual network in the peering.
Commands
TOOL COMMAND
PowerShell Remove-AzureRmVirtualNetworkPeering
Requirements and constraints
The virtual networks you peer must have non-overlapping IP address spaces.
You can't add address spaces to, or delete address spaces from a virtual network once a virtual network is
peered with another virtual network. To add or remove address spaces, delete the peering, add or remove the
address spaces, then re-create the peering. To add address spaces to, or remove address spaces from virtual
networks, read the Create, change, or delete virtual networks article.
You can peer two virtual networks deployed through Resource Manager or a virtual network deployed through
Resource Manager with a virtual network deployed through the classic deployment model. You cannot peer two
virtual networks created through the classic deployment model. If you're not familiar with Azure deployment
models, read the Understand Azure deployment models article. You can use a VPN Gateway to connect two
virtual networks created through the classic deployment model.
When peering two virtual networks created through Resource Manager, a peering must be configured for each
virtual network in the peering. When you create the peering to the second virtual network from the first virtual
network, the peering status is Initiated. When you create the peering from the second virtual network to the first
virtual network, its peering status is Connected. If you view the peering status for the first virtual network, you
see its status changed from Initiated to Connected. The peering is not successfully established until the peering
status for both virtual network peerings is Connected.
When peering a virtual network created through Resource Manager with a virtual network created through the
classic deployment model, you only configure a peering for the virtual network deployed through Resource
Manager. You cannot configure peering for a virtual network (classic), or between two virtual networks
deployed through the classic deployment model. When you create the peering from the virtual network
(Resource Manager) to the virtual network (Classic), the peering status is Updating, then shortly changes to
Connected.
A peering is established between two virtual networks. Peerings are not transitive. If you create peerings
between:
VirtualNetwork1 & VirtualNetwork2
VirtualNetwork2 & VirtualNetwork3
There is no peering between VirtualNetwork1 and VirtualNetwork3 through VirtualNetwork2. If you want to
create a virtual network peering between VirtualNetwork1 and VirtualNetwork3, you have to create a
peering between VirtualNetwork1 and VirtualNetwork3.
You can't resolve names in peered virtual networks using default Azure name resolution. To resolve names in
other virtual networks, you must use a custom DNS server. To learn how to set up your own DNS server, read
the Name resolution using your own DNS server article.
Resources in both virtual networks in the peering can communicate with each other with the same bandwidth
and latency as if they were in the same virtual network. Each virtual machine size has its own maximum network
bandwidth however. To learn more about maximum network bandwidth for different virtual machine sizes, read
the Windows or Linux virtual machine sizes articles.
You can peer virtual networks deployed through Resource Manager that are in the same, or different
subscriptions.
You can peer virtual networks deployed through different deployment models that are in the same, or different
subscriptions (preview).
The subscriptions that both virtual networks are in must be associated to the same Azure Active Directory
tenant. If you don't already have an AD tenant, you can quickly create one. You can use a VPN Gateway to
connect two virtual networks that exist in different subscriptions associated to different Active Directory tenants.
A virtual network can be peered to another virtual network, and also be connected to another virtual network
with an Azure virtual network gateway. When virtual networks are connected through both peering and a
gateway, traffic between the virtual networks flows through the peering configuration, rather than the gateway.
There is a nominal charge for ingress and egress traffic that utilizes a virtual network peering. For more
information, see the pricing page.
Permissions
The accounts you use to create a virtual network peering must have the necessary role or permissions. For example,
if you were peering two virtual networks named myVnetA and myVnetB, your account must be assigned the
following minimum role or permissions for each virtual network:
Learn more about built-in roles and assigning specific permissions to custom roles (Resource Manager only).
Next steps
Learn how to create a hub and spoke network topology
Configure a virtual network (classic) using a network
configuration file
7/10/2017 4 min to read Edit Online
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager deployment model.
You can create and configure a virtual network (classic) with a network configuration file using the Azure
command-line interface (CLI) 1.0 or Azure PowerShell. You cannot create or modify a virtual network through the
Azure Resource Manager deployment model using a network configuration file. You cannot use the Azure portal
to create or modify a virtual network (classic) using a network configuration file, however you can use the Azure
portal to create a virtual network (classic), without using a network configuration file.
Creating and configuring a virtual network (classic) with a network configuration file requires exporting, changing,
and importing the file.
IMPORTANT
Azure considers a subnet that has something deployed to it as in use. When a subnet is in use, it cannot be modified.
Before modifying subnet information in a network configuration file, move anything that you have deployed to the subnet
to a different subnet that isn't being modified. See Move a VM or Role Instance to a Different Subnet for details.
If the network configuration file you exported contains no contents, you can copy the XML in the previous
example, and paste it into a new file.
Example JSON for use with the Azure CLI 1.0
The following example network configuration file creates a virtual network named myVirtualNetwork with an
address space of 10.0.0.0/16 in the East US Azure region. The virtual network contains one subnet named
mySubnet with an address prefix of 10.0.0.0/24.
{
"VirtualNetworkConfiguration" : {
"Dns" : "",
"VirtualNetworkSites" : [
{
"AddressSpace" : [ "10.0.0.0/16" ],
"Location" : "East US",
"Name" : "myVirtualNetwork",
"Subnets" : [
{
"AddressPrefix" : "10.0.0.0/24",
"Name" : "mySubnet"
}
]
}
]
}
}
If the network configuration file you exported contains no contents, you can copy the json in the previous
example, and paste it into a new file.
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager deployment model.
Affinity groups ensure that resources created within the same affinity group are physically hosted by servers that
are close together, enabling these resources to communicate quicker. In the past, affinity groups were a
requirement for creating virtual networks (classic). At that time, the network manager service that managed virtual
networks (classic) could only work within a set of physical servers or scale unit. Architectural improvements have
increased the scope of network management to a region.
As a result of these architectural improvements, affinity groups are no longer recommended, or required for virtual
networks (classic). The use of affinity groups for virtual networks (classic) is replaced by regions. Virtual networks
(classic) that are associated with regions are called regional virtual networks.
We recommend that you don't use affinity groups in general. Aside from the virtual network requirement, affinity
groups were also important to use to ensure resources, such as compute (classic) and storage (classic), were placed
near each other. However, with the current Azure network architecture, these placement requirements are no
longer necessary.
IMPORTANT
Although it is still technically possible to create a virtual network that is associated with an affinity group, there is no
compelling reason to do so. Many virtual network features, such as network security groups, are only available when using a
regional virtual network, and are not available for virtual networks that are associated with affinity groups.
NOTE
The Location is the region that you specified for the affinity group that is associated with your virtual network
(classic). For example, if your virtual network (classic) is associated with an affinity group that is located in West US,
when you migrate, your Location must point to West US.
Edit the following lines in your network configuration file, replacing the values with your own:
Old value: <VirtualNetworkSitename="VNetUSWest" AffinityGroup="VNetDemoAG">
New value: <VirtualNetworkSitename="VNetUSWest" Location="West US">
3. Save your changes and import the network configuration to Azure.
NOTE
This migration does NOT cause any downtime to your services.
After you create one or more Network Security Groups (NSGs), you need to be able to retrieve information about
your NSGs, add and remove rules, edit existing rules, associate or dissociate NSGs, and delete NSGs. In this article,
you will learn how to execute each of these tasks. Before you can manage NSGs, it's important to know how NSGs
work.
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the Resource Manager deployment model, which Microsoft recommends for most new deployments
instead of the classic deployment model.
Sample Scenario
To better illustrate how to manage NSGs, this article uses the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL traffic from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
To deploy the scenario described above, follow this link, click Deploy to Azure, replace the default parameter
values if necessary, and follow the instructions in the portal. In the sample instructions below, the template was
used to deploy a resource group names RG-NSG.
Retrieve Information
You can view your existing NSGs, retrieve rules for an existing NSG, and find out what resources an NSG is
associated to.
View existing NSGs
To view all existing NSGs in a subscription, complete the following steps:
1. From a browser, navigate to http://portal.azure.com and, if necessary, sign in with your Azure account.
2. Click Browse > > Network security groups.
2. In the list of resources, look for items displaying the NSG icon, as shown in the Resources blade below.
List all rules for an NSG
To view the rules of an NSG named NSG-FrontEnd, complete the following steps:
1. From the Network security groups blade, or the Resources blade shown above, click NSG-FrontEnd.
2. In the Settings tab, click Inbound security rules.
NOTE
To view default rules, click the Default rules icon at the top of the blade that displays the rules.
3. In the Settings tab, click Network interfaces to view what NICs are associated to the NSG.
Manage rules
You can add rules to an existing NSG, edit existing rules, and remove rules.
Add a rule
To add a rule allowing inbound traffic to port 443 from any machine to the NSG-FrontEnd NSG, complete the
following steps:
1. From the Network security groups blade, or the Resources blade shown above, click NSG-FrontEnd.
2. In the Settings tab, click Inbound security rules.
3. In the Inbound security rules blade, click Add. Then, in the Add inbound security rule blade, fill the
values as shown below, and then click OK.
After a few seconds, notice the new rule in the Inbound security rules blade.
Change a rule
To change the rule created above to allow inbound traffic from the Internet only, complete the following steps:
1. From the Network security groups blade, or the Resources blade shown above, click NSG-FrontEnd.
2. In the Settings tab, click the rule created above.
3. In the allow-https blade, change the Source property as shown below, and then click Save.
Delete a rule
To delete the rule created above, complete the following steps:
1. From the Network security groups blade, or the Resources blade shown above, click NSG-FrontEnd.
2. In the Settings tab, click the rule created above.
3. In the allow-https blade, click Delete, and then click Yes.
Manage associations
You can associate an NSG to subnets and NICs. You can also dissociate an NSG from any resource it's associated
to.
Associate an NSG to a NIC
To associate the NSG-FrontEnd NSG to the TestNICWeb1 NIC, complete the following steps:
1. From the Network security groups blade, or the Resources blade shown above, click NSG-FrontEnd.
2. In the Settings tab, click Network interfaces > Associate > TestNICWeb1.
NOTE
You can also use this blade to associate the NIC to any existing NSG.
NOTE
You can also associate an NSG to a subnet from thh NSG's Settings blade.
Delete an NSG
You can only delete an NSG if it's not associated to any resource. To delete an NSG, complete the following steps:.
1. From the Azure portal, click Resource groups > > RG-NSG > ... > NSG-FrontEnd.
2. In the Settings blade, click Network interfaces.
3. If there are any NICs listed, click the NIC, and follow step 2 in Dissociate an NSG from a NIC.
4. Repeat step 3 for each NIC.
5. In the Settings blade, click Subnets.
6. If there are any subnets listed, click the subnet and follow steps 2 and 3 in Dissociate an NSG from a subnet.
7. Scrolls left to the NSG-FrontEnd blade, then click Delete > Yes.
Next steps
Enable logging for NSGs.
Manage network security groups using PowerShell
6/27/2017 8 min to read Edit Online
After you create one or more Network Security Groups (NSGs), you need to be able to retrieve information about
your NSGs, add and remove rules, edit existing rules, associate or dissociate NSGs, and delete NSGs. In this article,
you will learn how to execute each of these tasks. Before you can manage NSGs, it's important to know how NSGs
work.
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the Resource Manager deployment model, which Microsoft recommends for most new deployments
instead of the classic deployment model.
Sample Scenario
To better illustrate how to manage NSGs, this article uses the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL traffic from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
To deploy the scenario described above, follow this link, click Deploy to Azure, replace the default parameter
values if necessary, and follow the instructions in the portal. In the sample instructions below, the template was
used to deploy a resource group names RG-NSG.
NOTE
If you don't have an Azure account, you'll need one. Go sign up for a free trial here.
Retrieve Information
You can view your existing NSGs, retrieve rules for an existing NSG, and find out what resources an NSG is
associated to.
View existing NSGs
To view all existing NSGs in a subscription, run the Get-AzureRmNetworkSecurityGroup cmdlet.
Expected result:
Name :NSG-BackEnd
ResourceGroupName :RG-NSG
Location :westus
Id :/subscriptions/[Subscription Id]/resourceGroups/RG-NSG/providers/
Microsoft.Network/networkSecurityGroups/NSG-BackEnd
Etag : W/"[Id]"
ResourceGuid : [Id]
ProvisioningState : Succeeded
Tags :
SecurityRules : [...]
DefaultSecurityRules : [...]
NetworkInterfaces : [...]
Subnets : [...]
Name :NSG-FrontEnd
ResourceGroupName :RG-NSG
Location :eastus
Id :/subscriptions/[Subscription Id]/resourceGroups/NRP-RG/providers/
Microsoft.Network/networkSecurityGroups/NSG-FrontEnd
Etag : W/"[Id]"
ResourceGuid : [Id]
ProvisioningState : Succeeded
Tags :
SecurityRules : [...]
DefaultSecurityRules : [...]
NetworkInterfaces : [...]
Subnets : [...]
Name :WEB1
ResourceGroupName :RG101
Location :eastus2
Id :/subscriptions/[Subscription Id]/resourceGroups/RG101/providers/M
icrosoft.Network/networkSecurityGroups/WEB1
Etag : W/"[Id]"
ResourceGuid : [Id]
ProvisioningState : Succeeded
Tags :
SecurityRules : [...]
DefaultSecurityRules : [...]
NetworkInterfaces : [...]
Subnets : [...]
To view the list of NSGs in a specific resource group, run the Get-AzureRmNetworkSecurityGroup cmdlet.
Expected output:
Name : NSG-BackEnd
ResourceGroupName : RG-NSG
Location : westus
Id : /subscriptions/[Subscription Id]/resourceGroups/RG-NSG/providers/
Microsoft.Network/networkSecurityGroups/NSG-BackEnd
Etag : W/"[Id]"
ResourceGuid : [Id]
ProvisioningState : Succeeded
Tags :
SecurityRules : [...]
DefaultSecurityRules : [...]
NetworkInterfaces : [...]
Subnets : [...]
Name : NSG-FrontEnd
ResourceGroupName : RG-NSG
Location : eastus
Id : /subscriptions/[Subscription Id]/resourceGroups/NRP-RG/providers/
Microsoft.Network/networkSecurityGroups/NSG-FrontEnd
Etag : W/"[Id]"
ResourceGuid : [Id]
ProvisioningState : Succeeded
Tags :
SecurityRules : [...]
DefaultSecurityRules : [...]
NetworkInterfaces : [...]
Subnets : [...]
Expected output:
Name : rdp-rule
Id : /subscriptions/[Subscription Id]/resourceGroups/RG-NSG/providers/
Microsoft.Network/networkSecurityGroups/NSG-FrontEnd/securityRules/rdp-rule
Etag : W/"[Id]"
ProvisioningState : Succeeded
Description : Allow RDP
Protocol : Tcp
SourcePortRange : *
DestinationPortRange : 3389
SourceAddressPrefix : Internet
DestinationAddressPrefix : *
Access : Allow
Priority : 100
Direction : Inbound
Name : web-rule
Id : /subscriptions/[Subscription Id]/resourceGroups/RG-NSG/providers/
Microsoft.Network/networkSecurityGroups/NSG-FrontEnd/securityRules/web-rule
Etag : W/"[Id]"
ProvisioningState : Succeeded
Description : Allow HTTP
Protocol : Tcp
SourcePortRange : *
DestinationPortRange : 80
SourceAddressPrefix : Internet
DestinationAddressPrefix : *
Access : Allow
Priority : 101
Direction : Inbound
NOTE
You can also use
Get-AzureRmNetworkSecurityGroup -ResourceGroupName RG-NSG -Name "NSG-FrontEnd" | Select
DefaultSecurityRules -ExpandProperty DefaultSecurityRules
to list the default rules from the NSG-FrontEnd NSG.
NetworkInterfaces : []
Subnets : [
{
"Id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/RG-
NSG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontEnd",
"IpConfigurations": []
}
]
In the previous example, the NSG is not associated to any network interfaces (NICs); it is associated to a subnet
named FrontEnd.
Manage rules
You can add rules to an existing NSG, edit existing rules, and remove rules.
Add a rule
To add a rule allowing inbound traffic to port 443 from any machine to the NSG-FrontEnd NSG, complete the
following steps:
1. Run the following command to retrieve the existing NSG and store it in a variable:
3. To save the changes made to the NSG, run the following command:
Name : NSG-FrontEnd
...
SecurityRules : [
{
"Name": "rdp-rule",
...
},
{
"Name": "web-rule",
...
},
{
"Name": "https-rule",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/[Subscription Id]/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkSecurityGroups/NSG-FrontEnd/securityRules/https-rule",
"Description": "Allow HTTPS",
"Protocol": "Tcp",
"SourcePortRange": "*",
"DestinationPortRange": "443",
"SourceAddressPrefix": "*",
"DestinationAddressPrefix": "*",
"Access": "Allow",
"Priority": 102,
"Direction": "Inbound",
"ProvisioningState": "Succeeded"
}
]
Change a rule
To change the rule created above to allow inbound traffic from the Internet only, follow the steps below.
1. Run the following command to retrieve the existing NSG and store it in a variable:
3. To save the changes made to the NSG, run the following command:
Name : NSG-FrontEnd
...
SecurityRules : [
{
"Name": "rdp-rule",
...
},
{
"Name": "web-rule",
...
},
{
"Name": "https-rule",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/[Subscription Id]/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkSecurityGroups/NSG-FrontEnd/securityRules/https-rule",
"Description": "Allow HTTPS",
"Protocol": "Tcp",
"SourcePortRange": "*",
"DestinationPortRange": "443",
"SourceAddressPrefix": "Internet",
"DestinationAddressPrefix": "*",
"Access": "Allow",
"Priority": 102,
"Direction": "Inbound",
"ProvisioningState": "Succeeded"
}
]
Delete a rule
1. Run the following command to retrieve the existing NSG and store it in a variable:
2. Run the following command to remove the rule from the NSG:
Remove-AzureRmNetworkSecurityRuleConfig -NetworkSecurityGroup $nsg -Name https-rule
3. Save the changes made to the NSG, by running the following command:
Expected output showing only the security rules, notice the https-rule is no longer listed:
Name : NSG-FrontEnd
...
SecurityRules : [
{
"Name": "rdp-rule",
...
},
{
"Name": "web-rule",
...
}
]
Manage associations
You can associate an NSG to subnets and NICs. You can also dissociate an NSG from any resource it's associated
to.
Associate an NSG to a NIC
To associate the NSG-FrontEnd NSG to the TestNICWeb1 NIC, complete the following steps:
1. Run the following command to retrieve the existing NSG and store it in a variable:
2. Run the following command to retrieve the existing NIC and store it in a variable:
3. Set the NetworkSecurityGroup property of the NIC variable to the value of the NSG variable, by entering
the following command:
$nic.NetworkSecurityGroup = $nsg
4. To save the changes made to the NIC, run the following command:
2. Set the NetworkSecurityGroup property of the NIC variable to $null by running the following command:
$nic.NetworkSecurityGroup = $null
3. To save the changes made to the NIC, run the following command:
NetworkSecurityGroup : null
2. Run the following command to retrieve the FrontEnd subnet and store it in a variable:
3. Set the NetworkSecurityGroup property of the subnet variable to $null by entering the following
command:
$subnet.NetworkSecurityGroup = $null
4. To save the changes made to the subnet, run the following command:
Expected output showing only the properties of the FrontEnd subnet. Notice there isn't a property for
NetworkSecurityGroup:
...
Subnets : [
{
"Name": "FrontEnd",
"Etag": "W/\"[Id]\"",
"Id": "/subscriptions/[Subscription Id]/resourceGroups/RG-
NSG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontEnd",
"AddressPrefix": "192.168.1.0/24",
"IpConfigurations": [
{
"Id": "/subscriptions/[Subscription Id]/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkInterfaces/TestNICWeb2/ipConfigurations/ipconfig1"
},
{
"Id": "/subscriptions/[Subscription Id]/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkInterfaces/TestNICWeb1/ipConfigurations/ipconfig1"
}
],
"ProvisioningState": "Succeeded"
},
...
]
2. Run the following command to retrieve the FrontEnd subnet and store it in a variable:
3. Run the following command to retrieve the existing NSG and store it in a variable:
4. Set the NetworkSecurityGroup property of the subnet variable to $null by running the following
command:
$subnet.NetworkSecurityGroup = $nsg
5. To save the changes made to the subnet, run the following command:
Expected output showing only the NetworkSecurityGroup property of the FrontEnd subnet:
...
"NetworkSecurityGroup": {
"SecurityRules": [],
"DefaultSecurityRules": [],
"NetworkInterfaces": [],
"Subnets": [],
"Id": "/subscriptions/[Subscription Id]/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkSecurityGroups/NSG-FrontEnd"
}
...
Delete an NSG
You can only delete an NSG if it's not associated to any resource. To delete an NSG, follow the steps below.
1. To check the resources associated to an NSG, run the azure network nsg show as shown in View NSGs
associations.
2. If the NSG is associated to any NICs, run the azure network nic set as shown in Dissociate an NSG from a NIC
for each NIC.
3. If the NSG is associated to any subnet, run the azure network vnet subnet set as shown in Dissociate an NSG
from a subnet for each subnet.
4. To delete the NSG, run the following command:
NOTE
The -Force parameter ensures you don't need to confirm the deletion.
Next steps
Enable logging for NSGs.
Manage network security groups using the Azure CLI
2.0
6/27/2017 6 min to read Edit Online
NOTE
Azure has two different deployment models for creating and working with resources: Resource Manager and classic. This
article covers using the Resource Manager deployment model, which Microsoft recommends for most new deployments
instead of the classic deployment model.
Sample Scenario
To better illustrate how to manage NSGs, this article uses the scenario below.
In this scenario you will create an NSG for each subnet in the TestVNet virtual network, as described below:
NSG-FrontEnd. The front end NSG will be applied to the FrontEnd subnet, and contain two rules:
rdp-rule. This rule will allow RDP traffic to the FrontEnd subnet.
web-rule. This rule will allow HTTP traffic to the FrontEnd subnet.
NSG-BackEnd. The back end NSG will be applied to the BackEnd subnet, and contain two rules:
sql-rule. This rule allows SQL traffic only from the FrontEnd subnet.
web-rule. This rule denies all internet bound traffic from the BackEnd subnet.
The combination of these rules create a DMZ-like scenario, where the back end subnet can only receive incoming
traffic for SQL traffic from the front end subnet, and has no access to the Internet, while the front end subnet can
communicate with the Internet, and receive incoming HTTP requests only.
To deploy the scenario described above, follow this link, click Deploy to Azure, replace the default parameter
values if necessary, and follow the instructions in the portal. In the sample instructions below, the template was
used to deploy a resource group names RG-NSG.
Prerequisite
If you haven't yet, install and configure the latest Azure CLI 2.0 and log in to an Azure account using az login.
Expected output:
Expected output:
Name Desc Access Direction
DestPortRange DestAddrPrefix SrcPortRange SrcAddrPrefix
----------------------------- ------------------------------------------------------ -------- -----------
--------------- ---------------- -------------- -----------------
AllowVnetInBound Allow inbound traffic from all VMs in VNET Allow Inbound
* VirtualNetwork * VirtualNetwork
AllowAzureLoadBalancerInBound Allow inbound traffic from azure load balancer Allow Inbound
* * * AzureLoadBalancer
DenyAllInBound Deny all inbound traffic Deny Inbound
* * * *
AllowVnetOutBound Allow outbound traffic from all VMs to all VMs in VNET Allow Outbound
* VirtualNetwork * VirtualNetwork
AllowInternetOutBound Allow outbound traffic from all VMs to Internet Allow Outbound
* Internet * *
DenyAllOutBound Deny all outbound traffic Deny Outbound
* * * *
rdp-rule Allow Inbound
3389 * * Internet
web-rule Allow Inbound
80 * * Internet
NOTE
You can also use az network nsg rule list to list only the custom rules from an NSG .
[
[
{
"addressPrefix": null,
"etag": null,
"id": "/subscriptions/<guid>/resourceGroups/RG-
NSG/providers/Microsoft.Network/virtualNetworks/TestVNET/subnets/FrontEnd",
"ipConfigurations": null,
"name": null,
"networkSecurityGroup": null,
"provisioningState": null,
"resourceGroup": "RG-NSG",
"resourceNavigationLinks": null,
"routeTable": null
}
],
null
]
In the example above, the NSG is not associated to any network interfaces (NICs), and it is associated to a subnet
named FrontEnd.
Add a rule
To add a rule allowing inbound traffic to port 443 from any machine to the NSG-FrontEnd NSG, enter the
following command:
Expected output:
{
"access": "Allow",
"description": "Allow access to port 443 for HTTPS",
"destinationAddressPrefix": "*",
"destinationPortRange": "443",
"direction": "Inbound",
"etag": "W/\"<guid>\"",
"id": "/subscriptions/<guid>/resourceGroups/RG-NSG/providers/Microsoft.Network/networkSecurityGroups/NSG-
FrontEnd/securityRules/allow-https",
"name": "allow-https",
"priority": 102,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "RG-NSG",
"sourceAddressPrefix": "*",
"sourcePortRange": "*"
}
Change a rule
To change the rule created above to allow inbound traffic from the Internet only, run the az network nsg rule
update command:
Expected output:
{
"access": "Allow",
"description": "Allow access to port 443 for HTTPS",
"destinationAddressPrefix": "*",
"destinationPortRange": "443",
"direction": "Inbound",
"etag": "W/\"<guid>\"",
"id": "/subscriptions/<guid>/resourceGroups/RG-NSG/providers/Microsoft.Network/networkSecurityGroups/NSG-
FrontEnd/securityRules/allow-https",
"name": "allow-https",
"priority": 102,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "RG-NSG",
"sourceAddressPrefix": "Internet",
"sourcePortRange": "*"
}
Delete a rule
To delete the rule created above, run the following command:
Expected output:
{
"dnsSettings": {
"appliedDnsServers": [],
"dnsServers": [],
"internalDnsNameLabel": null,
"internalDomainNameSuffix": "k0wkaguidnqrh0ud.gx.internal.cloudapp.net",
"internalFqdn": null
},
"enableAcceleratedNetworking": false,
"enableIpForwarding": false,
"etag": "W/\"<guid>\"",
"id": "/subscriptions/<guid>/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkInterfaces/TestNICWeb1",
"ipConfigurations": [
{
"applicationGatewayBackendAddressPools": null,
"etag": "W/\"<guid>\"",
"id": "/subscriptions/<guid>/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkInterfaces/TestNICWeb1/ipConfigurations/ipconfig1",
"loadBalancerBackendAddressPools": null,
"loadBalancerInboundNatRules": null,
"name": "ipconfig1",
"primary": true,
"primary": true,
"privateIpAddress": "192.168.1.6",
"privateIpAddressVersion": "IPv4",
"privateIpAllocationMethod": "Static",
"provisioningState": "Succeeded",
"publicIpAddress": null,
"resourceGroup": "RG-NSG",
"subnet": {
"addressPrefix": null,
"etag": null,
"id": "/subscriptions/<guid>/resourceGroups/RG-
NSG/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/FrontEnd",
"ipConfigurations": null,
"name": null,
"networkSecurityGroup": null,
"provisioningState": null,
"resourceGroup": "RG-NSG",
"resourceNavigationLinks": null,
"routeTable": null
}
}
],
"location": "centralus",
"macAddress": "00-0D-3A-91-A9-60",
"name": "TestNICWeb1",
"networkSecurityGroup": {
"defaultSecurityRules": null,
"etag": null,
"id": "/subscriptions/<guid>/resourceGroups/RG-NSG/providers/Microsoft.Network/networkSecurityGroups/NSG-
FrontEnd",
"location": null,
"name": null,
"networkInterfaces": null,
"provisioningState": null,
"resourceGroup": "RG-NSG",
"resourceGuid": null,
"securityRules": null,
"subnets": null,
"tags": null,
"type": null
},
"primary": null,
"provisioningState": "Succeeded",
"resourceGroup": "RG-NSG",
"resourceGuid": "<guid>",
"tags": {},
"type": "Microsoft.Network/networkInterfaces",
"virtualMachine": null
}
In the output, the networkSecurityGroup key has something similar for the value:
"networkSecurityGroup": {
"defaultSecurityRules": null,
"etag": null,
"id": "/subscriptions/0e220bf6-5caa-4e9f-8383-51f16b6c109f/resourceGroups/RG-
NSG/providers/Microsoft.Network/networkSecurityGroups/NSG-FrontEnd",
"location": null,
"name": null,
"networkInterfaces": null,
"provisioningState": null,
"resourceGroup": "RG-NSG",
"resourceGuid": null,
"securityRules": null,
"subnets": null,
"tags": null,
"type": null
}
Delete an NSG
You can only delete an NSG if it's not associated to any resource. To delete an NSG, follow the steps below.
1. To check the resources associated to an NSG, run the azure network nsg show as shown in View NSGs
associations.
2. If the NSG is associated to any NICs, run the azure network nic set as shown in Dissociate an NSG from a NIC
for each NIC.
3. If the NSG is associated to any subnet, run the azure network vnet subnet set as shown in Dissociate an NSG
from a subnet for each subnet.
4. To delete the NSG, run the following command:
Next steps
5. Enable logging for NSGs.
Log analytics for network security groups (NSGs)
8/7/2017 3 min to read Edit Online
You can enable the following diagnostic log categories for NSGs:
Event: Contains entries for which NSG rules are applied to VMs and instance roles based on MAC address. The
status for these rules is collected every 60 seconds.
Rule counter: Contains entries for how many times each NSG rule is applied to deny or allow traffic.
NOTE
Diagnostic logs are only available for NSGs deployed through the Azure Resource Manager deployment model. You cannot
enable diagnostic logging for NSGs deployed through the classic deployment model. For a better understanding of the two
models, reference the Understanding Azure deployment models article.
Activity logging (previously known as audit or operational logs) is enabled by default for NSGs created through
either Azure deployment model. To determine which operations were completed on NSGs in the activity log, look
for entries that contain the following resource types:
Microsoft.ClassicNetwork/networkSecurityGroups
Microsoft.ClassicNetwork/networkSecurityGroups/securityRules
Microsoft.Network/networkSecurityGroups
Microsoft.Network/networkSecurityGroups/securityRules
Read the Overview of the Azure Activity Log article to learn more about activity logs.
Logged data
JSON-formatted data is written for both logs. The specific data written for each log type is listed in the following
sections:
Event log
This log contains information about which NSG rules are applied to VMs and cloud service role instances, based
on MAC address. The following example data is logged for each event:
{
"time": "[DATE-TIME]",
"systemId": "007d0441-5d6b-41f6-8bfd-930db640ec03",
"category": "NetworkSecurityGroupEvent",
"resourceId": "/SUBSCRIPTIONS/[SUBSCRIPTION-ID]/RESOURCEGROUPS/[RESOURCE-GROUP-
NAME]/PROVIDERS/MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/[NSG-NAME]",
"operationName": "NetworkSecurityGroupEvents",
"properties": {
"vnetResourceGuid":"{5E8AEC16-C728-441F-B0CA-B791E1DBC2F4}",
"subnetPrefix":"192.168.1.0/24",
"macAddress":"00-0D-3A-92-6A-7C",
"primaryIPv4Address":"192.168.1.4",
"ruleName":"UserRule_default-allow-rdp",
"direction":"In",
"priority":1000,
"type":"allow",
"conditions":{
"protocols":"6",
"destinationPortRange":"3389-3389",
"sourcePortRange":"0-65535",
"sourceIP":"0.0.0.0/0",
"destinationIP":"0.0.0.0/0"
}
}
}
Learn how to create, change settings for, and delete a network interface. A network interface enables an Azure
Virtual Machine to communicate with Internet, Azure, and on-premises resources. When creating a virtual machine
using the Azure portal, the portal creates one network interface with default settings for you. You may instead
choose to create network interfaces with custom settings and add one or more network interfaces to a virtual
machine when you create it. You may also want to change default network interface settings for an existing
network interface. This article explains how to create a network interface with custom settings, change existing
settings, such as network filter (network security group) assignment, subnet assignment, DNS server settings, and
IP forwarding, and delete a network interface.
If you need to add, change, or remove IP addresses for a network interface, read the Manage IP addresses article. If
you need to add network interfaces to, or remove network interfaces from virtual machines, read the Add or
remove network interfaces article.
IPv6 name (only appears when the Yes, if the Private IP address (IPv6) This name is assigned to a secondary
Private IP address (IPv6) checkbox checkbox is checked. IP configuration for the network
is checked) interface. Learn more about IP
configurations in the View network
interface settings section of this
article.
The portal doesn't provide the option to assign a public IP address to the network interface when you create it,
though the portal does create a public IP address and assign it to a network interface when you create a virtual
machine using the portal. To learn how to add a public IP address to the network interface after creating it, read the
Manage IP addresses article. If you want to create a network interface with a public IP address, you must use the
CLI or PowerShell to create the network interface.
NOTE
Azure assigns a MAC address to the network interface only after the network interface is attached to a virtual machine and
the virtual machine is started the first time. You cannot specify the MAC address that Azure assigns to the network interface.
The MAC address remains assigned to the network interface until the network interface is deleted or the private IP address
assigned to the primary IP configuration of the primary network interface is changed. To learn more about IP addresses and
IP configurations, read the Manage IP addresses article.
Commands
TOOL COMMAND
PowerShell New-AzureRmNetworkInterface
View network interface settings
You can view and change most settings for a network interface after it's created.
1. Log in to the Azure portal with an account that is assigned (at a minimum) permissions for the Network
Contributor role for your subscription. Read the Built-in roles for Azure role-based access control article to
learn more about assigning roles and permissions to accounts.
2. In the box that contains the text Search resources at the top of the Azure portal, type network interfaces. When
network interfaces appears in the search results, click it.
3. In the Network interfaces blade that appears, click the network interface you want to view or change settings
for.
4. The following settings are listed in the blade that appears for the network interface you selected:
Overview: Provides information about the network interface, such as the IP addresses assigned to it, the
virtual network/subnet the network interface is assigned to, and the virtual machine the network
interface is attached to (if it's attached to one). The following picture shows the overview settings for a
network interface named mywebserver256:
You can move a network interface to a different resource group or subscription by clicking (change)
next to the Resource group or Subscription name. If you move the network interface, you must move
all resources related to the network interface with it. If the network interface is attached to a virtual
machine, for example, you must also move the virtual machine, and other virtual machine-related
resources. To move a network interface, read the Move resource to a new resource group or subscription
article. The article lists prerequisites, and how to move resources using the Azure portal, PowerShell, and
the Azure CLI.
IP configurations: Public and private IPv4 and IPv6 addresses assigned to IP configurations are listed
here. If an IPv6 address is assigned to an IP configuration, the address is not displayed. Learn more about
IP configurations and how to add and remove IP addresses in the Configure IP addresses for an Azure
network interface article. IP forwarding and subnet assignment are also configured in this section. To
learn more about these settings, read the Enable or disable IP forwarding and Change subnet
assignment sections of this article.
DNS servers: You can specify which DNS server a network interface is assigned by the Azure DHCP
servers. The network interface can inherit the setting from the virtual network the network interface is
assigned to, or have a custom setting that overrides the setting for the virtual network it's assigned to. To
modify what's displayed, complete the steps in the Change DNS servers section of this article.
Network security group (NSG): Displays which NSG is associated to the network interface (if any). An
NSG contains inbound and outbound rules to filter network traffic for the network interface. If an NSG is
associated to the network interface, the name of the associated NSG is displayed. To modify what's
displayed, complete the steps in the Manage network security group associations article.
Properties: Displays key settings about the network interface, including its MAC address (blank if the
network interface isn't attached to a virtual machine), and the subscription it exists in.
Effective security rules: Security rules are listed if the network interface is attached to a running virtual
machine, and an NSG is associated to the network interface, the subnet it's assigned to, or both. To learn
more about what's displayed, read the Troubleshoot network security groups article. To learn more
about NSGs, read the Network security groups article.
Effective routes: Routes are listed if the network interface is attached to a running virtual machine. The
routes are a combination of the Azure default routes, any user-defined routes (UDR), and any BGP routes
that may exist for the subnet the network interface is assigned to. To learn more about what's displayed,
read the Troubleshoot routes article. To learn more about Azure default and UDRs, read the User-defined
routes article.
Common Azure Resource Manager settings: To learn more about common Azure Resource Manager
settings, read the Activity log, Access control (IAM), Tags, Locks, and Automation script articles.
Commands
If an IPv6 address is assigned to a network interface, the PowerShell output returns the fact that the address is
assigned, but it doesn't return the assigned address. Similarly, the CLI returns the fact that the address is assigned,
but returns null in its output for the address.
TOOL COMMAND
TOOL COMMAND
PowerShell Set-AzureRmNetworkInterface
TOOL COMMAND
PowerShell Set-AzureRmNetworkInterface
TOOL COMMAND
PowerShell Set-AzureRmNetworkInterfaceIpConfig
TOOL COMMAND
PowerShell Remove-AzureRmNetworkInterface
Next steps
To create a virtual machine with multiple network interfaces or IP addresses, read the following articles:
Commands
TASK TOOL
Create a single NIC VM with a private IPv6 address (behind CLI, PowerShell, Azure Resource Manager template
an Azure Load Balancer)
Add, change, or remove IP addresses for an Azure
network interface
8/14/2017 14 min to read Edit Online
Learn how to add, change, and remove public and private IP addresses for a network interface. Private IP
addresses assigned to a network interface enable a virtual machine to communicate with other resources in an
Azure virtual network and connected networks. A private IP address also enables outbound communication to
the Internet using an unpredictable IP address. A Public IP address assigned to a network interface enables
inbound communication to a virtual machine from the Internet. The address also enables outbound
communication from the virtual machine to the Internet using a predictable IP address. For details, see
Understanding outbound connections in Azure.
If you need to create, change, or delete a network interface, read the Manage a network interface article. If you
need to add network interfaces to or remove network interfaces from a virtual machine, read the Add or remove
network interfaces article.
Add IP addresses
You can add as many private and public IPv4 addresses as necessary to a network interface, within the limits
listed in the Azure limits article. You cannot use the portal to add an IPv6 address to an existing network
interface (though you can use the portal to add a private IPv6 address to a network interface when you create
the network interface). You can use PowerShell or the CLI to add a private IPv6 address to one secondary IP
configuration (as long as there are no existing secondary IP configurations) for an existing network interface that
is not attached to a virtual machine. You cannot use any tool to add a public IPv6 address to a network interface.
See IPv6 for details about using IPv6 addresses.
1. Log in to the Azure portal with an account that is assigned (at a minimum) permissions for the Network
Contributor role for your subscription. Read the Built-in roles for Azure role-based access control article to
learn more about assigning roles and permissions to accounts.
2. In the box that contains the text Search resources at the top of the Azure portal, type network interfaces.
When network interfaces appears in the search results, click it.
3. In the Network interfaces blade that appears, click the network interface you want to add an IPv4 address
for.
4. Click IP configurations in the SETTINGS section of the blade for the network interface you selected.
5. Click + Add in the blade that opens for IP configurations.
6. Specify the following, then click OK to close the Add IP configuration blade:
7. Manually add secondary private IP addresses to the virtual machine operating system by completing the
instructions in the Assign multiple IP addresses to virtual machine operating systems article. See private IP
addresses for special considerations before manually adding IP addresses to a virtual machine operating
system. Do not add any public IP addresses to the virtual machine operating system.
Commands
TOOL COMMAND
PowerShell Add-AzureRmNetworkInterfaceIpConfig
NOTE
If the primary network interface has multiple IP configurations and you change the private IP address of the primary IP
configuration, you must manually reassign the primary and secondary IP addresses to the network interface within
Windows (not required for Linux). To manually assign IP addresses to a network interface within an operating system, read
the Assign multiple IP addresses to virtual machines article. See private IP addresses for special considerations before
manually adding IP addresses to a virtual machine operating system. Do not add any public IP addresses to the virtual
machine operating system.
Commands
TOOL COMMAND
PowerShell Set-AzureRMNetworkInterfaceIpConfig
Remove IP addresses
You can remove private and public IP addresses from a network interface, but a network interface must always
have at least one private IPv4 address assigned to it.
1. Log in to the Azure portal with an account that is assigned (at a minimum) permissions for the Network
Contributor role for your subscription. Read the Built-in roles for Azure role-based access control article to
learn more about assigning roles and permissions to accounts.
2. In the box that contains the text Search resources at the top of the Azure portal, type network interfaces.
When network interfaces appears in the search results, click it.
3. In the Network interfaces blade that appears, click the network interface you want to remove IP addresses
from.
4. Click IP configurations in the SETTINGS section of the blade for the network interface you selected.
5. Right-click a secondary IP configuration (you cannot delete the primary configuration) you want to delete,
click Delete, then click Yes to confirm the deletion. If the configuration had a public IP address resource
associated to it, the resource is dissociated from the IP configuration, but the resource is not deleted.
6. Close the IP configurations blade.
Commands
TOOL COMMAND
PowerShell Remove-AzureRmNetworkInterfaceIpConfig
IP configurations
Private and (optionally) public IP addresses are assigned to one or more IP configurations assigned to a network
interface. There are two types of IP configurations:
Primary
Each network interface is assigned one primary IP configuration. A primary IP configuration:
Has a private IPv4 address assigned to it. You cannot assign a private IPv6 address to a primary IP
configuration.
May also have a public IPv4 address assigned to it. You cannot assign a public IPv6 address to a primary or
secondary IP configuration. You can however, assign a public IPv6 address to an Azure load balancer, which
can load balance traffic to a virtual machine's private IPv6 address. For more information, see details and
limitations for IPv6.
Secondary
In addition to a primary IP configuration, a network interface may have zero or more secondary IP
configurations assigned to it. A secondary IP configuration:
Must have a private IPv4 or IPv6 address assigned to it. If the address is IPv6, the network interface can only
have one secondary IP configuration. If the address is IPv4, the network interface may have multiple
secondary IP configurations assigned to it. To learn more about how many private and public IPv4 addresses
can be assigned to a network interface, see the Azure limits article.
May also have a public IPv4 address assigned to it, if the private IP address is IPv4. If the private IP address is
IPv6, you cannot assign a public IPv4 or IPv6 address to the IP configuration. Assigning multiple IP addresses
to a network interface is helpful in scenarios such as:
Hosting multiple websites or services with different IP addresses and SSL certificates on a single
server.
A virtual machine serving as a network virtual appliance, such as a firewall or load balancer.
The ability to add any of the private IPv4 addresses for any of the network interfaces to an Azure Load
Balancer back-end pool. In the past, only the primary IPv4 address for the primary network interface
could be added to a back-end pool. To learn more about how to load balance multiple IPv4
configurations, see the Load balancing multiple IP configurations article.
The ability to load balance one IPv6 address assigned to a network interface. To learn more about how
to load balance to a private IPv6 address, see the Load balance IPv6 addresses article.
Address types
You can assign the following types of IP addresses to an IP configuration:
Private
Private IPv4 addresses enable a virtual machine to communicate with other resources in a virtual network or
other connected networks. A virtual machine cannot be communicated inbound to, nor can the virtual machine
communicate outbound with a private IPv6 address, with one exception. A virtual machine can communicate
with the Azure load balancer using an IPv6 address. For more information, see details and limitations for IPv6.
By default, the Azure DHCP servers assign the private IPv4 address for the primary IP configuration of the
network interface to the network interface within the virtual machine operating system. Unless necessary, you
should never manually set the IP address of a network interface within the virtual machine's operating system.
WARNING
If the IPv4 address set as the primary IP address of a network interface within a virtual machine's operating system is ever
different than the private IPv4 address assigned to the primary IP configuration of the primary network interface attached
to a virtual machine within Azure, you lose connectivity to the virtual machine.
There are scenarios where it's necessary to manually set the IP address of a network interface within the virtual
machine's operating system. For example, you must manually set the primary and secondary IP addresses of a
Windows operating system when adding multiple IP addresses to an Azure virtual machine. For a Linux virtual
machine, you may only need to manually set the secondary IP addresses. See Add IP addresses to a VM
operating system for details. When you manually set the IP address within the operating system, it's
recommended that you always assign the addresses to the IP configuration for a network interface using the
static (rather than dynamic) assignment method. Assigning the address using the static method ensures that the
address does not change within Azure. If you ever need to change the address assigned to an IP configuration,
it's recommended that you:
1. To ensure the virtual machine is receiving an address from the Azure DHCP servers, change the assignment
of the IP address back to DHCP within the operating system and restart the virtual machine.
2. Stop (deallocate) the virtual machine.
3. Change the IP address for the IP configuration within Azure.
4. Start the virtual machine.
5. Manually configure the secondary IP addresses within the operating system (and also the primary IP address
within Windows) to match what you set within Azure.
By following the previous steps, the private IP address assigned to the network interface within Azure, and within
a virtual machine's operating system, remain the same. To keep track of which virtual machines within your
subscription that you've manually set IP addresses within an operating system for, consider adding an Azure tag
to the virtual machines. You might use "IP address assignment: Static", for example. This way, you can easily find
the virtual machines within your subscription that you've manually set the IP address for within the operating
system.
In addition to enabling a virtual machine to communicate with other resources within the same, or connected
virtual networks, a private IP address also enables a virtual machine to communicate outbound to the Internet.
Outbound connections are source network address translated by Azure to an unpredictable public IP address. To
learn more about Azure outbound Internet connectivity, read the Azure outbound Internet connectivity article.
You cannot communicate inbound to a virtual machine's private IP address from the Internet.
Public
Public IP addresses enable inbound connectivity to a virtual machine from the Internet. Outbound connections to
the Internet use a predictable IP address. See Understanding outbound connections in Azure for details. You may
assign a public IP address to an IP configuration, but aren't required to. If you don't assign a public IP address to
a virtual machine, it can still communicate outbound to the Internet using its private IP address. To learn more
about public IP addresses, read the Public IP address article.
There are limits to the number of private and public IP addresses that you can assign to a network interface. For
details, read the Azure limits article.
NOTE
Azure translates a virtual machine's private IP address to a public IP address. As a result, the operating system is unaware
of any public IP addresses assigned to it, so there is no need to ever manually assign a public IP address within the
operating system.
Assignment methods
Public and private IP addresses are assigned using the following assignment methods:
Dynamic
Dynamic private IPv4 and IPv6 (optionally) addresses are assigned by default. Dynamic addresses can change if
the virtual machine is put into the stopped (deallocated) state, then started. If you don't want IPv4 addresses to
change for the life of the virtual machine, assign the addresses using the static method. You can only assign a
private IPv6 address using the dynamic assignment method. You cannot assign a public IPv6 address to an IP
configuration using either method.
Static
Addresses assigned using the static method do not change until a virtual machine is deleted. You manually
assign a static private IPv4 address to an IP configuration from the address space for the subnet the network
interface is in. You can (optionally) assign a public or private static IPv4 address to an IP configuration. You
cannot assign a static public or private IPv6 address to an IP configuration. To learn more about how Azure
assigns static public IPv4 addresses, see the Public IP address article.
IP address versions
You can specify the following versions when assigning addresses:
IPv4
Each network interface must have one primary IP configuration with an assigned private IPv4 address. You can
add one or more secondary IP configurations that each have an IPv4 private and (optionally) an IPv4 public IP
address.
IPv6
You can assign zero or one private IPv6 address to one secondary IP configuration of a network interface. The
network interface cannot have any existing secondary IP configurations. You cannot add an IP configuration with
an IPv6 address using the portal. Use PowerShell or the CLI to add an IP configuration with a private IPv6
address to an existing network interface. The network interface cannot be attached to an existing VM.
NOTE
Though you can create a network interface with an IPv6 address using the portal, you can't add an existing network
interface to a new, or existing virtual machine, using the portal. Use PowerShell or the Azure CLI 2.0 to create a network
interface with a private IPv6 address, then attach the network interface when creating a virtual machine. You cannot
attach a network interface with a private IPv6 address assigned to it to an existing virtual machine. You cannot add a
private IPv6 address to an IP configuration for any network interface attached to a virtual machine using any tools (portal,
CLI, or PowerShell).
Next steps
To create a virtual machine with different IP configurations, read the following articles:
TASK TOOL
Create a single NIC VM with a private IPv6 address (behind CLI, PowerShell, Azure Resource Manager template
an Azure Load Balancer)
Move a VM (Classic) or Cloud Services role instance
to a different subnet using PowerShell
6/27/2017 1 min to read Edit Online
You can use PowerShell to move your VMs (Classic) from one subnet to another in the same virtual network
(VNet). Role instances can be moved by editing the CSCFG file, rather than using PowerShell.
NOTE
This article explains how to move VMs deployed through the classic deployment model only.
Why move VMs to another subnet? Subnet migration is useful when the older subnet is too small and cannot be
expanded due to existing running VMs in that subnet. In that case, you can create a new, larger subnet and migrate
the VMs to the new subnet, then after migration is complete, you can delete the old empty subnet.
If you specified a static internal private IP for your VM, you'll have to clear that setting before you can move the VM
to a new subnet. In that case, use the following:
Learn about a public IP address and how to create, change, and delete one. A public IP address is a resource with
its own configurable settings. Assigning a public IP address to other Azure resources enables:
Inbound Internet connectivity to resources such as Azure Virtual Machines (VM), Azure Virtual Machine Scale
Sets, Azure VPN Gateway, Application gateways, and Internet-facing Azure Load Balancers. Azure resources
cannot receive inbound communication from the Internet without an assigned public IP address. While some
Azure resources are inherently accessible through public IP addresses, other resources must have public IP
addresses assigned to them to be accessible from the Internet.
Outbound connectivity to the Internet using a predictable IP address. For example, a virtual machine can
communicate outbound to the Internet without a public IP address assigned to it, but its address is network
address translated by Azure to an unpredictable public address. Assigning a public IP address to a resource
enables you to know which IP address is used for the outbound connection. Though predictable, the address
can change, depending on the assignment method chosen. For more information, see Create a public IP
address. To learn more about outbound connections from Azure resources, read the Understand outbound
connections article.
Name (Only visible if you checked Yes, if you select the Create an IPv6 The name must be different than the
the Create an IPv6 (or IPv4) (or IPv4) checkbox. name you enter for the first Name in
address checkbox) this list. If you choose to create both
an IPv4 and an IPv6 address, the
portal creates two separate public IP
address resources, one with each IP
address version assigned to it.
IP address assignment (Only visible if Yes, if you select the Create an IPv6 If the checkbox says Create an IPv4
you checked the Create an IPv6 (or (or IPv4) checkbox. address, you can select an
IPv4) address checkbox) assignment method. If the checkbox
says Create an IPv6 address, you
cannot select an assignment method,
as it must be Dynamic.
Commands
Though the portal provides the option to create two public IP address resources (one IPv4 and one IPv6), the
following CLI and PowerShell commands create one resource with an address for one IP version or the other. If
you want two public IP address resources, one for each IP version, you must run the command twice, specifying
different names and versions for the public IP address resources.
TOOL COMMAND
PowerShell New-AzureRmPublicIpAddress
WARNING
When you change the assignment method from static to dynamic, you lose the IP address that was assigned to the public IP
address. While the Azure public DNS servers maintain a mapping between static or dynamic addresses and any DNS name
label (if you defined one), a dynamic IP address can change when the VM is started after being in the stopped (deallocated)
state. To prevent the address from changing, assign a static IP address.
Commands
TOOL COMMAND
Next steps
Assign public IP addresses when creating the following Azure resources:
Windows or Linux virtual machines
Internet-facing Azure Load Balancer
Azure Application Gateway
Site-to-site connection using an Azure VPN Gateway
Azure Virtual Machine Scale Set
Troubleshoot Network Security Groups using the
Azure Portal
6/27/2017 8 min to read Edit Online
If you configured Network Security Groups (NSGs) on your virtual machine (VM) and are experiencing VM
connectivity issues, this article provides an overview of diagnostics capabilities for NSGs to help troubleshoot
further.
NSGs enable you to control the types of traffic that flow in and out of your virtual machines (VMs). NSGs can be
applied to subnets in an Azure Virtual Network (VNet), network interfaces (NIC), or both. The effective rules applied
to a NIC are an aggregation of the rules that exist in the NSGs applied to a NIC and the subnet it is connected to.
Rules across these NSGs can sometimes conflict with each other and impact a VM's network connectivity.
You can view all the effective security rules from your NSGs, as applied on your VM's NICs. This article shows how
to troubleshoot VM connectivity issues using these rules in the Azure Resource Manager deployment model. If
you're not familiar with VNet and NSG concepts, read the Virtual network and Network security groups overview
articles.
NOTE
If the VM associated with the NIC is not in a running state, or NSGs haven't been applied to the NIC or subnet, no
rules are shown.
8. To edit NSG rules, click Subnet1-NSG in the Associated NSGs section. This opens the Subnet1-NSG blade.
You can directly edit the rules by clicking on Inbound security rules.
9. After removing the denyRDP inbound rule in the Subnet1-NSG and adding an allowRDP rule, the effective
rules list looks like the following picture:
Confirm that TCP port 3389 is open by opening an RDP connection to the VM or using the PsPing tool. You
can learn more about PsPing by reading the PsPing download page.
View effective security rules for a network interface
If your VM traffic flow is impacted for a specific NIC, you can view a full list of the effective rules for the NIC from
the network interfaces context by completing the following steps:
1. Login to the Azure portal at https://portal.azure.com.
2. Click More services, then click Network interfaces in the list that appears.
3. Select a network interface. In the following picture, a NIC named VM1-NIC1 is selected.
Notice that the Scope is set to the network interface selected. To learn more about the additional
information shown, read step 6 of the Troubleshoot NSGs for a VM section of this article.
NOTE
If an NSG is removed from a network interface, the subnet NSG is still effective on the given NIC. In this case, the
output would only show rules from the subnet NSG. Rules only appear if the NIC is attached to a VM.
4. You can directly edit rules for NSGs associated with a NIC and a subnet. To learn how, read step 8 of the View
effective security rules for a virtual machine section of this article.
NOTE
If an NSG is applied to only an empty subnet, VMs will not be listed. If an NSG is applied to a NIC which is not
associated with a VM, those NICs will also not be listed.
Network Interface: A VM can have multiple network interfaces. You can select a network interface
attached to the selected VM.
AssociatedNSGs: At any time, a NIC can have up to two effective NSGs, one applied to the NIC and the
other to the subnet. Although the scope is selected as VM1-nsg, if the NIC has an effective subnet NSG,
the output will show both NSGs.
4. You can directly edit rules for NSGs associated with a NIC or subnet. To learn how, read step 8 of the View
effective security rules for a virtual machine section of this article.
To learn more about the additional information shown, read step 6 of the View effective security rules for a
virtual machine section of this article.
NOTE
Though a subnet and NIC can each have only one NSG applied to them, an NSG can be associated to multiple NICs and
multiple subnets.
Considerations
Consider the following points when troubleshooting connectivity problems:
Default NSG rules will block inbound access from the internet and only permit VNet inbound traffic. Rules
should be explicitly added to allow inbound access from Internet, as required.
If there are no NSG security rules causing a VMs network connectivity to fail, the problem may be due to:
Firewall software running within the VM's operating system
Routes configured for virtual appliances or on-premises traffic. Internet traffic can be redirected to on-
premises via forced-tunneling. An RDP/SSH connection from the Internet to your VM may not work with
this setting, depending on how the on-premises network hardware handles this traffic. Read the
Troubleshooting Routes article to learn how to diagnose route problems that may be impeding the flow
of traffic in and out of the VM.
If you have peered VNets, by default, the VIRTUAL_NETWORK tag will automatically expand to include prefixes
for peered VNets. You can view these prefixes in the ExpandedAddressPrefix list, to troubleshoot any issues
related to VNet peering connectivity.
Effective security rules are only shown if there is an NSG associated with the VMs NIC and or subnet.
If there are no NSGs associated with the NIC or subnet and you have a public IP address assigned to your VM,
all ports will be open for inbound and outbound access. If the VM has a public IP address, applying NSGs to the
NIC or subnet is strongly recommended.
Troubleshoot Network Security Groups using Azure
PowerShell
6/27/2017 6 min to read Edit Online
If you configured Network Security Groups (NSGs) on your virtual machine (VM) and are experiencing VM
connectivity issues, this article provides an overview of diagnostics capabilities for NSGs to help troubleshoot
further.
NSGs enable you to control the types of traffic that flow in and out of your virtual machines (VMs). NSGs can be
applied to subnets in an Azure Virtual Network (VNet), network interfaces (NIC), or both. The effective rules applied
to a NIC are an aggregation of the rules that exist in the NSGs applied to a NIC and the subnet it is connected to.
Rules across these NSGs can sometimes conflict with each other and impact a VM's network connectivity.
You can view all the effective security rules from your NSGs, as applied on your VM's NICs. This article shows how
to troubleshoot VM connectivity issues using these rules in the Azure Resource Manager deployment model. If
you're not familiar with VNet and NSG concepts, read the Virtual network and Network security groups overview
articles.
TIP
If you don't know the name of a NIC, enter the following command to retrieve the names of all NICs in a resource
group:
Get-AzureRmNetworkInterface -ResourceGroupName RG1 | Format-Table Name
The following text is a sample of the effective rules output returned for the VM1-NIC1 NIC:
NetworkSecurityGroup : {
"Id": "/subscriptions/[Subscription
ID]/resourceGroups/RG1/providers/Microsoft.Network/networkSecurityGroups/VM1-NIC1-NSG"
}
Association : {
"NetworkInterface": {
"Id": "/subscriptions/[Subscription
ID]/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/VM1-NIC1"
}
}
EffectiveSecurityRules : [
{
"Name": "securityRules/allowRDP",
"Protocol": "Tcp",
"SourcePortRange": "0-65535",
"DestinationPortRange": "3389-3389",
"SourceAddressPrefix": "Internet",
"DestinationAddressPrefix": "0.0.0.0/0",
"ExpandedSourceAddressPrefix": [ ],
"ExpandedDestinationAddressPrefix": [],
"Access": "Allow",
"Priority": 1000,
"Direction": "Inbound"
},
{
"Name": "defaultSecurityRules/AllowVnetInBound",
"Protocol": "All",
"SourcePortRange": "0-65535",
"DestinationPortRange": "0-65535",
"SourceAddressPrefix": "VirtualNetwork",
"DestinationAddressPrefix": "VirtualNetwork",
"ExpandedSourceAddressPrefix": [
"10.9.0.0/16",
"168.63.129.16/32",
"10.0.0.0/16",
"10.1.0.0/16"
],
"ExpandedDestinationAddressPrefix": [
"10.9.0.0/16",
"168.63.129.16/32",
"10.0.0.0/16",
"10.1.0.0/16"
],
"Access": "Allow",
"Priority": 65000,
"Direction": "Inbound"
},
]
NetworkSecurityGroup : {
"Id":
"/subscriptions/[Subscription
ID]/resourceGroups/RG1/providers/Microsoft.Network/networkSecurityGroups/Subnet1-NSG"
}
Association : {
"Subnet": {
"Id":
"/subscriptions/[Subscription
ID]/resourceGroups/RG1/providers/Microsoft.Network/virtualNetworks/WestUS-VNet1/subnets/Subnet1"
}
}
EffectiveSecurityRules : [
{
"Name": "securityRules/denyRDP",
"Protocol": "Tcp",
"SourcePortRange": "0-65535",
"DestinationPortRange": "3389-3389",
"SourceAddressPrefix": "Internet",
"DestinationAddressPrefix": "0.0.0.0/0",
"DestinationAddressPrefix": "0.0.0.0/0",
"ExpandedSourceAddressPrefix": [
... ],
"ExpandedDestinationAddressPrefix": [],
"Access": "Deny",
"Priority": 1000,
"Direction": "Inbound"
},
{
"Name": "defaultSecurityRules/AllowVnetInBound",
"Protocol": "All",
"SourcePortRange": "0-65535",
"DestinationPortRange": "0-65535",
"SourceAddressPrefix": "VirtualNetwork",
"DestinationAddressPrefix": "VirtualNetwork",
"ExpandedSourceAddressPrefix": [
"10.9.0.0/16",
"168.63.129.16/32",
"10.0.0.0/16",
"10.1.0.0/16"
],
"ExpandedDestinationAddressPrefix": [
"10.9.0.0/16",
"168.63.129.16/32",
"10.0.0.0/16",
"10.1.0.0/16"
],
"Access": "Allow",
"Priority": 65000,
"Direction": "Inbound"
},...
]
NOTE
The command only shows effective rules if an NSG is associated with either a subnet, a NIC, or both. A VM
may have multiple NICs with different NSGs applied. When troubleshooting, run the command for each NIC.
3. To ease filtering over larger number of NSG rules, enter the following commands to troubleshoot further:
A filter for RDP traffic (TCP port 3389), is applied to the grid view, as shown in the following picture:
4. As you can see in the grid view, there are both allow and deny rules for RDP. The output from step 2 shows
that the DenyRDP rule is in the NSG applied to the subnet. For inbound rules, NSGs applied to the subnet
are processed first. If a match is found, the NSG applied to the network interface is not processed. In this
case, the DenyRDP rule from the subnet blocks RDP to the VM (VM1).
NOTE
A VM may have multiple NICs attached to it. Each may be connected to a different subnet. Since the commands in
the previous steps are run against a NIC, it's important to ensure that you specify the NIC you're having the
connectivity failure to. If you're not sure, you can always run the commands against each NIC attached to the VM.
5. To RDP into VM1, change the Deny RDP (3389) rule to Allow RDP(3389) in the Subnet1-NSG NSG. Confirm
that TCP port 3389 is open by opening an RDP connection to the VM or using the PsPing tool. You can learn
more about PsPing by reading the PsPing download page
You can or remove rules from an NSG by using the information in the output from the following command:
Get-Help *-AzureRmNetworkSecurityRuleConfig
Considerations
Consider the following points when troubleshooting connectivity problems:
Default NSG rules will block inbound access from the internet and only permit VNet inbound traffic. Rules
should be explicitly added to allow inbound access from Internet, as required.
If there are no NSG security rules causing a VMs network connectivity to fail, the problem may be due to:
Firewall software running within the VM's operating system
Routes configured for virtual appliances or on-premises traffic. Internet traffic can be redirected to on-
premises via forced-tunneling. An RDP/SSH connection from the Internet to your VM may not work with
this setting, depending on how the on-premises network hardware handles this traffic. Read the
Troubleshooting Routes article to learn how to diagnose route problems that may be impeding the flow
of traffic in and out of the VM.
If you have peered VNets, by default, the VIRTUAL_NETWORK tag will automatically expand to include prefixes
for peered VNets. You can view these prefixes in the ExpandedAddressPrefix list, to troubleshoot any issues
related to VNet peering connectivity.
Effective security rules are only shown if there is an NSG associated with the VMs NIC and or subnet.
If there are no NSGs associated with the NIC or subnet and you have a public IP address assigned to your VM,
all ports will be open for inbound and outbound access. If the VM has a public IP address, applying NSGs to the
NIC or subnet is strongly recommended.
Troubleshoot routes using the Azure Portal
6/27/2017 7 min to read Edit Online
If you are experiencing network connectivity issues to or from your Azure Virtual Machine (VM), routes may be
impacting your VM traffic flows. This article provides an overview of diagnostics capabilities for routes to help
troubleshoot further.
Route tables are associated with subnets and are effective on all network interfaces (NIC) in that subnet. The
following types of routes can be applied to each network interface:
System routes: By default, every subnet created in an Azure Virtual Network (VNet) has system route tables
that allow local VNet traffic, on-premises traffic via VPN gateways, and Internet traffic. System routes also exist
for peered VNets.
BGP routes: Propagated to network interfaces through ExpressRoute or site-to-site VPN connections. Learn
more about BGP routing by reading the BGP with VPN gateways and ExpressRoute overview articles.
User-defined routes (UDR): If you are using network virtual appliances or are forced-tunneling traffic to an
on-premises network via a site-to-site VPN, you may have user-defined routes (UDRs) associated with your
subnet route table. If you're not familiar with UDRs, read the user-defined routes article.
With the various routes that can be applied to a network interface, it can be difficult to determine which aggregate
routes are effective. To help troubleshoot VM network connectivity, you can view all the effective routes for a
network interface in the Azure Resource Manager deployment model.
NOTE
If your VM has more than one NIC attached, check effective routes for each of the NICs to diagnose network connectivity
issues to and from a VM.
NOTE
If the VM associated with the NIC is not in a running state, effective routes will not be shown. Only the first 200
effective routes are shown in the portal. For the full list, click Download. You can further filter on the results from the
downloaded .csv file.
The bi-directional link for the peering is broken, which explains why VM1 could not connect to VM3 in the
WestUS-VNet3 VNet.
8. The following picture shows the routes after establishing the bi-directional peering link:
For more troubleshooting scenarios for forced-tunneling and route evaluation, read the Considerations section of
this article.
View effective routes for a network interface
If network traffic flow is impacted for a particular network interface (NIC), you can view a full list of effective routes
on a NIC directly. To see the aggregate routes that are applied to a NIC, complete the following steps:
1. Login to the Azure portal at https://portal.azure.com.
2. Click More services, then click Network interfaces
3. Search the list for the name of a NIC, or select it from the list that appears. In this example, VM1-NIC1 is
selected.
4. Select Effective routes in the Network interface blade, as shown in the following picture:
![](./media/virtual-network-routes-troubleshoot-portal/image6.png)
4. Select Effective Routes in the Route table blade. The Scope is set to the route table you selected.
5. A route table can be applied to multiple subnets. Select the Subnet you want to review from the list. In this
example, Subnet1 is selected.
6. Select a Network Interface. All NICs connected to the selected subnet are listed. In this example, VM1-NIC1
is selected.
NOTE
If the NIC is not associated with a running VM, no effective routes are shown.
Considerations
A few things to keep in mind when reviewing the list of routes returned:
Routing is based on Longest Prefix Match (LPM) among UDRs, BGP and system routes. If there is more than
one route with the same LPM match, then a route is selected based on its origin in the following order:
User-defined route
BGP route
System (Default) route
With effective routes, you can only see effective routes that are LPM match based on all the availble
routes. By showing how the routes are actually evaluated for a given NIC, this makes it a lot easier to
troubleshoot specific routes that may be impacting connectivity to/from your VM.
If you have UDRs and are sending traffic to a network virtual appliance (NVA), with VirtualAppliance as
nextHopType, ensure that IP forwarding is enabled on the NVA receiving the traffic or packets are dropped.
If Forced tunneling is enabled, all outbound Internet traffic will be routed to on-premises. RDP/SSH from
Internet to your VM may not work with this setting, depending on how the on-premises handles this traffic.
Forced-tunneling can be enabled:
If using site-to-site VPN, by setting a user-defined route (UDR) with nextHopType as VPN Gateway
If a default route is advertised over BGP
For VNet peering traffic to work correctly, a system route with nextHopType VNetPeering must exist for the
peered VNets prefix range. If such a route doesnt exist and the VNet peering link looks OK:
Wait a few seconds and retry if it's a newly established peering link. It occasionally takes longer to
propagate routes to all the network interfaces in a subnet.
Network Security Group (NSG) rules may be impacting the traffic flows. For more information, see the
Troubleshoot Network Security Groups article.
Troubleshoot routes using Azure PowerShell
6/27/2017 5 min to read Edit Online
If you are experiencing network connectivity issues to or from your Azure Virtual Machine (VM), routes may be
impacting your VM traffic flows. This article provides an overview of diagnostics capabilities for routes to help
troubleshoot further.
Route tables are associated with subnets and are effective on all network interfaces (NIC) in that subnet. The
following types of routes can be applied to each network interface:
System routes: By default, every subnet created in an Azure Virtual Network (VNet) has system route tables
that allow local VNet traffic, on-premises traffic via VPN gateways, and Internet traffic. System routes also exist
for peered VNets.
BGP routes: Propagated to network interfaces through ExpressRoute or site-to-site VPN connections. Learn
more about BGP routing by reading the BGP with VPN gateways and ExpressRoute overview articles.
User-defined routes (UDR): If you are using network virtual appliances or are forced-tunneling traffic to an
on-premises network via a site-to-site VPN, you may have user-defined routes (UDRs) associated with your
subnet route table. If you're not familiar with UDRs, read the user-defined routes article.
With the various routes that can be applied to a network interface, it can be difficult to determine which aggregate
routes are effective. To help troubleshoot VM network connectivity, you can view all the effective routes for a
network interface in the Azure Resource Manager deployment model.
NOTE
If your VM has more than one NIC attached, check effective routes for each of the NICs to diagnose network connectivity
issues to and from a VM.
TIP
If you dont know the name of a network interface, type the following command to retrieve the names of all network
interfaces in a resource group.*
The following output looks similar to the output for each route applied to the subnet the NIC is connected
to:
Name :
State : Active
AddressPrefix : {10.9.0.0/16}
NextHopType : VNetLocal
NextHopIpAddress : {}
Name :
State : Active
AddressPrefix : {0.0.0.0/16}
NextHopType : Internet
NextHopIpAddress : {}
The following output is some of the output received for the scenario described previously:
3. There is no route listed to the WestUS-VNet3 VNet (Prefix 10.10.0.0/16)** from WestUS-VNet1 (Prefix
10.9.0.0/16) in the output from the previous step. As shown in the following picture, the VNet peering link
with the WestUS-VNet3 VNet is in the Disconnected state.
The bi-directional link for the peering is broken, which explains why VM1 could not connect to VM3 in the
WestUS-VNet3 VNet. Setup a bi-directional VNet peering link again for WestUS-VNet1 and WestUS-VNet3
VNets. The output returned after the VNet peering link is correctly established follows:
Once you determine the issue, you can add, remove, or change routes and route tables. Type the following
command to see a list of the commands used to do so:
Get-Help *-AzureRmRouteConfig
Considerations
A few things to keep in mind when reviewing the list of routes returned:
Routing is based on Longest Prefix Match (LPM) among UDRs, BGP and system routes. If there is more than
one route with the same LPM match, then a route is selected based on its origin in the following order:
User-defined route
BGP route
System (Default) route
With effective routes, you can only see effective routes that are LPM match based on all the availble
routes. By showing how the routes are actually evaluated for a given NIC, this makes it a lot easier to
troubleshoot specific routes that may be impacting connectivity to/from your VM.
If you have UDRs and are sending traffic to a network virtual appliance (NVA), with VirtualAppliance as
nextHopType, ensure that IP forwarding is enabled on the NVA receiving the traffic or packets are dropped.
If Forced tunneling is enabled, all outbound Internet traffic will be routed to on-premises. RDP/SSH from
Internet to your VM may not work with this setting, depending on how the on-premises handles this traffic.
Forced-tunneling can be enabled:
If using site-to-site VPN, by setting a user-defined route (UDR) with nextHopType as VPN Gateway
If a default route is advertised over BGP
For VNet peering traffic to work correctly, a system route with nextHopType VNetPeering must exist for the
peered VNets prefix range. If such a route doesnt exist and the VNet peering link looks OK:
Wait a few seconds and retry if it's a newly established peering link. It occasionally takes longer to
propagate routes to all the network interfaces in a subnet.
Network Security Group (NSG) rules may be impacting the traffic flows. For more information, see the
Troubleshoot Network Security Groups article.
Bandwidth/Throughput testing (NTTTCP)
7/25/2017 3 min to read Edit Online
When testing network throughput performance in Azure, it's best to use a tool that targets the network for testing
and minimizes the use of other resources that could impact performance. NTTTCP is recommended.
Copy the tool to two Azure VMs of the same size. One VM functions as SENDER and the other as RECEIVER.
Deploying VMs for testing
For the purposes of this test, the two VMs should be in either the same Cloud Service or the same Availability Set
so that we can use their internal IPs and exclude the Load Balancers from the test. It is possible to test with the VIP
but this kind of testing is outside the scope of this document.
Make a note of the RECEIVER's IP address. Let's call that IP "a.b.c.r"
Make a note of the number of cores on the VM. Let's call this "#num_cores"
Run the NTTTCP test for 300 seconds (or 5 minutes) on the sender VM and receiver VM.
Tip: When setting up this test for the first time, you might try a shorter test period to get feedback sooner. Once the
tool is working as expected, extend the test period to 300 seconds for the most accurate results.
NOTE
The sender and receiver must specify the same test duration parameter (-t).
NOTE
The preceding sample should only be used to confirm your configuration. Valid examples of testing are covered later in this
document.
ntttcp -r -t 300
Sender :
Sender :
Next steps
Depending on results, there may be room to Optimize network throughput machines for your scenario.
Learn more wtih Azure Virtual Network frequently asked questions (FAQ)
Troubleshooting: Failed to delete a virtual network in
Azure
7/18/2017 2 min to read Edit Online
You might receive errors when you try to delete a virtual network in Microsoft Azure. This article provides
troubleshooting steps to help you resolve this problem.
If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and the Stack Overflow. You can
post your issue in these forums, or post to @AzureSupport on Twitter. You also can submit an Azure support
request. To submit a support request, on the Azure support page, select Get support.
Troubleshooting guidance
1. Check whether a virtual network gateway is running in the virtual network.
2. Check whether an application gateway is running in the virtual network.
3. Check whether Azure Active Directory Domain Service is enabled in the virtual network.
4. Check whether the virtual network is connected to other resource.
5. Check whether a virtual machine is still running in the virtual network.
6. Check whether the virtual network is stuck in migration.
Troubleshooting steps
Check whether a virtual network gateway is running in the virtual network
To remove the virtual network, you must first remove the virtual network gateway.
For classic virtual networks, go to the Overview page of the classic virtual network in the Azure portal. In the VPN
connections section, if the gateway is running in the virtual network, you will see the IP address of the gateway.
For virtual networks, go to the Overview page of the virtual network. Check Connected devices for the virtual
network gateway.
Before you can remove the gateway, first remove any Connection objects in the gateway.
Check whether an application gateway is running in the virtual network
Go to the Overview page of the virtual network. Check the Connected devices for the application gateway.
If there is an application gateway, you must remove it before you can delete the virtual network.
Check whether Azure Active Directory Domain Service is enabled in the virtual network
If the Active Directory Domain Service is enabled and connected to the virtual network, you cannot delete this
virtual network.
Next steps
Azure Virtual Network
Azure Virtual Network frequently asked questions (FAQ)
Troubleshooting connectivity problems between
Azure VMs
8/29/2017 3 min to read Edit Online
You might experience connectivity problems between Azure virtual machines (VMs). This article provides
troubleshooting steps to help you resolve this problem.
If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and the Stack Overflow. You can
post your issue in these forums, or post to @AzureSupport on Twitter. You also can submit an Azure support
request. To submit a support request, on the Azure support page, select Get support.
Symptom
One Azure VM cannot connect to another Azure VM.
Troubleshooting guidance
1. Check whether NIC is misconfigured
2. Check whether network traffic is blocked by NSG or UDR
3. Check whether network traffic is blocked by VM firewall
4. Check whether VM app or service is listening on the port
5. Check whether the problem is caused by SNAT
6. Check whether traffic is blocked by ACLs for the classic VM
7. Check whether the endpoint is created for the classic VM
8. Try to connect to a VM network share
9. Check Inter-Vnet connectivity
Troubleshooting steps
Follow these steps to troubleshoot the problem. After you complete each step, check whether the problem is
resolved.
Step 1: Check whether NIC is misconfigured
Follow the steps in How to reset network interface for Azure Windows VM.
If the problem occurs after you modify the network interface (NIC), follow these steps:
Multi-NIC VMs
1. Add a NIC.
2. Fix the problems in the bad NIC or remove the bad NIC. Then add the NIC again.
For more information, see Add network interfaces to or remove from virtual machines.
Single-NIC VM
Redeploy Windows VM
Redeploy Linux VM
Step 2: Check whether network traffic is blocked by NSG or UDR
Use Network Watcher IP Flow Verify and NSG Flow Logging to determine whether there is a Network Security
Group (NSG) or User-Defined Route (UDR) that is interfering with traffic flow.
Step 3: Check whether network traffic is blocked by VM firewall
Disable the firewall, and then test the result. If the problem is resolved, verify the firewall settings, and then re-
enable the firewall.
Step 4: Check whether VM app or service is listening on the port
You can use one of the following methods to check whether the VM app or service is listening on the port.
Run the following commands to check whether the server is listening on that port.
Windows VM
netstat ano
Linux VM
netstat -l
Run the telnet command on the virtual machine itself to test the port. If the test fails, the application or service
is not configured to listen on that port.
Step 5: Check whether the problem is caused by SNAT
In some scenarios, the VM is placed behind a load balance solution that has a dependency on resources outside of
Azure. In these scenarios, if you experience intermittent connection problems, the problem may be caused by SNAT
port exhaustion. To resolve the issue, create a VIP (or ILPIP for classic) for each VM that is behind the load balancer
and secure with NSG or ACL.
Step 6: Check whether traffic is blocked by ACLs for the classic VM
An access control list (ACL) provides the ability to selectively permit or deny traffic for a virtual machine endpoint.
For more information, see Manage the ACL on an endpoint.
Step 7: Check whether the endpoint is created for the classic VM
All VMs that you create in Azure by using the classic deployment model can automatically communicate over a
private network channel with other virtual machines in the same cloud service or virtual network. However,
computers on other virtual networks require endpoints to direct the inbound network traffic to a virtual machine.
For more information, see How to set up endpoints.
Step 8: Try to connect to a VM network share
If you cannot connect to a VM network share, the problem may be caused by unavailable NICs in the VM. To delete
the unavailable NICs, see How to delete the unavailable NICs
Step 9: Check Inter-Vnet connectivity
Use Network Watcher IP Flow Verify and NSG Flow Logging to determine whether there is a NSG or UDR that is
interfering with traffic flow. You can also verify your Inter-Vnet configuration here.
Need help? Contact support.
If you still need help, contact support to get your issue resolved quickly.