Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use different DNS servers for different domains Network
This hint is about DNS routing, i.e. redirecting requests to different DNS servers based on domain name.

Sometimes it's good to have separate DNS servers for different domains. For example, you may want to have a local default DNS server on your laptop and use it for all Internet-related DNS lookups, and use your office DNS servers for all intranet domains resolving when at work. There are an endless amount of possible configurations, and Mac OS X has a very nice and simple generic way to set up a DNS server's routing. In the simplest case, all you need to do is to create a text file in the directory /etc/resolver/ with the same name as the desired domain, and define the nameservers inside. Let's say your office network has local domain name foobar.com and DNS servers are 10.1.2.3 and 10.1.2.4. You create file /etc -> resolver -> foobar.com with content:
nameserver 10.1.2.3
nameserver 10.1.2.4 
and you're all set. From this moment on, all requests for foobar.com and its subdomains will go directly to specified servers, and all other requests will go to the default server in /etc/resolv.conf (this is the server you specify in the Network Preference panel). No need to mess with bind configuration and it will work as soon as file created without restarts, reboots, logouts and other radical enforcements.

Also you may need to setup a reverse-lookup for your foobar.com domain. Let's say your office IP space is 10.0.0.0/8 (ask your sysadmin if you don't know it). Then while in the /etc/resolver directory, copy the file foobar.com. to the file 10.in-addr.arpa, and from this moment on, all reverse-lookups for network 10.0.0.0/8 will go to the same servers. This is little more complex if you don't know how reverse DNS works, but another example may give you a hint. For subnet 192.168.0.0/16, you'll need to copy to file 168.192.in-addr.arpa and for 192.168.1.0/24, copy to 1.168.192.in-addr.arpa. If you're still unsure, ask your sysadmin, but don't tell him my name :). For more advanced users, type man 5 resolver in your Terminal, and you'll get a nice description of this mechanism. Also the name of file is not fixed -- you can use any name if you specify the option domain foobar.com as the first one in that file:
domain foobar.com
nameserver 10.1.2.3
nameserver 10.1.2.4 
But it should be in the /etc/resolver/ directory. So, you can have many configurations for the same domain -- this may be important for reverse lookups if you have overlapping address spaces for different networks (like 192.168.1.0/24 at home and 192.168.0.0/16 at work, for example). Read the man page for more details about search order and so on.

I tested different configurations for the resolver and have been using this feature for some time without any problems, but if you find any pitfalls leave a comment here -- this may save a sleepless night for some good innocent soul!
    •    
  • Currently 3.57 / 5
  You rated: 1 / 5 (7 votes cast)
 
[35,669 views]  

Use different DNS servers for different domains | 13 comments | Create New Account
Click here to return to the 'Use different DNS servers for different domains' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use different DNS servers for different domains
Authored by: club60.org on Jun 30, '04 11:07:52AM

Great hint!

Is it possible to make different settings for different locations?



