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

103,713

Solution 1

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.

Solution 2

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.

Solution 3

Put the search line after the nameserver lines.

Share:
103,713

Related videos on Youtube

SomeGuyOnAComputer
Author by

SomeGuyOnAComputer

Updated on September 18, 2022

Comments

  • SomeGuyOnAComputer
    SomeGuyOnAComputer over 1 year

    I'm running Ubuntu 12.04 and I'm trying to ping the following systems:

    • system0.oldcompany.com
    • system1.fing.oldcompany.com
    • system2.newcompany.com
    • system3.thing.newcompany.com

    My resolv.conf

    # internal dns servers
    nameserver 1.1.1.151
    nameserver 1.1.1.152
    search oldcompany.com fing.oldcompany.com newcompany.com thing.newcompany.com
    #domain thing.newcompany.com
    domain oldcompany.com
    #domain fing.oldcompany.com
    #domain newcompany.com
    #nameserver 8.8.8.8 #commented out due to other issues
    

    If I leave all of those lines uncommented, I won't be able to ping system0 or system1. How do I set it up so I can ping all 4 systems by just using its domain name? In Windows, it resolves every system.

    ping system0
    ping: unknown host system0
    ping system1
    ping: unknown host system1
    

    I've been trying to read the man page on resolv.conf but I'm still having issues troubleshooting this problem. No one at my company uses Linux so unfortunately so I'm on my own.

    Edit: Updated search so it's only 1 line and now I can ping system0 but still cannot ping system1. However, I can ping system1.fing because it's on the oldcompany domain.

  • SomeGuyOnAComputer
    SomeGuyOnAComputer over 9 years
    Hi webmarc, I have all of my search domains on one line and only specified one domain but still have issues with system1. It does not seem to search the fing.oldcompany.com subdomain correctly.
  • SomeGuyOnAComputer
    SomeGuyOnAComputer about 9 years
    Hi. I tried your suggestion and updated the resolv.conf in my post. The issue still exists. I noticed that if I switch my domain from the oldcompany.com to newcompany.com, then I can ping system2 but then I cannot ping system0...