LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices



Reply
 
Search this Thread
Old 10-02-2008, 04:53 PM   #1
thespaceman
LQ Newbie
 
Registered: Oct 2008
Posts: 16

Rep: Reputation: 0
Correct way to define hostname in /etc/hosts


Hi,

I've just done my first install of RHEL 5.1 and every went ok and the server is on the network.

My question is what is the correct way to define the hostname within /etc/hosts? The entry after the install is like this:

127.0.0.1 myserver.mydomain.com myserver localhost


Normally (in Solaris,HP-UX etc) the hosts file would be as follows:

127.0.0.1 localhost
10.10.10.10 myserver myserver.mydomain.com


So for Linux should I leave /etc/hosts as is or should I go for the Solaris method?

The address 10.10.10.10 is the IP associated with the primary interface as is defined as an IP within the NIC device config file. The hostname is set to myserver.

Thanks.
 
Old 10-02-2008, 05:06 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
Leave it whatever way the Linux one has it. I got this from 'man hosts':
Quote:
For each host a single line should be present with the following information:
IP_address canonical_hostname [aliases...]
 
Old 10-03-2008, 03:26 AM   #3
stuart_cherrington
Member
 
Registered: Aug 2008
Location: Get back in your Cube Unix Boy!
Distribution: rh5, oel5, debian etch, solaris
Posts: 228

Rep: Reputation: 36
If you're going to run any apps (like Oracle) then you need the FQDN first in the lists of hostnames.
 
Old 10-03-2008, 01:03 PM   #4
thespaceman
LQ Newbie
 
Registered: Oct 2008
Posts: 16

Original Poster
Rep: Reputation: 0
Question

So this is correct:

127.0.0.1 myserver.mydomain.com myserver localhost


But how would you define the 10.10.10.10 address? Obviously other hosts on the same DNS domain would associate myserver with 10.10.10.10. So would it be normal not to define the primary IP (hostname aliase) in /etc/hosts?

Is this done for performance reasons?
 
Old 10-05-2008, 11:49 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
/etc/hosts existed in the early days of arpanet (internet forerunner). All machines had the same file and new copies were emailed out regularly. When the net got too big, they came up with DNS/bind which would automatically find systems on demand.
These days /etc/hosts will often only have the 127.0.0.1 address. If you define another address in there, it will not be visible across the net.
It should be in the file that defines the NIC eg eth0. On my F8 system that's
/etc/sysconfig/networking/devices/ifcfg-eth0
 
Old 10-06-2008, 12:00 AM   #6
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
If you don't run your own DNS server, then enter each host on your private lan , in the hosts file. If you have the avahi service running, you can use instead use "<hostname>.local" to refer to another computer by name.
 
Old 10-12-2008, 11:27 AM   #7
schotzy
LQ Newbie
 
Registered: Dec 2003
Posts: 10

Rep: Reputation: 0
Quote:
Originally Posted by thespaceman View Post
So this is correct:

127.0.0.1 myserver.mydomain.com myserver localhost


But how would you define the 10.10.10.10 address? Obviously other hosts on the same DNS domain would associate myserver with 10.10.10.10. So would it be normal not to define the primary IP (hostname aliase) in /etc/hosts?

Is this done for performance reasons?
I think it is probably done for machines that are using dhcp and may have their address change. This way local processes can still resolve the actual hostname without needing dns or changing /etc/hosts every time.

If you are using a static address you can certainly add a line for the 10.x.x.x address with the host name, and make the hosts file appear just like it does on a Solaris box.

You should also note that if there are more than one entry in /etc/hosts with the same address, only the last will be used. So if you had :

127.0.0.1 myserver.mydomain.com myserver localhost
10.10.10.10 myserver.mydomain.com myserver
[...]
then myserver.mydomain.com myserver would resolve to 10.10.10.10, not 127.0.0.1.

On my machines with static addresses I *always* set up the hosts file with only localhost on the 127.0.0.1 line and a separate line for the "real" hostname and it's associated IP.
 
  


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
Define new hostname without root access? pwc101 Linux - Networking 8 07-31-2008 06:05 AM
correct config of Hosts file ankycooper Red Hat 1 06-15-2006 02:07 AM
In what other locations does Unbuntu define hostname? Kropotkin Ubuntu 1 02-02-2006 02:53 AM
Correct entry for local machine in /etc/hosts Kropotkin Linux - Networking 1 11-16-2004 06:41 PM
Unable to define RH7.3 hostname glorinc Linux - Networking 3 09-09-2002 07:37 AM


All times are GMT -5. The time now is 06:40 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration