none
ARM Templates VNET DNS settings

    Question

  • Hi

    I have recently created the below arm template, however I cant seem to get the DNS of the VNET to apply with this config. When viewing in the manager it is not applying it at a vnet level, but rather at the NIC level. To add, the machine deploys with no issues, I can connect to it, etc.... just the DNS settings not applying at the VNET level.

    Hopefully this is a simple fix I am missing:

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
         "parameters": {
            "osDiskVhdUri": {
                "defaultValue": "https://imageoffile",
                "type": "String",
                 "metadata": {
                    "description": "Uri of the user image"
                }
            },
            "adminUsername": {
                "defaultValue": "username",
                "type": "String",
                "metadata": {
                    "description": "Username for the Virtual Machine. Default value is localadmin"
                }
            },
            "adminPassword": {
                "defaultValue": "password",
                "type": "String",
                "metadata": {
                    "description": "Password for the Virtual Machine. Default value is 'Subscription#<subscription id>'"
                }
            },
            "imagePublisher": {
                "defaultValue": "Canonical",
                "type": "String",
                "metadata": {
                    "description": "Maps to the publisher in the Azure Stack Platform Image Repository manifest file Eg: Canonical, Suse, OpenLogic "
                }
            },
            "imageOffer": {
                "defaultValue": "UbuntuServer",
                "type": "String",
                "metadata": {
                    "description": "Maps to the Offer in the Azure Stack Platform Image Repository manifest file Eg: UbuntuServer, SlesServer, CentOS "
                }
            },
            "imageSku": {
                "defaultValue": "16.04-LTS",
                "type": "String",
                "metadata": {
                    "description": "Maps to the sku in the Azure Stack Platform Image Repository manifest file Eg: 12.SP1, 6.7 , 7.2"
                }
            },
            "vmSize": {
                "defaultValue": "Standard_A1",
                "type": "String",
                "metadata": {
                    "description": "The size of the Virtual Machine."
                }
            },
            "publicIPAllocationMethod": {
                "allowedValues": [
                    "Dynamic",
                    "Static"
                ],
                "type": "String"
            },
            "idleTimeoutInMinutes": {
                "defaultValue": "4",
                "type": "Int"       
            },
            "publicIpAddressVersion": {
                "defaultValue": "IPv4",
                "type": "String"
            }
        },
        "variables": {
     "dnsNameForPublicIP": "[tolower(concat('dns', uniquestring(resourceGroup().id)))]",
     "dnsserver": "192.168.1.2",
     "location": "[resourceGroup().location]",
     "OSDiskName": "osdisk",
     "nicName1": "nic1",
     "nicName2": "nic2",
     "addressPrefix": "10.0.0.0/16",
     "subnet1Name": "NSGMGMT",
     "subnet1Id": "[concat(variables('vnetId'), '/subnets/', variables('subnet1Name'))]",
     "subnet1Prefix": "10.0.1.0/24",
     "subnet1PrivateAddress": "10.0.1.10",
     "subnet2Name": "Client",
     "subnet2Id": "[concat(variables('vnetId'), '/subnets/', variables('subnet2Name'))]",
     "subnet2Prefix": "10.0.2.0/24",
     "subnet2PrivateAddress": "10.0.2.10",
     "storageAccountName": "[concat('sa', uniquestring(resourceGroup().id))]",
     "storageAccountType": "Standard_LRS",
     "vmStorageAccountContainerName": "vhds",
     "vmName": "[concat('vm', resourceGroup().name)]",
     "vnetName": "vnet",
     "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('vnetName'))]",
     "networkSecurityGroupName": "[tolower(concat('nsg',uniquestring(resourceGroup().id)))]",
     "publicIPAddressName": "[substring(concat('simplelinuxip2',resourceGroup().Name),0,16)]",
     "publicIPAddressId": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
        },
        "resources": [
            {
                "type": "Microsoft.Storage/storageAccounts",
                "name": "[toLower(variables('storageAccountName'))]",
                "apiVersion": "2015-05-01-preview",
                "location": "[variables('location')]",
                "properties": {
                    "accountType": "[variables('storageAccountType')]"
                }
            },
        {
          "type": "Microsoft.Network/virtualNetworks",
          "apiVersion": "2015-05-01-preview",
          "location": "[resourceGroup().location]",
          "name": "[variables('vnetName')]",
          "properties": {
            "addressSpace": {
              "addressPrefixes": [
                "[variables('addressPrefix')]"
              ]
            },
            "dhcpOptions": {
                        "dnsServers": "[variables('dnsserver')]"
            },
            "subnets": [
              {
                "name": "[variables('subnet1Name')]",
                "properties": {
                  "addressPrefix": "[variables('subnet1Prefix')]"
                }
              },
              {
                "name": "[variables('subnet2Name')]",
                "properties": {
                  "addressPrefix": "[variables('subnet2Prefix')]"
                }
              }
            ]
          }
        },
       {
          "type": "Microsoft.Network/networkInterfaces",
          "apiVersion": "2015-05-01-preview",
          "dependsOn": [
            "[variables('vnetId')]",
            "[variables('publicIPAddressId')]"
          ],
          "location": "[resourceGroup().location]",
          "name": "[variables('nicName1')]",
          "properties": {
              "dnsSettings": {
                "dnsServers": [ "[variables('dnsserver')]" ]
              },
                "networkSecurityGroup": {
                        "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
                },
          "ipConfigurations": [
              {
                "name": "ipconfig1",
                "properties": {
                  "privateIPAddress": "[variables('subnet1PrivateAddress')]",
                  "privateIPAllocationMethod": "Static",
                  "PublicIpAddress": {
                    "Id": "[variables('publicIPAddressId')]"
                  },
                  "subnet": {
                    "id": "[variables('subnet1Id')]"
                  }
                }
              }
            ]
       }
    },
        {
          "type": "Microsoft.Network/networkInterfaces",
          "apiVersion": "2015-06-15",
          "dependsOn": [
            "[variables('vnetId')]"
          ],
          "location": "[resourceGroup().location]",
          "name": "[variables('nicName2')]",
          "properties": {
            "ipConfigurations": [
              {
                "name": "ipconfig2",
                "properties": {
                  "privateIPAddress": "[variables('subnet2PrivateAddress')]",
                  "privateIPAllocationMethod": "Static",
                  "subnet": {
                    "id": "[variables('subnet2Id')]"
                  }
                }
              }
            ]
          }
        },
                 {
                "type": "Microsoft.Network/publicIPAddresses",
                "name":  "[variables('publicIPAddressName')]",
                "apiVersion": "2015-06-15",
                "location":  "[variables('location')]",
                "properties": {
                    "publicIPAllocationMethod": "[parameters('publicIPAllocationMethod')]",
                    "idleTimeoutInMinutes": "[parameters('idleTimeoutInMinutes')]",
                    "publicIpAddressVersion": "[parameters('publicIpAddressVersion')]"
                }
            },
            {
                "type": "Microsoft.Network/networkSecurityGroups",
                "name": "[variables('networkSecurityGroupName')]",
                "apiVersion": "2015-05-01-preview",
                "location": "[resourceGroup().location]",
                "properties": {
                    "securityRules": [
                        {
                            "name": "SSH",
                            "properties": {
                                "description": "SSH",
                                "protocol": "Tcp",
                                "sourcePortRange": "*",
                                "destinationPortRange": "22",
                                "sourceAddressPrefix": "*",
                                "destinationAddressPrefix": "*",
                                "access": "Allow",
                                "priority": 200,
                                "direction": "Inbound"
                            }
                        }
                    ]
                }
            },
           {
                "type": "Microsoft.Compute/virtualMachines",
                "name": "[variables('vmName')]",
                "apiVersion": "2015-06-15",
                "location": "[variables('location')]",
                "properties": {
                    "hardwareProfile": {
                        "vmSize": "[parameters('vmSize')]"
                    },
                    "osProfile": {
                        "computerName": "[variables('vmName')]",
                        "adminUsername": "[parameters('adminUsername')]",
                        "adminPassword": "[parameters('adminPassword')]"
                    },
                    "storageProfile": {
                        "osDisk": {
                            "name": "osdisk",
                            "vhd": {
                                "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, variables                             ('vmStorageAccountContainerName'),'/', variables('OSDiskName'), '.vhd')]"
                            },
                            "caching": "ReadWrite",
                            "createOption": "FromImage",
                            "osType": "Linux",
                            "image": {
                                "uri": "[parameters('osDiskVhdUri')]"
                            }
                        }
                    },
                    "networkProfile": {
                        "networkInterfaces": [
                  {
                  "properties": {
                    "primary": true
                  },
                  "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName1'))]"
                },
                {
                  "properties": {
                    "primary": false
                  },
                  "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName2'))]"
                }
              ]
            },
                    "diagnosticsProfile": {
                        "bootDiagnostics": {
                            "enabled": "true",
                            "storageUri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob)]"
                        }
                    }
                },
                "dependsOn": [
                    "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
                    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName1'))]",
                    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName2'))]"
                ]
            }
        ]
    }

    Cheers

    G



    • Edited by G2017 Thursday, April 4, 2019 8:35 AM
    Thursday, April 4, 2019 8:27 AM

