LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-19-2010, 04:16 PM   #1
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Rep: Reputation: 16
Why am I localhost? My name is tahiti my number is 10...


Maybe this belongs in the server or network forum?

I'm having a hard time getting this one...

I install a box named tahiti. Tahiti is a major server in the yahoo.com infrastructure (for pretend). Or rather, tahiti will be a node in the yahoo.com zone (dns speak). When I setup this sytem, without any direct administrative intervention, the install process gives me an /etc/hosts like so:

127.0.0.1 tahiti.yahoo.com tahiti localhost.localdomain localhost

---
/etc/host.conf is: order hosts,bind

---
/etc/nsswitch.conf is: hosts: files dns

---
So this means if I do...

[root@tahiti ~]# ping tahiti
PING tahiti.yahoo.com (127.0.0.1) 56(84) bytes of data.
64 bytes from tahiti.yahoo.com (127.0.0.1): icmp_seq=0 ttl=64 time=0.090 ms


[root@tahiti ~]# nslookup tahiti
Server: 10.3.1.16
Address: 10.3.1.16#53

Name: tahiti.yahoo.com
Address: 10.3.1.15



---

Why do we encourage split personalities?

Is this simply a matter of when we're at the local system we talk to loopback but everywhere else we're a routable ipaddr?

Can somebody point to an established reference that expalins this? I don't see any basis for this in the RFCs covering the concept of hosts or localhost.
 
Old 05-19-2010, 04:26 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,817

Rep: Reputation: 609Reputation: 609Reputation: 609Reputation: 609Reputation: 609Reputation: 609
ping looks at /etc/hosts first. nslookup, being a DNS utility, looks at the DNS servers as defined in /etc/resolv.conf first. You can switch /etc/hosts around if you want to change what "tahiti" resolves to according to most programs.
 
Old 05-19-2010, 04:32 PM   #3
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Original Poster
Rep: Reputation: 16
Right --and with the way host.conf and nsswitch.conf is written (again, by default) we would expect files, specifically /etc/hosts to be examined first.

My point is once we use DNS for resolution anything going through the resolver library is going to get 10.3.1.15. Anything not using the resolver is going
to get loopback 127.0.0.1

Is it a better practice then to NOT include the custom hostname in /etc/hosts at all? Or if we do, create a new entry, removing it from the loopback listing. Thus:

NOT:

127.0.0.1 tahiti.yahoo.com tahiti localhost.localdomain localhost

But rather this:

127.0.0.1 localhost.localdomain localhost

Or this:

127.0.0.1 localhost.localdomain localhost
10.3.1.15 tahiti.yahoo.com tahiti
 
Old 05-19-2010, 07:20 PM   #4
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Original Poster
Rep: Reputation: 16
Does anyone have an opinion on this --or can anyone point to a reference which explains why it should be one way or another?
 
Old 05-19-2010, 07:24 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
The latter would only work for a static IP and only on that system, unless you have a DNS entry somewhere that repeats the 10.x ipaddr/host entry.
FYI, that's how the orig ARPAnet (precursor to internet) worked, but updating everybody's hosts file became impracticable, so they invented DNS.
On a DHCP client, on RedHat systems, you'd find the FQDN in /etc/sysconfig/network as well.
 
Old 05-19-2010, 07:35 PM   #6
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Original Poster
Rep: Reputation: 16
Right --this is assuming the system is using a static ipaddr. Absolutely.

The gist of the question is that in using files, and using files the way in which they're created by default my hostname (in the example above, "tahiti") is 127.0.0.1. But once I reference bind, my hostname becomes 10.3.1.15. That being the case I would get one ipaddr from 'ping tahiti' (127.0.0.1) and another ipaddr from 'nslookup tahiti' (10.3.1.15).

The question is a) remove my hostname from /etc/hosts alltogether OR
b) create an entry in /etc/hosts that is the same ipaddr as what I get from resolver

My practice is (was) to always include myhostname in /etc/hosts but I'm beginning to wonder if it should only include localhost 127.0.0.1


I have not found a clear explanation on this anywhere.
 
Old 05-19-2010, 09:24 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
On my system I've got

Code:
#/etc/hosts

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.1.100   boole.home.cxm boole

# /etc/nsswitch.conf
hosts:      files dns

# /etc/sysconfig/network 
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=boole.home.cxm
This means whether DNS is available or not, the system knows its name.
( I deliberately use a non-existent TLD as this name is not supposed to be accessed over the internet. It won't get confused with a real domain if it does somehow get out )

/etc/resolv.conf just has my router IP.

HTH
PS If you add your distro name+version to your profile, you may get more specific help.
 
Old 05-19-2010, 10:55 PM   #8
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Original Poster
Rep: Reputation: 16
chrism01: Thanks for the comments. Typically I'd include the distro/kernel rev but this is an issue encompassing an array of distros. It's almost more of a universal OS issue.

More frequently I'm seeing linux systems setup with the unique hostname edited into /etc/hosts on the same line as loopback. I imagine in many cases this is done by installers or
interfaces that help expedite network configuration. Even when the system has ipaddrs applied to one or more interfaces the hostname of the system is listed in /etc/hosts next to loopback. If
the system's fqdn resolves through a dns made available to that system it can do: 1) ping <myhostname> and get 127.0.0.1 and 2) nslookup <myhostname> and get something entirely different. This ends up being acceptable and I'm finding this configuration on systems that have been functioning just fine. I imagine a performance junkie did some measurements of response time with 127. on loopback vs an ipaddr on a NIC and saw faster results (ms differences) using loopback (fewer bit shifts to calculate?).

I'm looking for an explanation as to why this has become the norm (or at least become common). I could simply modify all my /etc/hosts tables and get on with it but it seems there might be a good reason why new installs are setup this way.
 
Old 05-19-2010, 10:58 PM   #9
kobeli
LQ Newbie
 
Registered: May 2010
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
The latter would only work for a static IP and only on that system, unless you have a DNS entry somewhere that repeats the 10.x ipaddr/host entry.
FYI, that's how the orig ARPAnet (precursor to internet) worked, but updating everybody's hosts file became impracticable, so they invented DNS.
On a DHCP client, on RedHat systems, you'd find the FQDN in /etc/sysconfig/network as well.
 I was actually looking for this resource a few weeks back. Thanks for sharing with us your wisdom.This will absolutely going to help me in my projects .
 
Old 05-19-2010, 11:01 PM   #10
damgar
Senior Member
 
Registered: Sep 2009
Location: dallas, tx
Distribution: Slackware - current multilib/gsb Arch
Posts: 1,949
Blog Entries: 8

Rep: Reputation: 201Reputation: 201Reputation: 201
This is from the /etc/hosts as it appears in Slackware:
Quote:
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server. Just add the names, addresses
# and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <REMOVED EMAIL ADDRESS> says that 127.0.0.1
# should NEVER be named with the name of the machine. It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1 localhost
192.168.1.108 i7 i7
192.168.1.104 dell
192.168.1.101 dtest
192.168.1.102 dlin
I went ahead and included my entries. So there's one opinion.

Last edited by damgar; 05-19-2010 at 11:03 PM.
 
Old 05-20-2010, 08:09 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
If DNS or your NIC is not working/connected eg standalone (as a lot of systems used to be and some still are if you live way out in the bush), you can only refer to your system by the 127.0.0.1 line, so some people add the preferred hostname to the end of that line. For example, I could add 'boole' to the end of that line in that case. That would then appear in the cmd prompt (assuming I've asked the prompt to include hostname).
Note that systems can have multiple 'hostnames', at least one per IP addr and you can have multiple ipaddrs, either on separate NICs or by using the 'virtual interface' option eg

eth0
eth0:1
eth0:2

each can have a separate ip+name, using only one NIC.
Older systems also had an /etc/hostname (uppercase filename?) file that contained the preferred hostname.

Does that help?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error parsing proxy URL http://localhost:4001 : Bad port number? lugoteehalt Linux - Networking 1 11-20-2009 07:58 PM
Localhost pointing to default page if I don't specify the port number in the address rajaoLQ Linux - Server 6 08-24-2009 03:52 PM
apache : localhost/ works localhost/index.html does not PhilA Linux - Server 4 05-27-2007 08:32 PM
Message from syslogd@localhost localhost kernel: Disabling IRQ #21 ylts Linux - Hardware 0 02-26-2005 09:01 AM
localhost ip number jamaas Linux - Networking 1 09-10-2004 10:39 AM


All times are GMT -5. The time now is 07:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration