Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've followed these instructions for setting up a local DNS server on my mac, and using it to server wildcard subdomains on localhost. It's a really nice thing:

http://mikeferrier.ca/2011/04/04/setting-up-wildcard-dns-on-localhost-domains-on-osx/

One weakness, though: I'm sometimes trying to work offline, and the local BIND instance is only consulted when you have a live connection with 127.0.0.1 in the DNS server list.

Is there a way to achieve this effect offline?

share|improve this question
    
127.0.0.1 is offline. You can always connect to 127.0.0.1 = localhost. The only thing you need is the loopback interface aka localhost aka 127.0.0.1. I'm not an osx buff, and I don't have enough cred here to make a comment... What exactly is meant by "work offline"? A safari mode? –  Ярослав Рахматуллин Jun 16 '11 at 12:43
    
I'm working on a site that uses subdomains-- using that trick above, I can fake that on localhost, so I have one.mydomain.local, and two.mydomain.local, etc, all resolving to 127.0.0.1. But it only works when I have an active connection. By offline, I just mean not connected to any network –  Ross M Karchner Jun 17 '11 at 2:59
    
just make sure "lo", the loop-back is up. ifconfig lo up or whatever (where whatever is something like ifconfig 127.0.0.1 lo up; route add -net 127.0.0.0 gw 127.0.0.1 netmask 255.0.0.0 -- but you should not have to do this manually) –  Ярослав Рахматуллин Jun 17 '11 at 3:11
    
Localhost is fine-- what I want is my locally running instance of BIND to be consulted for domain lookups, even when I'm not online. –  Ross M Karchner Jun 17 '11 at 11:08
    

3 Answers 3

The thread A small bit of hardware hacking == No Wi-Fi suggests using a hardware loopback device ($6.79 on Amazon).

This might be a solution to trick OS X into thinking it has a valid network connection.

This also requires using a static IP address, since there is no DHCP server.

image

share|improve this answer
    
I'm buying it now to see if this works. Have you actually tried this, along with the local DNS thing? –  Barnabas Kendall Jul 4 '11 at 22:07
    
Hope this works for you. But no, I never had this problem, nor a Mac. Did you try just connecting a network cable to the card and using a static IP? –  harrymc Jul 5 '11 at 5:59
    
This is interesting-- but there has to be a software solution, right? –  Ross M Karchner Jul 6 '11 at 16:49
    
Hmmmm.... maybe. –  harrymc Jul 6 '11 at 17:40

Perhaps I am missing something, but you seem to be overlooking the /etc/hosts file completely. Unix operating systems will reference /etc/hosts before making DNS requests. localhost resolves to 127.0.0.1 because it is specified so in /etc/hosts!

http://en.wikipedia.org/wiki/Hosts_%28file%29

You can edit /etc/hosts with any text editor, but you'll need root privileges.

sudo open -a TextEdit /etc/hosts

127.0.0.1 one.mydomain.local
127.0.0.1 two.mydomain.local
127.0.0.1 example.com subdomain.example.com
share|improve this answer
    
The idea is to not have to manually tend /etc/hosts-- I want anything.local to resolve to 127.0.0.1 –  Ross M Karchner Jul 7 '11 at 14:38
    
/etc/hosts is not very helpful when you're developing sites that use dynamic subdomains, like username.example.com. On my local DNS server I have a zone for *.dev so if I just rename ".com" to ".dev" then it goes to my localhost server. –  Andrew Vit Jul 31 '11 at 21:05

You need to set your resolver configuration to use 127.0.0.1 for that local domain:

sudo mkdir /etc/resolver
sudo vim /etc/resolver/local

Add the following lines to the /etc/resolver/local configuration:

nameserver 127.0.0.1
search_order 1

The name of the configuration file "local" is the name of your search domain. (Mine happens to be "dev"; if you followed that tutorial, yours would be "local".)

You can then go into your System Preferences / Network configuration and remove the custom DNS server you had set there for 127.0.0.1. The above resolver configuration means your localhost DNS will only be consulted for "local" domains.

More details in this helpful serverfault answer.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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