Skip to main content

Setting DNS for an Ubuntu VPS?

Open the /etc/resolv.conf file in a text editor with the command

sudo nano /etc/resolv.conf

Add your custom DNS servers to the file, one per line, using the following format:

nameserver 178.22.122.100
nameserver 185.51.200.2

Save the changes to the file and exit the text editor.

Note that any changes made to the /etc/resolv.conf file may be overwritten by other processes or tools that manage the network configuration. To ensure that your custom DNS servers are used persistently, it's recommended to use the /etc/netplan/01-netcfg.yaml file instead.

 

 

Clearing Cache

To clear the network cache and ensure that your new DNS settings are used, you can follow these steps:

  1. Flush the DNS resolver cache by running the command sudo systemd-resolve --flush-caches. This will clear the cache for the systemd-resolved service, which is used by default in recent versions of Ubuntu.

  2. Restart the systemd-resolved service by running the command sudo systemctl restart systemd-resolved. This will restart the service and reload the DNS configuration.

  3. Restart any applications or services that rely on DNS resolution, such as your web browser or web server, to ensure that they use the new DNS settings.

After completing these steps, your Ubuntu VPS should be using the new custom DNS servers that you configured.

 

Making sure that the DNS is working

resolvectl status