Setting up DNS on Debian & Ubuntu

How to change DNS servers on Debian/Ubuntu.

DNS (Domain Name System) is the system that translates human-readable domain names (like google.com) into IP addresses that computers use to connect to servers. Public DNS servers such as Google Public DNS and Cloudflare can be useful in these cases:

  • Access issues: Your ISP’s DNS servers may be slow, unreliable, or block certain sites.
  • Privacy & speed: Third-party DNS providers often offer faster resolution, better privacy, and even malware filtering.
  • Geo-restrictions: Some services may behave differently depending on the DNS server used.

On VPS or dedicated servers running Debian/Ubuntu, the /etc/resolv.conf file is commonly edited manually to use faster, more reliable, or privacy-focused DNS servers instead of the ones provided by your hosting provider or ISP.

Step 1: Open the resolv.conf file

Use any text editor, for example nano:

sudo nano /etc/resolv.conf

Step 2: Update the nameserver lines

Replace or add the desired DNS servers in the nameserver lines. Here are some popular public DNS options:

Google Public DNS
nameserver 8.8.8.8
nameserver 8.8.4.4

Cloudflare DNS
nameserver 1.1.1.1
nameserver 1.0.0.1

Quad9
nameserver 9.9.9.9
nameserver 149.112.112.112

Example of a complete file:

Optional settings (can be kept or removed)
options rotate
options timeout:2
options attempts:1

Optional settings (can be kept or removed)
nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 8.8.8.8

Step 3: Save the changes

In nano:

  • Ctrl+O → Enter (to save)
  • Ctrl+X (to exit)

Step 4: Apply the changes

Restart the DNS resolver or update the cache:

sudo systemctl restart systemd-resolved

or (if using resolvconf):

sudo resolvconf -u

Verify that DNS is working:

nslookup google.com

or

dig google.com

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Need help?Our engineers will help you free of charge with any question in minutesContact us