I have a laptop running Ubuntu 16.04 connected to two different networks (in fact, I have 5 different laptop models all experiencing this). One is a wireless network the other one isn't. On these two networks I have different DNS servers.

I regularly experience that when attempting to ping or establish an ssh connection to a known host, I get a 'unknown host' error, I can run five ping commands a second apart, and sometimes all five get through, sometimes only one or two (or none). I experience the same when I use 'nslookup' on a hostname. When using SSH with an IP address, I never receive any errors. This leads me to believe that Ubuntu randomly selects which networks' DNS server to use.

So is there a way to select which networks' DNS server should be used, or have Ubuntu ask both of them, provided one of them doesn't know the host?

'ip route list' lists different metrics for the networks, with one set to 100 and one to 600.

If there is any other information that might be relevant, please let me know.

The contents of /etc/resolv.conf:

Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
search xx.yy.zz

Output of ip route list

default via dev enp0s25 proto static metric 100
default via dev wlo1 proto static metric 600 dev enp0s25 proto kernel scope link src metric 100 dev wlo1 proto kernel scope link src metric 600 via dev enp0s25 proto dhcp metric 100 dev enp0s25 scope link metric 1000 via dev wlo1 proto dhcp metric 600

user@host:~$ nmcli dev show enp0s25 | grep DNS

user@host:~$ nmcli dev show wlo1 | grep DNS
  • What you need is to look into your /etc/resolv.conf
    – Ziazis
    May 31, 2017 at 6:31
  • It says nameserver and it has a search domain. What am I looking for? For clarification, I don't want to specify a specific DNS server, I want to specify which network to grab the DNS server info from.
    – Tobias
    May 31, 2017 at 9:42
  • There you have your issue, your dhcp server doesn't provide an dns server. Either add a manual one or configure your dhcp server correctly to give one on each network. For trial you can add this line into the resolv.conf and see if it works nameservers 192.168.x.x 10.x.x.x (adjust to your own needs) and test if it works now. If it works you know that your dhcp server is not set up correctly
    – Ziazis
    May 31, 2017 at 9:50
  • @Ziazis I appreciate the effort but that is not true. Both networks supply a DNS server. nmcli dev show [device] clearly show a nameserver for both networks. Also, if I didn't have a nameserver it would not works ome of the time.
    – Tobias
    May 31, 2017 at 9:54
  • Just a check, do you have by chance installed dnsmasq or something it's own other dns server on the machine?
    – Ziazis
    May 31, 2017 at 10:13

1 Answer 1


Ubuntu itself always uses all it's DNS'. If it doesn't find one address on the first DNS it will try the second one that is available to it.

So your solution is, since we saw that your /etc/resolv.conf is empty - but you provided information that you have a DNS server correctly distributed by your dhcp.

Now you can either disable NetworkManager and just use the interfaces which would fix your issue right away or you look into your /etc/NetworkManager/NetworkManager.conf and look for the line dns=XXXXXX and delete that line or comment that line out.

Restart your NetworkManager sudo systemctl restart NetworkManager.service and now your DNS should be set in /etc/resolv.conf

  • 2
    I won't accept a solution that involves disabling NetworkManager, but I will try removing the DNS=dnsmasq line from NetworkManager.
    – Tobias
    May 31, 2017 at 10:55
  • 1
    Removing dns=dnsmasq from /etc/NetworkManager/NetworkManager.conf does it indeed add both DNS servers to /etc/resolv.conf (and also prioritises the right one) and the behaviour is as expected and wanted. For the record, this was a clean Ubuntu setup, so dnsmasq is default. The package 'dnsmasq' is not installed, but there is a dnsmasq process running. Can't explain where it comes from.
    – Tobias
    May 31, 2017 at 11:09
  • In my case not all DNS servers are queried. It stops at the first server that answers. There are three DNS servers on my WLAN connection (I have no influence on this), where the servers #1 and #2 fail. Server #3 answers, but doesn't know the name. The only DNS server for my ethernet connection may answer this name, but is not queried. After setting this server into /etc/resolvconf/resolv.conf.d/head (which isn't recommended), it works!
    – Nicolas
    Jun 5, 2018 at 11:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .