[Techtalk] Re: /etc/hosts

Therese Gustafsson th_gustafsson at yahoo.com
Thu Oct 3 05:15:03 EST 2002


--- Magni Onsoien <magnio+lc-techtalk at pvv.ntnu.no>
wrote:
> 
> Yes, you do.
> 
> /etc/hosts contains a mapping of IP-address <->
> hostname, just like DNS.
> In fact, in the early era of Internet they
> distributed /etc/hosts
> between all servers connected (getting the file from
> an ftp-server) -
> but of course that didn't scale very well :)
> 
> /etc/nsswitch.conf contains info about in which
> order to look up fex
> hostnames - from dns, files (/etc/hosts), nis etc.
> The most convenient
> order _unless you know it should be different_ for
> the line starting
> with hosts is 'files dns'. Usually there is NO need
> to change anything
> in this file, but of course someone may have done
> that before :)
> 
> If your hostname isn't in /etc/hosts, it should be
> in DNS in stead - if
> it's nowhere your computer may be a bit confused if
> it tries to look up
> it's own name. On the other hand, you may be very
> confused if you put
> your hostname and current IP address in /etc/hosts
> and then move your
> computer to another location without changing
> /etc/hosts and changing
> DNS in stead. "Hm, everybody exccept me seems to
> connect to my
> webserver! What the h*** have I done with my
> firewall??" is rather
> common then :)
> 
[snip] .... [/snip]
> So, my conclusion is:
> - you need your hostname in /etc/hosts
> - you may have aliases to your hostname there
> - it may stay there even if you later add it to DNS
> - remember to change /etc/hosts if your IP-address,
> domainname etc
> changes later, unless you want to confuse yourself
> 
> Usually you should have at least two lines in
> /etc/hosts on a networked
> client:
> 127.0.0.1	localhost
> 10.2.3.4	myhostname myhostname.example.com
> 
> If you don't have an IP-address you can add your
> hostname to the first
> line instead: 
> 127.0.0.1	localhost myhostname
> 
> In your case, when you have a static IP-address, you
> can
> use the two lines with a few changes in IP-address
> and hostname.
> 
> (The "duplication" with  both myhostname and
> myhostname.example.com is
> to make sure both short and fully qualified hostname
> works.)
> 
> > I have another problem now: I deleted the old
> hostname
> > from /etc/hosts but Apache and sshd still think
> > they're at the.old.hostname. I have restarted
> Apache
> > but no change. Where do they get that information
> from
> > if it's not in /etc/hosts anymore? 
> 
> Apache has it in httpd.conf, look for ServerName.
> Also check that the
> virtualhost section (look for VirtualHost) doesn't
> contain the old 
> IP-address.
> 
> I am not sure what you mean with "sshd still think
> [it is] at
> the.old.hostname". Doesn't it work? Can't you log in
> from remote?
> 
> Have a look at /etc/ssh/sshd_config (or
> /etc/sshd_config) and check 
> that ListenAddress doesn't contain old IP-address
> (default is, AFAIK, 
> ListenAddress 0.0.0.0, and it's often not specified
> because that's 
> default. So no sign of ListenAddress probably means
> it's 0.0.0.0). 
> 
> Also check that /etc/hosts.allow doesn't only
> contain the old IP-address 
> as the only place where ssh is allowed from. This
> should, however, only
> affect remote login and should have been similar
> even before you changed
> /etc/hosts and hostname because sshd generally don't
> careabout
> _hostname_, only IP-address.
> 
> Magni :)

Thanks for the explanation!
Sorry for the bad sshd-explanation...What I meant was
that the command "hostname" printed the.old.hostname,
even after I changed in /etc/hosts. But I've changed
that now. 

There's no sign of ServerName or VirtualHost in
httpd.conf or ListenAddress.  But it's not really
important. Everything works, it's just annoying when
Apache says "Apache server at the.old.hostname" when
you go to a nonexisting page. The server is just
temporary and I'm the only one accessing it. It just
confused me what to put as hostname when you don't
have one. 

And I've solved the phpMyAdmin problem also. There was
a config-file that hade the old hostname in it so I
just changed that to the current ip-address instead. 

Thanks.

/Therese

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com



More information about the Techtalk mailing list