Skip to content

Commit f893eb0

Browse files
committed
added tabs and more instructions for each method
1 parent 88cfb28 commit f893eb0

File tree

1 file changed

+196
-25
lines changed

1 file changed

+196
-25
lines changed

articles/dns/dns-web-sites-custom-domain.md

Lines changed: 196 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
title: 'Tutorial: Create custom Azure DNS records for a web app'
32
description: In this tutorial, you learn how to create custom domain DNS records for web apps using Azure DNS.
43
services: dns
54
author: asudbring
@@ -22,7 +21,6 @@ To do this, you have to create three records:
2221
* A root "TXT" record for verification
2322
* A "CNAME" record for the www name that points to the A record
2423

25-
2624
In this tutorial, you learn how to:
2725

2826
> [!div class="checklist"]
@@ -42,18 +40,23 @@ If you don’t have an Azure subscription, create a [free account](https://azure
4240

4341
* A web app. If you don't have one, you can [create a static HTML web app](../app-service/quickstart-html.md) for this tutorial.
4442

45-
* An Azure DNS zone with delegation in your registrar to Azure DNS. If you don't have one, you can [create a DNS zone](./dns-getstarted-powershell.md), then [delegate your domain](dns-delegate-domain-azure-dns.md#delegate-the-domain) to Azure DNS.
43+
* An Azure DNS zone with delegation in your registrar to Azure DNS. If you don't have one, you can create a DNS zone, then [delegate your domain](dns-delegate-domain-azure-dns.md#delegate-the-domain) to Azure DNS.
4644

47-
> [!NOTE]
48-
> In this tutorial, `contoso.com` is used as an example domain name. Replace `contoso.com` with your own domain name.
45+
# [Portal](#tab/azure-portal)
46+
47+
[!INCLUDE [Azure portal prerequisites](~/reusable-content/ce-skilling/azure/includes/azure-portal-prerequisites.md)]
48+
49+
# [PowerShell](#tab/azure-powershell)
4950

50-
[!INCLUDE [cloud-shell-try-it.md](~/reusable-content/ce-skilling/azure/includes/cloud-shell-try-it.md)]
51+
[!INCLUDE [powershell-local-cloudshell](~/reusable-content/ce-skilling/azure/includes/powershell-local-cloudshell.md)]
5152

52-
[!INCLUDE [updated-for-az](~/reusable-content/ce-skilling/azure/includes/updated-for-az.md)]
53+
If you're running PowerShell locally, you also need the Azure PowerShell module. Run `Get-Module -ListAvailable Az` to find the version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure.
5354

54-
## Sign in to Azure
55+
# [Azure CLI](#tab/azure-cli)
5556

56-
Sign in to the [Azure portal](https://portal.azure.com).
57+
[!INCLUDE [azure-cli-local-cloudshell](~/reusable-content/ce-skilling/azure/includes/azure-cli-local-cloudshell.md)]
58+
59+
---
5760

5861
## Create the A record
5962

@@ -67,14 +70,56 @@ In the left navigation of the App Services page in the Azure portal, select **Cu
6770

6871
### Create the record
6972

73+
# [Azure portal](#tab/azure-portal)
74+
75+
1. Navigate to your DNS zone in the Azure portal.
76+
2. Select **+ Record set**.
77+
3. On the **Add record set** page, enter the following information:
78+
- **Name**: Enter **@** (represents the root domain)
79+
- **Type**: Select **A**
80+
- **TTL**: Enter **600**
81+
- **TTL unit**: Select **Seconds**
82+
- **IP address**: Enter the IP address of your web app (copied from the previous step)
83+
4. Select **OK** to create the record.
84+
85+
# [Azure PowerShell](#tab/azure-powershell)
86+
7087
To create the A record, use:
7188

7289
```azurepowershell
73-
New-AzDnsRecordSet -Name "@" -RecordType "A" -ZoneName "contoso.com" `
74-
-ResourceGroupName "MyAzureResourceGroup" -Ttl 600 `
75-
-DnsRecords (New-AzDnsRecordConfig -IPv4Address "<ip of web app service>")
90+
$recordParams = @{
91+
Name = "@"
92+
RecordType = "A"
93+
ZoneName = "contoso.com"
94+
ResourceGroupName = "test-rg"
95+
Ttl = 600
96+
DnsRecords = (New-AzDnsRecordConfig -IPv4Address "<ip of web app service>")
97+
}
98+
New-AzDnsRecordSet @recordParams
99+
```
100+
101+
# [Azure CLI](#tab/azure-cli)
102+
103+
To create the A record, use:
104+
105+
```azurecli
106+
# Create the A record set
107+
az network dns record-set a create \
108+
--resource-group test-rg \
109+
--zone-name contoso.com \
110+
--name "@" \
111+
--ttl 600
112+
113+
# Add the IP address to the A record set
114+
az network dns record-set a add-record \
115+
--resource-group test-rg \
116+
--zone-name contoso.com \
117+
--record-set-name "@" \
118+
--ipv4-address "<ip of web app service>"
76119
```
77120

121+
---
122+
78123
> [!IMPORTANT]
79124
> The A record must be manually updated if the underlying IP address for the web app changes.
80125
@@ -85,22 +130,76 @@ App Services uses this record only at configuration time to verify that you own
85130
> [!NOTE]
86131
> If you want to verify the domain name, but not route production traffic to the web app, you only need to specify the TXT record for the verification step. Verification does not require an A or CNAME record in addition to the TXT record.
87132
133+
# [Azure portal](#tab/azure-portal)
134+
135+
1. Navigate to your DNS zone in the Azure portal.
136+
2. Select **+ Record set**.
137+
3. On the **Add record set** page, enter the following information:
138+
- **Name**: Enter **@** (represents the root domain)
139+
- **Type**: Select **TXT**
140+
- **TTL**: Enter **600**
141+
- **TTL unit**: Select **Seconds**
142+
- **Value**: Enter your web app's default domain name (for example, **contoso.azurewebsites.net**)
143+
4. Select **OK** to create the record.
144+
145+
# [Azure PowerShell](#tab/azure-powershell)
146+
88147
To create the TXT record, use:
89148

90149
```azurepowershell
91-
New-AzDnsRecordSet -ZoneName contoso.com -ResourceGroupName MyAzureResourceGroup `
92-
-Name "@" -RecordType "txt" -Ttl 600 `
93-
-DnsRecords (New-AzDnsRecordConfig -Value "contoso.azurewebsites.net")
150+
$txtRecordParams = @{
151+
ZoneName = "contoso.com"
152+
ResourceGroupName = "test-rg"
153+
Name = "@"
154+
RecordType = "txt"
155+
Ttl = 600
156+
DnsRecords = (New-AzDnsRecordConfig -Value "contoso.azurewebsites.net")
157+
}
158+
New-AzDnsRecordSet @txtRecordParams
94159
```
95160

161+
# [Azure CLI](#tab/azure-cli)
162+
163+
To create the TXT record, use:
164+
165+
```azurecli
166+
az network dns record-set txt add-record \
167+
--resource-group test-rg \
168+
--zone-name contoso.com \
169+
--record-set-name "@" \
170+
--value "contoso.azurewebsites.net"
171+
```
172+
173+
---
174+
96175
## Create the CNAME record
97176

98177
If your domain is already managed by Azure DNS (see [DNS domain delegation](dns-domain-delegation.md)), you can use the following example to create a CNAME record for contoso.azurewebsites.net. The CNAME created in this example has a "time to live" of 600 seconds in DNS zone named "contoso.com" with the alias for the web app contoso.azurewebsites.net.
99178

179+
# [Azure portal](#tab/azure-portal)
180+
181+
1. Navigate to your DNS zone in the Azure portal.
182+
2. Select **+ Record set**.
183+
3. On the **Add record set** page, enter the following information:
184+
- **Name**: Enter **www**
185+
- **Type**: Select **CNAME**
186+
- **TTL**: Enter **600**
187+
- **TTL unit**: Select **Seconds**
188+
- **Alias**: Enter your web app's default domain name (for example, **contoso.azurewebsites.net**)
189+
4. Select **OK** to create the record.
190+
191+
# [Azure PowerShell](#tab/azure-powershell)
192+
100193
```azurepowershell
101-
New-AzDnsRecordSet -ZoneName contoso.com -ResourceGroupName "MyAzureResourceGroup" `
102-
-Name "www" -RecordType "CNAME" -Ttl 600 `
103-
-DnsRecords (New-AzDnsRecordConfig -cname "contoso.azurewebsites.net")
194+
$cnameRecordParams = @{
195+
ZoneName = "contoso.com"
196+
ResourceGroupName = "test-rg"
197+
Name = "www"
198+
RecordType = "CNAME"
199+
Ttl = 600
200+
DnsRecords = (New-AzDnsRecordConfig -cname "contoso.azurewebsites.net")
201+
}
202+
New-AzDnsRecordSet @cnameRecordParams
104203
```
105204

106205
The following example is the response:
@@ -116,6 +215,26 @@ The following example is the response:
116215
Tags : {}
117216
```
118217

218+
# [Azure CLI](#tab/azure-cli)
219+
220+
```azurecli
221+
# Create the CNAME record set
222+
az network dns record-set cname create \
223+
--resource-group test-rg \
224+
--zone-name contoso.com \
225+
--name "www" \
226+
--ttl 600
227+
228+
# Add the CNAME record
229+
az network dns record-set cname add-record \
230+
--resource-group test-rg \
231+
--zone-name contoso.com \
232+
--record-set-name "www" \
233+
--cname "contoso.azurewebsites.net"
234+
```
235+
236+
---
237+
119238
## Test the new records
120239

121240
You can validate the records were created correctly by querying the "www.contoso.com" and "contoso.com" using nslookup, as shown below:
@@ -159,12 +278,44 @@ contoso.com text =
159278

160279
Now, you can add the custom host names to your web app:
161280

281+
# [Azure portal](#tab/azure-portal)
282+
283+
1. Navigate to your web app in the Azure portal.
284+
2. In the left navigation under **Settings**, select **Custom domains**.
285+
3. Select **+ Add custom domain**.
286+
4. In the **Custom domain** field, enter your domain name (for example, **contoso.com** or **www.contoso.com**).
287+
5. Select **Validate**. Azure will validate that the DNS records you created are properly configured.
288+
6. If validation is successful, select **Add custom domain**.
289+
7. Repeat steps 3-6 for each custom domain you want to add (both **contoso.com** and **www.contoso.com**).
290+
291+
# [Azure PowerShell](#tab/azure-powershell)
292+
162293
```azurepowershell
163-
set-AzWebApp `
164-
-Name contoso `
165-
-ResourceGroupName <your web app resource group> `
166-
-HostNames @("contoso.com","www.contoso.com","contoso.azurewebsites.net")
294+
$webAppParams = @{
295+
Name = "contoso"
296+
ResourceGroupName = "<your web app resource group>"
297+
HostNames = @("contoso.com","www.contoso.com","contoso.azurewebsites.net")
298+
}
299+
Set-AzWebApp @webAppParams
300+
```
301+
302+
# [Azure CLI](#tab/azure-cli)
303+
304+
```azurecli
305+
# Add contoso.com
306+
az webapp config hostname add \
307+
--webapp-name contoso \
308+
--resource-group <your web app resource group> \
309+
--hostname contoso.com
310+
311+
# Add www.contoso.com
312+
az webapp config hostname add \
313+
--webapp-name contoso \
314+
--resource-group <your web app resource group> \
315+
--hostname www.contoso.com
167316
```
317+
318+
---
168319
## Test the custom host names
169320

170321
Open a browser and browse to `http://www.<your domain name>` and `http://<you domain name>`.
@@ -178,12 +329,32 @@ You should see the same page for both URLs. For example:
178329

179330
## Clean up resources
180331

181-
When no longer needed, you can delete all resources created in this tutorial by deleting the resource group **MyAzureResourceGroup**:
332+
When no longer needed, you can delete all resources created in this tutorial by deleting the resource group **test-rg**:
333+
334+
# [Azure portal](#tab/azure-portal)
182335

183336
1. On the Azure portal menu, select **Resource groups**.
184-
2. Select the **MyAzureResourceGroup** resource group.
337+
2. Select the **test-rg** resource group.
185338
3. On the **Overview** page, select **Delete resource group**.
186-
4. Enter *MyAzureResourceGroup* and select **Delete**.
339+
4. Enter *test-rg* and select **Delete**.
340+
341+
# [Azure PowerShell](#tab/azure-powershell)
342+
343+
```azurepowershell
344+
$resourceGroupParams = @{
345+
Name = "test-rg"
346+
Force = $true
347+
}
348+
Remove-AzResourceGroup @resourceGroupParams
349+
```
350+
351+
# [Azure CLI](#tab/azure-cli)
352+
353+
```azurecli
354+
az group delete --name test-rg --yes --no-wait
355+
```
356+
357+
---
187358

188359
## Next steps
189360

0 commit comments

Comments
 (0)