10.4: How to set up a wildcard DNS

Nov 08, '05 05:26:00AM

Contributed by: hagus

Tiger only hintI like to use a wildcard DNS entry for my localhost. The reason? If I want to establish a new virtual domain in Apache for testing, I need only go in and create my own arbitrary virtual domain (like railsdev.localhost), and the DNS side will "just work." On Linux machines, you can just edit /etc/hosts and put a *.localhost entry in. This didn't appear to work on OS X, so I instead enabled a local nameserver and went down that path.

I gathered hints from various parts of the net when it came to enabling DNS on OS X Tiger, and I think I have found the most efficient way to do that.

First up, run the following commands to generate a rndc.conf and key file. You can disable this stuff in /etc/named.conf if you like; otherwise:

$ rndc-confgen > /etc/rndc.conf 
$ head -n 6 /etc/rndc.conf > /etc/rndc.key
Now you need to add the wildcard record to the localhost zone file. To do this, add the following line to the end of /var/named/localhost.zone:
*       IN      A
In OS X Tiger, daemons like named are controlled via launchctl. There is a simple XML configuration file called org.isc.named.plist, which you'll find in /System/Library/LaunchDaemons. The first few lines are listed here:
<plist version="1.0">
Simply change the true/ bit to false/ to enable named. You can then use launchctl to bounce this process:
$ launchctl stop org.isc.named   
$ launchctl unload org.isc.named.plist
$ launchctl load org.isc.named.plist
$ launchctl start org.isc.named
Don't worry if the first two lines give you an error.

In previous versions of OS X (prior to 10.4.3), there was a bug where launchd may have run named before all network interfaces were up. This could create a situation where named binds only to localhost; a problem if you expect your named to be accessible to external machines. This has apparently been fixed in 10.4.3, but I have not verified it, as it's not that important to me.

The final thing you must do is set your TCP/IP preferences to check first before other nameservers. You could optionally edit /etc/named.conf, and set up forwarders. However, because I move between networks all the time, I have just left this alone.

Hope this helps!

Comments (18)

Mac OS X Hints