Edit

Share via


Custom DNS configuration in Azure Linux Virtual Machines

Applies to: ✔️ Linux VMs

This article provides instructions to configure custom DNS servers and search domains on Microsoft Azure Linux virtual machines (VMs).

Note

This article uses DNS servers 1.2.3.4 and 5.6.7.8 and search domain "test.example.com" as examples. Replace these values with your actual DNS server addresses and search domain path.

Configure custom DNS servers

  1. The initial configuration of the /etc/resolv.conf file in an Azure Linux VM is as shown in the following screenshot.

    Screenshot of default resolv.conf file in RHEL.

  2. Configure custom DNS servers at the Azure virtual network or network interface level. For more information, see Steps to change DNS servers at virtual network/network interface level.

    Note

    In Azure, you can set custom DNS servers at the virtual network level or the network interface level. If you set custom DNS servers at the network interface level, it will override the the custom DNS servers configuration in the virtual network.

  3. Restart the NetworkManager service, and then check the /etc/resolv.conf file. The file should contain the DNS servers that you configured in the step 2.

      sudo systemctl restart NetworkManager
    

    The following screenshot shows an example of /etc/resolv.conf after you configure the DNS servers.

    Screenshot of resolv.conf file post changing the DNS servers at portal level.

  4. Run the following command to determinate whether the DNS servers are successfully added to the network interface:

    sudo systemd-resolve --status
    

    The following screenshot shows an example of the network interface after you configure the DNS servers.

    Screenshot of command's partial output.

Configure search domains

  1. To change the search domain, add the domain name as follows in /etc/dhcp/dhclient.conf. To specify multiple search domains, separate them by using commas (for example: "test.example.com, test1.example.com, test2.example.com"):

    append domain-search "test.example.com";
    

    Example of /etc/dhcp/dhclient.conf file after you add the search domain:

    Screenshot of dhclient.conf file post modification.

  2. Restart the NetworkManager service, and then check whether the search domain is updated in /etc/resolv.conffile:

    sudo systemctl restart NetworkManager
    

    The following screenshot shows an example of /etc/resolv.conf file after you configure the search domain.

    Screenshot of resolv.conf file after restarting NM service.

  3. Run the following command to determinate whether the search domain is successfully added to the network interface:

    sudo systemd-resolve --status
    

    The following screenshot shows an example of the network interface after you configure the search domain.

    Screenshot showing the search domain.

Contact us for help

If you have questions or need help, create a support request, or ask Azure community support. You can also submit product feedback to Azure feedback community.