Search

Resolve DNS name in ubuntu

Enabling Active Directory DNS Resolution on Ubuntu

Problem Statement: An Ubuntu VM needs to communicate with several Windows VMs that are members of an Active Directory (AD) domain. While the Windows machines can resolve each other's hostnames via the Domain Controller, the Ubuntu VM fails to resolve these DNS names, preventing seamless connectivity.

Objective: Configure the Ubuntu VM to use the Active Directory Domain Controller (DC) as its primary DNS server for name resolution.

Technical Solution: Updating the Nameserver

To allow Ubuntu to "see" the AD environment, you must point its DNS configuration to the IP address of the Domain Controller.

1. Identify the DNS IP

On any of your Windows VMs already in the domain, find the DNS server IP (usually the IP of your Domain Controller).

2. Update the Configuration

In Linux, DNS resolution is primarily handled by the resolv.conf file. You need to add your AD DNS IP to this file.

  • File Path: /etc/resolv.conf

  • Action: Add a nameserver entry at the top of the file.

Example Entry

nameserver 192.168.1.10  # Replace with your AD DNS IP
search yourdomain.local  # Optional: allows resolution of short names

Modern Ubuntu versions (18.04 and later) use a service called systemd-resolved. If you manually edit /etc/resolv.conf, your changes might be overwritten after a reboot.

For a permanent fix, it is usually better to:

  1. Edit the Netplan configuration in /etc/netplan/.

  2. Or, use systemd-resolved by linking the file:

    ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

  3. Note: If you are in a production environment, ensure that your AD DNS server is also configured to "Forward" requests to a public DNS (like 8.8.8.8) so your Ubuntu VM doesn't lose general internet access while searching for the domain.

Specific Netplan commands to make this DNS change permanent

IF you're working with a modern version of Ubuntu (like 20.04, 22.04, or 24.04), using Netplan is the most reliable way to ensure your DNS settings survive a reboot.

Here is how to apply the fix permanently:

1. Locate your Netplan Configuration

Netplan configuration files are YAML files located in /etc/netplan/. Run this command to find the filename:

ls /etc/netplan/

(Common filenames are 01-netcfg.yaml, 50-cloud-init.yaml, or 00-installer-config.yaml.)

2. Edit the File

Open the file with root privileges (replace filename.yaml with your actual file name):

sudo nano /etc/netplan/filename.yaml

3. Add the DNS/Nameserver Info

Update the nameservers section under your network interface (usually eth0 or ens33). It should look like this:

YAML
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      nameservers:
        addresses: [192.168.1.10, 8.8.8.8] # Your AD DNS IP first, then a backup
        search: [yourdomain.local]         # Your AD Domain name

4. Apply the Changes

Save the file (Ctrl+O, Enter) and exit (Ctrl+X). Then, run:

sudo netplan apply

How to Verify the Fix

Once applied, you can check if Ubuntu is actually talking to your Active Directory DNS by running:

resolvectl status

Look for the "DNS Servers" section under your active interface to confirm your AD IP is listed.