MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.28k stars 21.47k forks source link

Provide DNS-Forwarder sample snippet #57085

Closed ezYakaEagle442 closed 4 years ago

ezYakaEagle442 commented 4 years ago

Please provide a sample snippet to describe how to implement a DNS-Forwarder, I have found a sample for Azure File Storage but the PowerShell snippet uses CommandLet from dnsserver Module which is not available neither on WSL neither on Windows 10, it looks available only on windows server :

az vm create --name $dnsf_name \
  --image Win2019Datacenter \
  --admin-username $dnsf_admin_username \
  --admin-password $dnsf_vm_admin_pwd \
  --resource-group $rg_name \
  --vnet-name $vnet_name \
  --subnet $worker_subnet_name \
  --nsg $dnsf_nsg \
  --size Standard_B2s \
  --location $location \
  --output table

$vnetDnsServers = "<azure-dns-server-ip>", "<azure-dns-server-ip>"

$storageAccountEndpoint = Get-AzContext | `
    Select-Object -ExpandProperty Environment | `
    Select-Object -ExpandProperty StorageEndpointSuffix

Add-DnsServerConditionalForwarderZone `
        -Name $storageAccountEndpoint `
        -MasterServers $vnetDnsServers

Add-DnsServerConditionalForwarderZone `
        -Name $storageAccountEndpoint `
        -MasterServers "168.63.129.16"

See also https://docs.microsoft.com/en-us/azure/virtual-network/what-is-ip-address-168-63-129-16

An easier way is to setup a small Linux VM + CoreDNS :

az vm create --name $dnsf_name \
    --image UbuntuLTS \
    --admin-username $dnsf_admin_username \
    --resource-group $rg_name \
    --vnet-name $vnet_name \
    --subnet $worker_subnet_name \
    --nsg $dnsf_nsg \
    --size Standard_B1s \
    --zone 1 \
    --location $location \
    --ssh-key-values ~/.ssh/$ssh_key.pub

network_interface_id=$(az vm show --name $dnsf_name -g $rg_name --query 'networkProfile.networkInterfaces[0].id' -o tsv)
echo "Bastion VM Network Interface ID :" $network_interface_id

network_interface_private_ip=$(az resource show --ids $network_interface_id \
  --api-version 2019-04-01 --query 'properties.ipConfigurations[0].properties.privateIPAddress' -o tsv)
echo "Network Interface private IP :" $network_interface_private_ip

network_interface_pub_ip_id=$(az resource show --ids $network_interface_id \
  --api-version 2019-04-01 --query 'properties.ipConfigurations[0].properties.publicIPAddress.id' -o tsv)

network_interface_pub_ip=$(az network public-ip show -g $rg_name --id $network_interface_pub_ip_id --query "ipAddress" -o tsv)
echo "Network Interface public  IP :" $network_interface_pub_ip

Setup CoreDNS

wget https://github.com/coredns/coredns/releases/download/v1.6.9/coredns_1.6.9_linux_amd64.tgz
tar zxvf coredns_1.6.9_linux_amd64.tgz
ls -al
chmod +x coredns
./coredns -version

# /etc/coredns/Corefile
vim Corefile

.:53 {
    bind 172.16.2.5 # Private IP ov the DNS server VM
    forward . 168.63.129.16
    log
    errors
    cache
}

sudo ./coredns -dns.port=53

Modify DNS on your Windows 10 client :

From CMD as admin
netsh and press Enter
netsh> prompt, type interface ip show config, then press Enter
interface ip set dns "Ethernet0" static 172.16.2.5 and press Enter. Replace Ethernet0 with the name of your connection and 172.16.2.5 with the DNS server you want to use.

Get-NetIPConfiguration
Set-DnsClientServerAddress -InterfaceIndex 8 -ServerAddresses 192.168.1.254, 172.16.2.5

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Karishma-Tiwari-MSFT commented 4 years ago

We will close this issue as it is a duplicate of https://github.com/MicrosoftDocs/azure-docs/issues/57086 Our team experts will help you out on that issue.