1

I have a Mac OS X Snow Leopard Server as my network router. Is it possible to set a global host in its /etc/hosts file, like:

127.0.0.1      www.foo.bar

that redirects all requests (e.g. browsing www.foo.bar) from the whole network to that IP? So I don't have to set it at all client machines?

2 Answers 2

2

The hosts file is simply something local to a machine.

Therefore, if you have a computer that queries www.foo.bar, it will first look in its host file, find nothing then query its DNS server. The DNS will look in its local zones, find nothing and send a recursive query (?... need to double check) to it's linked DNS servers and then if it finds nothing, it will send a query to the root zones.

At no point are DNS services on a machine influenced by their own hosts file. So if you add it, it will simply be for the server and only the server.

That being said, IF that server is the DNS server for the network, you can easily insert a new zone for foo.bar and an A/Cname record for www or just *, followed by a value of 127.0.0.1, this should do what you want for the entire network.

1

Not generally. Resolving is done on the host -- meaning if you lookup www.foo.bar on machine A, it's machine A's resolving rules that determine the IP for that address, not the router's.

Machine A will check its own hosts file, and then it'll check with DNS. (Other resolving systems could be in use.)

If your router serves as the local DNS for your network, then you can enforce this -- either through local zone records, if you are using a full-on DNS server like BIND, or by specially configuring a caching DNS server like DNSmasq to check its local hosts file first.

For DNSmasq (commonly used on OpenWRT and DD-WRT router firmwares), add expand-hosts to the /etc/dnsmasq.conf file to enable this functionality.

You must log in to answer this question.