[ Reply to This | # ]
Question
Authored by: sjonke on Jun 30, '04 11:24:54AM

Can this be used to resolve the problem that when on my home airport network, I can't go to a web page served on one of my home machines by using the outside address. I.e. let's say that http://photos.bozo.com from the outside world is directed to a particular machine on the local airport network (via port forwarding on the airport base station). From the outside using this address works great. But when on the local airport network, the address doesn't work. Instead I have to use the local numeric IP address to get to the page. 10.0.1.10, for example. I would like it to be the case that when on the local airport network the address photos.bozo.com would resolve to 10.0.1.10 instead of the outside world address of the base station.

---
--- What?



[ Reply to This | # ]
Question
Authored by: r0adrage on Jul 17, '04 06:04:34PM

I solved that for my home network by running my own DNS server specifically for requests within my house. I set up a zone file for the 10.x.x.x net, and for my domains with all of my hostnames mapped to the correct 10.x address. My DHCP server tells all clients to use my DNS server. So www.brokenvaporware.com maps to 10.0.1.1 (or whatever) for clients inside my network.

This is not the same as my primary and secondary DNS servers. Those still give out my cablemodem address, so people outside can still contact my hosts.

You could use the /etc/resolver/blah trick to have your computer look at your internal DNS server (instead of having the DHCP server give out its address), but you would still need a nameserver running to offer up your lan mappings.



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: bluehz on Jun 30, '04 11:43:39AM

Hmm.. thought I would give this a test, but not having any luck..

Internal lan (several mac os x machines, one slackware linux box with DNS server running)

e.g. myhome.lan is my internal domain, DNS is at 192.168.1.10

added /etc/resolver/myhome.lan

contents of myhome.lan:

nameserver: 192.168.1.10

and

/etc/resolver/1.168.192.in-addr.arpa

contents of 1.168.192.in-addr.arpa:

nameserver: 192.168.1.10

and then removed my dns server IP from the SysPref Pane. It should be able to locate items via their domain now. Not working though... I have no ability to identify any of the machines on the LAN and unless I specifically add my ISP DNS numbers - thats dead also (should be pulling that off the router). Normally I keep the IP of the linux DNS server in the Sys Prefs DNS field and that works fine. Once removed... dead.

Any suggestions?



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: atverd on Jun 30, '04 01:44:06PM

Try to remove colons ":" from your configs first - it should be just
----------
nameserver 192.168.1.10
----------



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: bluehz on Jul 02, '04 12:19:16AM

oops - no colons in the actual file - I added those by mistake when posting.



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: Gipetto on Jun 30, '04 01:01:19PM

Ok,
The hint makes sense for using it on my work domain, but I don't use a domain at home (and don't know many with their own domain controllers at home).

Since I'm on broadband, I hide behind my router, so I don't get a comcast.net domain attached to my IP. I'm simply 192.168.0.2
I also find my other machines by using their .local address. So it would help to know if we can apply this to work with a .local setup or how to make it work based solely on IP address.



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: Gipetto on Jun 30, '04 02:41:33PM

wait a minute, I think I misread the article.

This is for taking all requests, like for "apple.com" and having them resolve from a set of name servers, right?

I thought it would read the network domain (ie: mycompany.corp) and use certain name servers in that situation.



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: digitol on Jul 01, '04 04:14:30PM

BUMP in response to: Question
Authored by: sjonke on Wed, Jun 30 '04 at 11:24AM
Can this be used to resolve the problem that when on my home airport network, I can't go to a web page served on one of my home machines by using the outside address. I.e. let's say that http://photos.bozo.com from the outside world is directed to a particular machine on the local airport network (via port forwarding on the airport base station). From the outside using this address works great. But when on the local airport network, the address doesn't work. Instead I have to use the local numeric IP address to get to the page. 10.0.1.10, for example. I would like it to be the case that when on the local airport network the address photos.bozo.com would resolve to 10.0.1.10 instead of the outside world address of the base station.

---
--- What?



[ Reply to This | # ]
Re: Use different DNS servers for different domains
Authored by: sjk on Jul 01, '04 11:27:23PM

This is helpful, thanks! I'd wondered how to make use of the /etc/resolver directory but had a blind spot to checking the resolver(5) man page, duh.



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: kyngchaos on Dec 19, '05 01:50:12PM

(Reviving an old hint)

No luck with this. Tried both Panther and Tiger. Adding this resolver file has no effect on where Mac OS X looks for DNS. It always tries the first DNS server listed in the System Prefs-Network that is reachable, starting with the primary (builtin) ethernet. And reachable seems to mean the first network port that is active, without even trying to contact the DNS server.

So:

Builtin: network 192.168.1.x, foo.bar domain, DNS 192.168.1.100
Airport: network 192.168.2.x, nowhere.net domain, DNS 192.168.2.200
zaphod is a Mac on the nowhere.net network and has a DNS entry on 192.168.2.200

/etc/resolver/nowhere.net:
nameserver 192.168.2.200

if both network connections are active on the Mac, and both DNS servers are running, nslookup zaphod.nowhere.net returns domain not found, and says it tried 192.168.1.100 - not what I told it in the resolver file!

If both connections are active, but 192.168.1.100 is not reachable for some reason, nslookup times out trying to reach it, and doesn't try 192.168.2.200.

If the Builtin ethernet is disconnected, and wireless is connected, all lookups will go thru 192.168.2.200. zaphod.nowhere.net will just happen to work now.

It seems that some Mac OS X configuration thing must be overriding this resolver feature.



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: richonmaui on Mar 02, '06 07:31:04PM

Where is this directory /etc/ or /etc/resolver/ supposed to be? I don't seem to have either one on my G5 iMac.

Thanks

Rich

---
http://www.HawaiianRainbow.com



[ Reply to This | # ]
Use different DNS servers for different domains
Authored by: sjk on Mar 03, '06 01:01:52PM

Umm, your iMac wouldn't boot without the /etc (really /private/etc) directory. :-)

Certain system support folders (including /etc) are hidden from Finder by default. You can use "Go > Go To Folder..." (command-shift-G) to bring up a dialog and enter the path to a hidden folder you want to open. Or use Terminal.

Making modifications in system folders without adequately understanding the consequences (which unfortunately are often overlooked in "procedure-style" hints) can be risky. You might want to get some general familiarity with the contents of hidden directories before changing things that could disrupt the integrity of your system and/or network.



[ Reply to This | # ]