During Public Preview you can use the Team plan for free, and get an early-adopter discount at GA. Sign in
Deploying a Network Interface
This guide shows you how to deploy a Network Interface against Locally, with a dynamic or static private IP, a Network Security Group and a Public IP Address. As with the other guides we're going to use the Azure CLI, but the same resources can be provisioned with HashiCorp Terraform, Pulumi or Bicep too.
Creating a Virtual Machine creates a Network Interface for you. Creating one yourself lets you choose its address and settings.
Before you start
- The Azure CLI (
az) installed. - Locally installed, with Locally Setup completed.
1. Start Locally
Firstly, we need to launch Locally which we can do from a terminal by running:
$
locally build
Once Locally has started, the Locally Dashboard will open automatically:
2. Create a Resource Group
Next we can create the Resource Group:
$
locally run az group create -n sample-nic -l berlin
There's two things to note here:
- The Azure CLI supports Automatic Configuration, meaning that it can automatically be configured to work against Locally just by prefixing commands with
locally run. - Locally intentionally uses a different set of locations to Azure as a safety precaution, so that you can be confident you're deploying against Locally rather than regular Azure. You can also configure Locally to use the Azure locations too, but you'll want to be extra sure that you're prefixing commands with
locally runwhen you do.
3. Create a Network Interface
A Network Interface lives in a subnet, so we'll start with a Virtual Network:
$
locally run az network vnet create -g sample-nic -n sample-vnet --address-prefixes 10.0.0.0/16 --subnet-name workloads --subnet-prefixes 10.0.1.0/24
Then the Network Interface. Without an address of our own, it's given the next free one in the subnet:
$
locally run az network nic create -g sample-nic -n sample-nic-app --vnet-name sample-vnet --subnet workloads --query "{name:NewNIC.name, privateIp:NewNIC.ipConfigurations[0].privateIPAddress, allocation:NewNIC.ipConfigurations[0].privateIPAllocationMethod, state:NewNIC.provisioningState}"
{
"allocation": "Dynamic",
"name": "sample-nic-app",
"privateIp": "10.0.1.4",
"state": "Succeeded"
}
The first four addresses in the subnet are reserved, which is why it starts at 10.0.1.4.
4. Use a static IP, a Network Security Group and a Public IP Address
For a second Network Interface we'll pick the address ourselves, and attach a Network Security Group and a Public IP Address. First we create those two:
$
locally run az network nsg create -g sample-nic -n sample-nsg
$
locally run az network public-ip create -g sample-nic -n sample-nic-pip --sku Standard --allocation-method Static
Then the Network Interface, with a static private IP of 10.0.1.10:
$
locally run az network nic create -g sample-nic -n sample-nic-web --vnet-name sample-vnet --subnet workloads --private-ip-address 10.0.1.10 --network-security-group sample-nsg --public-ip-address sample-nic-pip --query "{name:NewNIC.name, privateIp:NewNIC.ipConfigurations[0].privateIPAddress, allocation:NewNIC.ipConfigurations[0].privateIPAllocationMethod, nsg:NewNIC.networkSecurityGroup.id, publicIp:NewNIC.ipConfigurations[0].publicIPAddress.id}"
{
"allocation": "Static",
"name": "sample-nic-web",
"nsg": "/subscriptions/0f766306-391f-4f66-b9ee-927fb2db629c/resourceGroups/sample-nic/providers/Microsoft.Network/networkSecurityGroups/sample-nsg",
"privateIp": "10.0.1.10",
"publicIp": "/subscriptions/0f766306-391f-4f66-b9ee-927fb2db629c/resourceGroups/sample-nic/providers/Microsoft.Network/publicIPAddresses/sample-nic-pip"
}
Each private IP can only be used once in a subnet, so asking for 10.0.1.10 again is refused:
$
locally run az network nic create -g sample-nic -n sample-nic-clash --vnet-name sample-vnet --subnet workloads --private-ip-address 10.0.1.10
ERROR: (PrivateIPAddressIsAllocated) Private IP address 10.0.1.10 is already allocated to another resource in subnet /subscriptions/0f766306-391f-4f66-b9ee-927fb2db629c/resourceGroups/sample-nic/providers/Microsoft.Network/virtualNetworks/sample-vnet/subnets/workloads.
Code: PrivateIPAddressIsAllocated
Message: Private IP address 10.0.1.10 is already allocated to another resource in subnet /subscriptions/0f766306-391f-4f66-b9ee-927fb2db629c/resourceGroups/sample-nic/providers/Microsoft.Network/virtualNetworks/sample-vnet/subnets/workloads.
5. See the effective rules and routes
The effective security rules are the ones that apply to the Network Interface. Our Network Security Group has no rules of its own yet, so these are the defaults:
$
locally run az network nic list-effective-nsg -g sample-nic -n sample-nic-web --query "value[0].effectiveSecurityRules[].{Name:name, Direction:direction, Access:access, Priority:priority}" -o table
Name Direction Access Priority
----------------------------- ----------- -------- ----------
AllowVnetInBound Inbound Allow 65000
AllowAzureLoadBalancerInBound Inbound Allow 65001
DenyAllInBound Inbound Deny 65500
AllowVnetOutBound Outbound Allow 65000
AllowInternetOutBound Outbound Allow 65001
DenyAllOutBound Outbound Deny 65500
And the effective routes, which would include any from a Route Table on the subnet:
$
locally run az network nic show-effective-route-table -g sample-nic -n sample-nic-web -o table
Source State Address Prefix Next Hop Type Next Hop IP
-------- ------- ---------------- --------------- -------------
Default Active 10.0.0.0/16 VnetLocal
Default Active 0.0.0.0/0 Internet
Default Active 10.0.0.0/8 None
Default Active 172.16.0.0/12 None
Default Active 192.168.0.0/16 None
Default Active 100.64.0.0/10 None
6. List the Network Interfaces
To see the Network Interfaces in the Resource Group:
$
locally run az network nic list -g sample-nic --query "[].{Name:name, PrivateIP:ipConfigurations[0].privateIPAddress, Allocation:ipConfigurations[0].privateIPAllocationMethod, State:provisioningState}" -o table
Name PrivateIP Allocation State
-------------- ----------- ------------ ---------
sample-nic-app 10.0.1.4 Dynamic Succeeded
sample-nic-web 10.0.1.10 Static Succeeded
We can see the Network Interface in the Locally Dashboard too:
7. Tidy up
Finally, we can tidy up. We delete the Network Interfaces first:
$
locally run az network nic delete -g sample-nic -n sample-nic-web
$
locally run az network nic delete -g sample-nic -n sample-nic-app
Then remove the Resource Group and everything left in it:
$
locally run az group delete -n sample-nic --yes
Doing this with other tooling
Whilst this guide used the Azure CLI, Network Interfaces work the same way through any of the tooling that Locally supports - a Microsoft.Network/networkInterfaces resource in HashiCorp Terraform or OpenTofu, Pulumi, Bicep or an ARM Template all provision against Locally in the same way, with only the location changed.
Next steps
To see a Network Interface in use, deploy a Virtual Machine. To control its traffic, add rules to its Network Security Group.
Should you encounter any issues, please take a look at the troubleshooting section, reach out in our Discord or open an issue and we'll take a look.
Resource types this guide uses
These are the Azure resource types this guide creates in Locally:
During Public Preview you can use the Team plan for free, and get an early-adopter discount at GA. Sign in