This guide explains how to change the DNS resolution servers on your virtual private server (VPS). DNS servers are essential for translating domain names (like pulseheberg.com) into IP addresses that your server can use to connect to other services on the Internet.

Debian-based operating systems (Debian, Ubuntu)#

Modern Debian-based distributions, including Ubuntu 18.04 and later, use Netplan to manage the network configuration. Directly editing the /etc/resolv.conf file is not persistent because Netplan generates it automatically.

Steps to change the DNS via Netplan#

  1. Locate the Netplan configuration file: The configuration files are located in the /etc/netplan/ directory and usually end with .yaml. You can list the files with the command:

    ls /etc/netplan/

    The file name may vary (for example, 01-netcfg.yaml, 50-cloud-init.yaml, etc.).

  2. Edit the configuration file: Open the file with a text editor such as nano or vim.

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


3.  **Add the DNS servers**: Locate the configuration of your network interface (usually `eth0` or `ens3`).

In the `nameservers` section, add the addresses (`addresses`) of your new DNS servers. If the `nameservers` section does not exist, you can add it.

Here is an example configuration:

```yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]

In this example, we use the DNS servers of Google (8.8.8.8) and Cloudflare (1.1.1.1). Replace them with the ones of your choice.

  1. Apply the new configuration: For the changes to take effect, run the following command:

netplan apply


5.  **Verify the changes**: You can check that the new DNS servers are being used with the command:

netplan status


You should see the IP addresses you just configured.

-----

## Red Hat-based operating systems (Rocky Linux, RHEL, AlmaLinux)

On Red Hat-based systems, network management is usually handled by **NetworkManager**. The simplest and safest way to change the DNS is to use the command line tool `nmcli`.

### Steps to change the DNS via nmcli

1.  **Identify the name of your network connection**: List the active connections to find the name of your main interface.

nmcli connection show


The name is often `ens3` or `eth0`.

2.  **Change the DNS servers**: Use the `nmcli` command to set the new DNS servers. Replace `ens3` with the name of your connection and the IP addresses with the ones of your choice.

nmcli con mod ens3 ipv4.dns "8.8.8.8 1.1.1.1"


This command configures the DNS servers for IPv4. For IPv6, the syntax is similar:

nmcli con mod ens3 ipv6.dns "2001:4860:4860::8888 2606:4700:4700::1111"


3.  **Apply the changes**: For the new configuration to be taken into account, reactivate the connection.

nmcli con down ens3 && nmcli con up ens3


4.  **Verify the configuration**: Check the `/etc/resolv.conf` file to see if your new DNS servers appear there.

cat /etc/resolv.conf


The file should now contain the `nameserver` entries you configured.