How do I change my DNS on Ubuntu 18.04? Which DNS should I use?

6,771

Solution 1

First, I recommend that you install namebench.

namebench searches the fastest DNS servers available for your computer to use. namebench runs a fair and thorough benchmark using your web browser history, tcpdump output, or standardized datasets in order to provide an individualized recommendation.

Install namebench from the terminal:

sudo apt update && sudo apt install namebench

Start the program:

namebench

namebench makes thousands of queries and takes a few minutes to complete; please be patient. When it completes, a report will be prepared that illustrates the fastest available nameservers. Here is a sample from my machine:

Saving report to /tmp/namebench_2018-12-24_1436.html

When we examine the saved report, we see:

enter image description here

Once you know the two or three most ideal nameservers, apply them in Network Manager's settings like this:

enter image description here

Turn DNS Automatic to off. Insert the IP addresses of the preferred nameservers, seperated by commas, click Apply and close.

Solution 2

Does changing DNS result it a more secure web experience?

Yes, only if you do not trust your network provider. In which case, you can set up DNS. I actually use Google DNS, as this is generally faster.

Normally OpenDNS and GoogleDNS are faster than provider DNS.

However, there is a catch. If your network is such that it requires you to login before you can access the internet (like in airports, some cafes, co-working spaces), then they might not work if you overwrite the provider's DNS settings, as their authentication process depends upon DNS.

There is, however a very good solution available. You setup DNS per connection.

  1. Right click on the network manager icon in the panel and choose "Edit connections..."
  2. Select your connection from the wired or wireless tab, choose "Edit"
  3. (Enter your password if the connection is set as "system-wide available")
  4. Choose IPv4 settings tab
  5. Switch method to "Automatic (DHCP) addresses only"
  6. Enter the name server you want in the box "Additional DNS servers" and press "Apply"

Network Configuration Window

Finally, for the command line oriented: Open the connection file in Network Manager. For example, if the WiFi Name is Tarzan, then look for a file (case sensitive):

/etc/NetworkManager/system-connections/Tarzan

In that file, make sure the ipv4 block is like this:

[ipv4]
dns=8.8.4.4;8.8.8.8;
dns-search=
ignore-auto-dns=true
method=auto

replace 8.8.4.4;8.8.8.8; with your DNS servers.

 method=auto

This instructs NetworkManager to use DHCP to get IP address for the interface.

 ignore-auto-dns=true

This instructs NetworkManager to ignore the DHCP provided DNS servers.

That should do the trick.
You need to do that for every WiFi AP that you connect to.

PS: Google DNS are 8.8.8.8 , 8.8.4.4

Share:
6,771

Related videos on Youtube

Akane Yoshinega
Author by

Akane Yoshinega

She lives, reads books, will die too. Oh and she fell in love for linux.

Updated on September 18, 2022

Comments

  • Akane Yoshinega
    Akane Yoshinega over 1 year

    I'm recently interested in DNS for a cleaner, faster & more secure Internet surfing. In my country many websites are obscured and I was told that changing DNS may allow me to use them as I did before. I also don't like to share my metadata with others and some DNSs, such as the ones provided by OpenDNS, seem to provide more privacy to the user.

    Is it true that changing DNS results in a more secure web experience?

    How do I change DNS on Ubuntu 18.04, and most importantly, which DNS should I switch to?

  • Akane Yoshinega
    Akane Yoshinega over 5 years
    I'm looking forward to try this on my pc!
  • chili555
    chili555 over 5 years
    If my answer has been helpful, please accept it: askubuntu.com/tour The searchers will appreciate it.
  • Akane Yoshinega
    Akane Yoshinega over 5 years
    I wan unable to install namebench. It says: E: Unable to locate package namebench
  • chili555
    chili555 over 5 years
    Which Ubuntu version? lsb_release -d Are you quite sure that you first ran: sudo apt update?
  • Akane Yoshinega
    Akane Yoshinega over 5 years
    Ubuntu 18.04.1 LTS, yes I ran sudo apt update and i even tried with sudo apt-get update
  • chili555
    chili555 over 5 years
    Under Software and Updates, is the repository Universe activated?
  • Akane Yoshinega
    Akane Yoshinega over 5 years
    It improved the situation, but now the terminal says: Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:
  • Akane Yoshinega
    Akane Yoshinega over 5 years
    And: The following packages have unmet dependencies. namebench : Depends: python-dnspython but it is not installable Depends: python-httplib2 but it is not installable Depends: python-jinja2 but it is not installable Depends: python-simplejson but it is not installable Recommends: python-tk but it is not installable E: Unable to correct problems, you have held broken packages.
  • chili555
    chili555 over 5 years
    Please make certain that, under Software and Updates, main, universe, restricted, and multiverse are activated. Then again run: sudo apt update and then: sudo apt install namebench.
  • Akane Yoshinega
    Akane Yoshinega over 5 years
    Thanks! You were right! That worked well and I managed to install namebench!
  • Akane Yoshinega
    Akane Yoshinega over 5 years
    I edited the server's name in the box "Additional DNS servers", but when I try to do a benchmark with namebench it keeps reporting my old primary server's number instead of the new OpenDNS's one.
  • Domo N Car
    Domo N Car over 5 years
    @AkaneYoshinega Switch Method to "Automatic (DHCP) addresses only"; the Other (or Additional) DNS Servers will change to DNS Servers. These are the servers then the system will use. I have updated the answer with an image of the window.
  • Bruno Ranschaert
    Bruno Ranschaert almost 5 years
    Do not forget to restart the interface by turning it off - on so that the new settings take effect.
  • krubo
    krubo over 3 years
    How to get to that NetworkManager settings screen?