Answers

All replies

  • Hello,

    if you want your VM's nic to inherit the DNS servers set at the vnet level you should set empty bracket for dnsServers and appliedDnsServers of your networkInterfaces.

    Will look like this -->

    "dnsSettings": {
    "dnsServers": [],
    "appliedDnsServers": [],

    },

    Regards,

    James

    Thursday, April 4, 2019 9:09 AM
  • DNS settings on the NIC are fine, as this is the only place it is currently setting it. The place however it is not setting it is at the VNET level.

    Are you suggesting if I remove config from these as mentioned above, this will resolve it? As it will set at the VNET level and not at the NIC level?

    Thursday, April 4, 2019 9:16 AM
  • Adding in screen shot to show what is currently happening, as you can see on the left it is sat at default, this is where I would like the DNS setting to apply. Rather than on the right where we can see the config going directly in at the nic level.

    • Edited by G2017 Thursday, April 4, 2019 9:23 AM
    Thursday, April 4, 2019 9:21 AM
  • Leaving the DNS settings empty will force your NIC to inherit the DNS servers set at the vnet level.

    This will look like this at the nic level : 

    Your vnet template part will look like this : 


    • Edited by James DLD Thursday, April 4, 2019 12:13 PM Wording
    Thursday, April 4, 2019 9:27 AM
  • Hi

    I have changed the below JSON to the following, however it is still not applying the DNS settings to the VNET level:

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
         "parameters": {
            "osDiskVhdUri": {
                "defaultValue": "https://imageoffile",
                "type": "String",
                 "metadata": {
                    "description": "Uri of the user image"
                }
            },
            "adminUsername": {
                "defaultValue": "username",
                "type": "String",
                "metadata": {
                    "description": "Username for the Virtual Machine. Default value is localadmin"
                }
            },
            "adminPassword": {
                "defaultValue": "password",
                "type": "String",
                "metadata": {
                    "description": "Password for the Virtual Machine. Default value is 'Subscription#<subscription id>'"
                }
            },
            "imagePublisher": {
                "defaultValue": "Canonical",
                "type": "String",
                "metadata": {
                    "description": "Maps to the publisher in the Azure Stack Platform Image Repository manifest file Eg: Canonical, Suse, OpenLogic "
                }
            },
            "imageOffer": {
                "defaultValue": "UbuntuServer",
                "type": "String",
                "metadata": {
                    "description": "Maps to the Offer in the Azure Stack Platform Image Repository manifest file Eg: UbuntuServer, SlesServer, CentOS "
                }
            },
            "imageSku": {
                "defaultValue": "16.04-LTS",
                "type": "String",
                "metadata": {
                    "description": "Maps to the sku in the Azure Stack Platform Image Repository manifest file Eg: 12.SP1, 6.7 , 7.2"
                }
            },
            "vmSize": {
                "defaultValue": "Standard_A1",
                "type": "String",
                "metadata": {
                    "description": "The size of the Virtual Machine."
                }
            },
            "publicIPAllocationMethod": {
                "allowedValues": [
                    "Dynamic",
                    "Static"
                ],
                "type": "String"
            },
            "idleTimeoutInMinutes": {
                "defaultValue": "4",
                "type": "Int"       
            },
            "publicIpAddressVersion": {
                "defaultValue": "IPv4",
                "type": "String"
            }
        },
        "variables": {
     "dnsNameForPublicIP": "[tolower(concat('dns', uniquestring(resourceGroup().id)))]",
     "dnsserver": "192.168.1.2",
     "location": "[resourceGroup().location]",
     "OSDiskName": "osdisk",
     "nicName1": "nic1",
     "nicName2": "nic2",
     "addressPrefix": "10.0.0.0/16",
     "subnet1Name": "NSGMGMT",
     "subnet1Id": "[concat(variables('vnetId'), '/subnets/', variables('subnet1Name'))]",
     "subnet1Prefix": "10.0.1.0/24",
     "subnet1PrivateAddress": "10.0.1.10",
     "subnet2Name": "Client",
     "subnet2Id": "[concat(variables('vnetId'), '/subnets/', variables('subnet2Name'))]",
     "subnet2Prefix": "10.0.2.0/24",
     "subnet2PrivateAddress": "10.0.2.10",
     "storageAccountName": "[concat('sa', uniquestring(resourceGroup().id))]",
     "storageAccountType": "Standard_LRS",
     "vmStorageAccountContainerName": "vhds",
     "vmName": "[concat('vm', resourceGroup().name)]",
     "vnetName": "vnet",
     "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('vnetName'))]",
     "networkSecurityGroupName": "[tolower(concat('nsg',uniquestring(resourceGroup().id)))]",
     "publicIPAddressName": "[substring(concat('simplelinuxip2',resourceGroup().Name),0,16)]",
     "publicIPAddressId": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
        },
        "resources": [
            {
                "type": "Microsoft.Storage/storageAccounts",
                "name": "[toLower(variables('storageAccountName'))]",
                "apiVersion": "2015-05-01-preview",
                "location": "[variables('location')]",
                "properties": {
                    "accountType": "[variables('storageAccountType')]"
                }
            },
        {
          "type": "Microsoft.Network/virtualNetworks",
          "apiVersion": "2015-05-01-preview",
          "location": "[resourceGroup().location]",
          "name": "[variables('vnetName')]",
          "properties": {
            "addressSpace": {
              "addressPrefixes": [
                "[variables('addressPrefix')]"
              ]
            },
            "dhcpOptions": {
                        "dnsServers": "[variables('dnsserver')]"
            },
            "subnets": [
              {
                "name": "[variables('subnet1Name')]",
                "properties": {
                  "addressPrefix": "[variables('subnet1Prefix')]"
                }
              },
              {
                "name": "[variables('subnet2Name')]",
                "properties": {
                  "addressPrefix": "[variables('subnet2Prefix')]"
                }
              }
            ]
          }
        },
       {
          "type": "Microsoft.Network/networkInterfaces",
          "apiVersion": "2015-05-01-preview",
          "dependsOn": [
            "[variables('vnetId')]",
            "[variables('publicIPAddressId')]"
          ],
          "location": "[resourceGroup().location]",
          "name": "[variables('nicName1')]",
          "properties": {
                "dnsSettings": {
         "dnsServers": [],
         "appliedDnsServers": []
              },
                "networkSecurityGroup": {
                        "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
                },
          "ipConfigurations": [
              {
                "name": "ipconfig1",
                "properties": {
                  "privateIPAddress": "[variables('subnet1PrivateAddress')]",
                  "privateIPAllocationMethod": "Static",
                  "PublicIpAddress": {
                    "Id": "[variables('publicIPAddressId')]"
                  },
                  "subnet": {
                    "id": "[variables('subnet1Id')]"
                  }
                }
              }
            ]
       }
    },
        {
          "type": "Microsoft.Network/networkInterfaces",
          "apiVersion": "2015-06-15",
          "dependsOn": [
            "[variables('vnetId')]"
          ],
          "location": "[resourceGroup().location]",
          "name": "[variables('nicName2')]",
          "properties": {
            "ipConfigurations": [
              {
                "name": "ipconfig2",
                "properties": {
                  "privateIPAddress": "[variables('subnet2PrivateAddress')]",
                  "privateIPAllocationMethod": "Static",
                  "subnet": {
                    "id": "[variables('subnet2Id')]"
                  }
                }
              }
            ]
          }
        },
                 {
                "type": "Microsoft.Network/publicIPAddresses",
                "name":  "[variables('publicIPAddressName')]",
                "apiVersion": "2015-06-15",
                "location":  "[variables('location')]",
                "properties": {
                    "publicIPAllocationMethod": "[parameters('publicIPAllocationMethod')]",
                    "idleTimeoutInMinutes": "[parameters('idleTimeoutInMinutes')]",
                    "publicIpAddressVersion": "[parameters('publicIpAddressVersion')]"
                }
            },
            {
                "type": "Microsoft.Network/networkSecurityGroups",
                "name": "[variables('networkSecurityGroupName')]",
                "apiVersion": "2015-05-01-preview",
                "location": "[resourceGroup().location]",
                "properties": {
                    "securityRules": [
                        {
                            "name": "SSH",
                            "properties": {
                                "description": "SSH",
                                "protocol": "Tcp",
                                "sourcePortRange": "*",
                                "destinationPortRange": "22",
                                "sourceAddressPrefix": "*",
                                "destinationAddressPrefix": "*",
                                "access": "Allow",
                                "priority": 200,
                                "direction": "Inbound"
                            }
                        }
                    ]
                }
            },
           {
                "type": "Microsoft.Compute/virtualMachines",
                "name": "[variables('vmName')]",
                "apiVersion": "2015-06-15",
                "location": "[variables('location')]",
                "properties": {
                    "hardwareProfile": {
                        "vmSize": "[parameters('vmSize')]"
                    },
                    "osProfile": {
                        "computerName": "[variables('vmName')]",
                        "adminUsername": "[parameters('adminUsername')]",
                        "adminPassword": "[parameters('adminPassword')]"
                    },
                    "storageProfile": {
                        "osDisk": {
                            "name": "osdisk",
                            "vhd": {
                                "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, variables                             ('vmStorageAccountContainerName'),'/', variables('OSDiskName'), '.vhd')]"
                            },
                            "caching": "ReadWrite",
                            "createOption": "FromImage",
                            "osType": "Linux",
                            "image": {
                                "uri": "[parameters('osDiskVhdUri')]"
                            }
                        }
                    },
                    "networkProfile": {
                        "networkInterfaces": [
                  {
                  "properties": {
                    "primary": true
                  },
                  "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName1'))]"
                },
                {
                  "properties": {
                    "primary": false
                  },
                  "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName2'))]"
                }
              ]
            },
                    "diagnosticsProfile": {
                        "bootDiagnostics": {
                            "enabled": "true",
                            "storageUri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob)]"
                        }
                    }
                },
                "dependsOn": [
                    "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
                    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName1'))]",
                    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName2'))]"
                ]
            }
        ]
    }

    Its no longer applying DNS settings to either the VNET or any of the interfaces. Please can you amend the config with what should be being put in to achieve the mentioned result.

    Many thanks

    G

    Monday, April 8, 2019 8:40 AM
  • In the resource "Microsoft.Network/virtualNetworks" could you try to replace

    this line : "dnsServers": "[variables('dnsserver')]"

    by : "dnsServers": ["[variables('dnsserver')]"]

    Tuesday, April 9, 2019 7:48 AM
  • That's done it, 10 points to you! Many thanks for your help on this one.
    Tuesday, April 9, 2019 10:50 AM