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 '17 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 '17 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 '17 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 '17 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 '17 at 10:13

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

| improve this answer | |
  • 1
    I won't accept a solution that involves disabling NetworkManager, but I will try removing the DNS=dnsmasq line from NetworkManager. – Tobias May 31 '17 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 '17 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 '18 at 11:15

I think you are missing the static routing on both network cards because the model you are using requires static routing at network card level.

You can edit your network interfaces like given below:

auto eth1

iface eth1 inet static



post-up route add via dev eth1

auto eth2

iface eth2 inet static



post-up route add via dev eth2

in this way it will route the queries to different networks.

| improve this answer | |
  • I presume this goes in /etc/network/interfaces - will it work with networkmanager? I'm not sure what setting up a static route exactly means, but surely it's not going to work with those addresses you wrote? I haven't told you any addresses from my network. Is this an attempt to 'reroute' queries sent to one of the servers to the other? – Tobias May 31 '17 at 6:12
  • yes this will goes in /etc/network/interfaces. These are the private addresses and they are used as example. You need to modify these addresses according to your network. – azhar buttar May 31 '17 at 7:12
  • Alright, but could you please explain what it will do? I'd prefer not to apply something I don't understand. I don't know what it means that 'the model I am using requires static routing at network card level'. When I use IP addresses rather than DNS, I don't have any routing issues at all. – Tobias May 31 '17 at 9:41
  • You are using two different networks, this means there will be two different DNS. It will route the queries to specific systems on the specific networks. Lets say you are trying to connect to a system which is connected to the network of eth1. The static route will help you find the system using eth1. same will happen in the case of other network. – azhar buttar May 31 '17 at 10:00
  • But when I connect to something on 'eth1', sometimes it uses the DNS server from 'eth1', sometimes it uses the DNS server from 'eth2', I can ALWAYS get a route to the destination, it's only the DNS query that's the problem. – Tobias May 31 '17 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.