Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tannn

macrumors newbie
Original poster
Dec 10, 2008
6
0
Hey,

How / where can i set /etc/hosts or the hostfile to take priority over DNS. I have set some hostnames/ips up in the hostfile but the domain controller keeps taking precedence unless i dscacheutil -flushcache. Is there a comparable nsswitch.conf in Leopard?

i am looking for something similar to lookupd which is not available for 10.5 OS X.

cheers
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
Put the following in /etc/resolv.conf above your nameserver line:

order hosts, bind
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
Put the following in /etc/resolv.conf above your nameserver line:

order hosts, bind

Where did you find that? I have never seen that in resolv.conf.

Now, you can edit /etc/nsswitch.conf and make sure the line beginning with "hosts" has listed after it "files dns".
 

tannn

macrumors newbie
Original poster
Dec 10, 2008
6
0
resolv.conf is temporary, the second i reboot the system it erases the entry.

and, there is no nsswitch.conf in Mac OS X Leopard.
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
Where did you find that? I have never seen that in resolv.conf.

Now, you can edit /etc/nsswitch.conf and make sure the line beginning with "hosts" has listed after it "files dns".

It's a *nix convention. Google resolv.conf options. You'll see it.
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
resolv.conf is temporary, the second i reboot the system it erases the entry.

and, there is no nsswitch.conf in Mac OS X Leopard.

It's not technically temporary. dhcp clients overwrite resolv.conf. If you don't run dhcp, resolv.conf is persistent. If you have to use dhcp (and most people do), the next trick is to put a boot script that copies your adjusted resolv.conf to /etc after booting up.

I haven't fiddled this yet, but you might be able to get away with:

chown root:root /etc/resolve.conf and chmod og-rw /etc/resolv.conf to prevent the dhcp daemon from being able to write/modify the file.
 

tannn

macrumors newbie
Original poster
Dec 10, 2008
6
0
i run dhcp, and theres gotta be a better way than this..
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
It's not technically temporary. dhcp clients overwrite resolv.conf. If you don't run dhcp, resolv.conf is persistent. If you have to use dhcp (and most people do), the next trick is to put a boot script that copies your adjusted resolv.conf to /etc after booting up.

I haven't fiddled this yet, but you might be able to get away with:

chown root:root /etc/resolve.conf and chmod og-rw /etc/resolv.conf to prevent the dhcp daemon from being able to write/modify the file.

True, but then if you switch networks, and require different DNS servers, you're hosed.
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
order hosts, bind works

Try it, if it doesn't, delete the line. Regarding reboot, just put a bootup script that copies ~/myresolv.conf to /etc/resolve.conf

simple.
 

Attachments

  • Picture 1.png
    Picture 1.png
    147.5 KB · Views: 1,109

tannn

macrumors newbie
Original poster
Dec 10, 2008
6
0
Did you even try the command?

yes i did, look:

marc-anssa-macbook-pro:~ manssa$ lookupd -configuration
-bash: lookupd: command not found
marc-anssa-macbook-pro:~ manssa$

lookupd does not exist in leopard.
 

tannn

macrumors newbie
Original poster
Dec 10, 2008
6
0
order hosts, bind works

Try it, if it doesn't, delete the line. Regarding reboot, just put a bootup script that copies ~/myresolv.conf to /etc/resolve.conf

simple.

I have no idea how to write that kind of script, unfortunately :(
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
I have no idea how to write that kind of script, unfortunately :(

Do this as root:

cp /etc/resolv.conf /etc/resolve.conf.mine
nano /etc/rc.local

In nano:
cp /etc/resolve.conf.mine /etc/resolv.conf

In resolv.conf make sure you have above nameserver
order hosts, bind

That should take care of it.

One other option: If this is a home network, disable dhcp, use a static address instead.
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
Why did Apple do this? This is just another dumb idea.

It's not apple. It's the way *nix works. It's been working that way for a looooooooooooong time. hosts files were outgrown about a week into the Internet. Bind was the right answer. Generally the default behaviour is to consult the bind system over hosts. BTW: resolv.conf was never an issue until dhcp showed up, but when you dynamically assign IP addresses, you have to tell the client where to search for dns which is why it overwrites resolv.conf
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
Do this as root:

cp /etc/resolv.conf /etc/resolve.conf.mine
nano /etc/rc.local

In nano:
cp /etc/resolve.conf.mine /etc/resolv.conf

In resolv.conf make sure you have above nameserver
order hosts, bind

That should take care of it.

One other option: If this is a home network, disable dhcp, use a static address instead.

I think I would do something different, in case you go to another site, and grab different DNS servers.

You could do:
Code:
mv /etc/resolv.conf /etc/resolv.conf.new
echo order hosts, bind > /etc/resolv.conf
cat /etc/resolv.conf.new >> /etc/resolv.conf

This way, no matter what you grab from the DHCP server, you put that above it.

Since I don't have Leopard, can either of you check that widget link above? It may set the option permanently without the need for the script.
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
It's not apple. It's the way *nix works. It's been working that way for a looooooooooooong time. hosts files were outgrown about a week into the Internet. Bind was the right answer. Generally the default behaviour is to consult the bind system over hosts. BTW: resolv.conf was never an issue until dhcp showed up, but when you dynamically assign IP addresses, you have to tell the client where to search for dns which is why it overwrites resolv.conf

The latest versions of Solaris, HP-UX, and Linux use /etc/nsswitch.conf that defaults it to consult hosts first. I do this on all of our boxes at work without the need to mess around with any other files. Just add entries to /etc/hosts and go.

Apple chose to make it hard to change the behavior.
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
I think I would do something different, in case you go to another site, and grab different DNS servers.

You could do:
Code:
mv /etc/resolv.conf /etc/resolv.conf.new
echo order hosts, bind > /etc/resolv.conf
cat /etc/resolv.conf.new >> /etc/resolv.conf

This way, no matter what you grab from the DHCP server, you put that above it.

Since I don't have Leopard, can either of you check that widget link above? It may set the option permanently without the need for the script.

Yup, that would be even better. Good call.
 

jmxp69

macrumors 6502
Dec 10, 2008
324
0
The latest versions of Solaris, HP-UX, and Linux use /etc/nsswitch.conf that defaults it to consult hosts first. I do this on all of our boxes at work without the need to mess around with any other files. Just add entries to /etc/hosts and go.

Apple chose to make it hard to change the behavior.

And those aren't really consumer OS's. No surprise in the enterprise that long term conventions are massaged to meet the needs of IT admins....

So I stand corrected, but many many many *nix distros still use resolv.conf as described.
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
And those aren't really consumer OS's. No surprise in the enterprise that long term conventions are massaged to meet the needs of IT admins....

Yeah, that's probably right, except for Linux. Either way, this guy should be set in one way or another. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.