Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

/etc/hosts file

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
US
I am running Solaris 2.7.

I have created a script that updates the /etc/hosts file every night by running a command that gives me all ip addresses and hostnames on my network, writes the output to a file and I am "cat"ing that with a file I call /etc/hosts.static to give me my updated /etc/hosts file.

My question:

Can this cause any potential problems? Assume for the sake of argument that there was no /etc/hosts file at boot time. Would that cause the system not to boot? Are there any other potential problems with not having an /etc/hosts file? My /etc/hosts has a link to /etc/inet/hosts as well. My /etc/nsswitch.conf file is set up as follows:

hosts dns

Thanks in advance.
 
blue,

I know it can, but if I run an ifconfig and set the ip address of the interface, does it just write a line in the /etc/hosts? I think it does more than that.
 
I don't believe ifconfig does anything to the /etc/hosts file (if it did you would think it would say so in the man pages for ifconfig).
 
The /etc/hosts file is just used for local name-to-ip resolution, in other words when you type something like #telnet hermes.arapahoe.edu , the hosts file is checked for an entry for hermes.arapahoe.edu and if found uses the IP listed to make the connection. without the hermes.arapahoe.edu listing in the hosts file you would HAVE to use the proper IP address. I believe that this is all the hosts file does. So not having a good hosts file means you would have to have access to or know all of the remote machines IP addresses you might wish to access. The only problem I can see you having is if you cat a file into another like so:

cat filename > filename2

Then you just clobbered what was in filename2 and replaced it with the contents of filename. Use the append feature if your hosts file is not too complex like so;

cat filename >> filename2

this will preserve whats in filename2 and add the contents of filename to the end of filename2.


However you would still want to do a filesize check on filename to make sure it has data that you want, and as always keep a good backup just in case.
 
If your nsswitch.conf is set up "hosts dns", then I belive the contents of your host file are irrellevant.
Your machine only looks to dns to resolve IP addresses.

You must specify "hosts dns files" if you want to use the hosts file to resolve any IP addresses that dns can't.

Steve
 
true, however on boot it does use the hosts file, even if you are running nis/fns/dns/nis+ to set the startup ip address and/or look for the nis server

if your hosts file is empty (and you're not running nis) then it will fail to set the interface up on and network cards/modems

if you are running nis (or nis+) it will fail to talk to the nis server and fail to boot.

if this is a server, the minimum you need is each interface, a localhost, and any possible boot up servers it needs.

Jon
 
Harris79 I dod not know that! I will make the change. What I want is for DNS to resolve any names that HOSTS cannot! That is the whole point of writing the script, because our DNS is often slow and unreliable.

How can I make my box use DNS only for addresses Hosts cannot relove?
 
Sorry about the typos. If DNS can't love my addresses, well the heck with it! Hosts loves them!
 
in your nsswitch.conf

hosts files dns

should work for you.
 
Ok I see. I forgot how the file is stuctured, it's not like the /etc/hosts. the structure is

hosts:
Networks:

etc etc

With each line telling the box how to resolve certain aspects.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top