How to Change DNS in Ubuntu

The Domain Resolution Override Vector

When you deploy a headless Ubuntu server on a standard corporate or residential network, the DHCP protocol mathematically forces the machine to utilize the ISP’s default DNS servers (e.g., Comcast or Vodafone’s internal routing tables). These default resolvers are frequently mathematically slow, actively censor specific domains, and log your telemetry. If you demand a sterile, hyper-fast, and secure networking matrix, you must instruct the core Linux kernel to bypass the DHCP provision and explicitly force all domain resolution requests through a mathematically superior third-party architecture (like Cloudflare’s `1.1.1.1` or Google’s `8.8.8.8`).

How to Change DNS in Ubuntu

In modern Ubuntu architectures (18.04 LTS and later), the legacy `/etc/resolv.conf` file is a mere symlink managed by `systemd-resolved`. You cannot manually edit it without the system overwriting your changes upon reboot. You must execute the configuration injection via the master `Netplan` utility.

1. Open your terminal application or connect to the server via SSH.
2. Phase 1: Summon the Master Netplan Configuration:
* The Netplan architecture defines network states using highly rigid YAML files. You must locate the active configuration block.
* Type exactly:

ls /etc/netplan/

* Press Enter.
* Identify the exact alphanumeric name of the `.yaml` file (e.g., `01-network-manager-all.yaml` or `50-cloud-init.yaml`).
* Type exactly (replacing the filename with yours):

sudo nano /etc/netplan/50-cloud-init.yaml

* Press Enter.
3. Phase 2: The YAML Injection (Defining the Nameservers):
* The terminal will render the active YAML matrix. YAML relies on mathematically precise indentation (spaces, never tabs).
* Locate your primary network interface (e.g., `eth0` or `enp3s0`).
* Directly beneath the `dhcp4: true` (or static IP block), you must inject the `nameservers` block.
* Carefully type the following, ensuring the indentation aligns perfectly with the interface parameters:
nameservers:
addresses: [1.1.1.1, 1.0.0.1]
* (This specific mathematical sequence forces the kernel to route all queries through Cloudflare’s secure matrix).
* Press Ctrl + O (Write Out), press Enter to confirm, and Ctrl + X to exit.
4. Phase 3: The Execution Trigger (Compiling the Netplan):
* The kernel will not recognize the new parameters until you instruct Netplan to compile the YAML logic.
* Type exactly:
sudo netplan apply
* Press Enter.
5. Phase 4: The Verification Handshake:
* To mathematically prove the core OS is utilizing the new resolution matrix.
* Type exactly: resolvectl status
* Check the output for your primary interface. The “DNS Servers” line must explicitly read `1.1.1.1`.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.