How to be able to resolve multiple domains using /etc/resolv.conf on Linux?

After following @webmarc and @dan-hook, it wasn't working until I removed the domain line which I still quite don't fully understand.

According to this answer, the domain becomes the first search string. I find it easier to just not use the domain string.

Steps:

  1. All search domains are put on a single line
  2. domain line(s) were removed
  3. New company domains were placed before the old company names

This is my new /etc/resolv.conf and it works perfectly.

# internal dns servers
nameserver 1.1.1.151
nameserver 1.1.1.152
search newcompany.com thing.newcompany.com oldcompany.com fing.oldcompany.com

Also if your /etc/resolv.conf will be overwritten then modify /etc/network/interfaces

auto eth0
iface eth0 inet static
    address 10.59.2.50
    netmask 255.255.255.0
    gateway 10.59.2.1
    dns-nameservers 1.1.1.151 1.1.1.152
    dns-search newcompany.com thing.newcompany.com oldcompany.com fing.oldcompany.com

If the new company has a new dns server IP, make sure that IP also comes before the old company's so that the new dns servers get queried first.


There's a few problems with your file:

  1. There should only be one search line like search domain.com domain2.com domain3.com up to 6 domains.
  2. There should only be one domain line with exactly 1 domain specified.

After you fix those, see if you still have problems and update your question if so.

You can find information on the required format of this file in the man page.


Put the search line after the nameserver lines.