View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-09-2009, 09:34 AM   #1
Registered: Mar 2009
Distribution: Fedora 8, Ubuntu 9.10, SuSE 10, Fedora 14
Posts: 98

Rep: Reputation: 15
Changing hostname in /etc/hosts so that it is defined to ip-address and not loopback


I'm really clueless. I have to configure two network interface cards. I want to change the /etc/hosts file so that the hostname is defined to my ip-address and not to the loopback device. In the following extract (I put in line numbers to make it easier) I am confused as to where I should type in my specific details:

1 ip_address=`/bin/hostname -i`
2 host_name=`/bin/hostname -f`
3 short_name=`/bin/hostname -s`
4 sed -i "s/*/ localhost.localdomain localhost/g" /etc/hosts
5 sed -i "s/$ip_address/#$ip_address/g" /etc/hosts
6 echo "$ip_address $host_name $short_name" >> /etc/hosts

Question 1)
Do I put my computer's hostname at the /bin/hostname part in line 1, or do I put it at host_name in line 2 ?

For example, if my hostname is gnlserv01, and the ip-address for the private interface is would I type the following into a terminal for line 1:

ip_address = `/bin/gnlserv01 -i`

or = `/bin/hostname -i`

or something else?

Question 2)
Why do I need a short_name, and can I make it anything I want?

It doesn't seem as if it reverts to the loopback device if I do the following:

[root@gnlserv01 ~]# /bin/hostname
[root@gnlserv01 ~]# ping -c1 gnlserv01
PING gnlserv01.getec ( 56(84) bytes of data.
64 bytes from gnlserv01.getec ( icmp_seq=1 ttl=64 time=0.025 ms

--- gnlserv01.getec ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.025/0.025/0.025/0.000 ms

This is what is in my /etc/hosts at present:

# Do not remove the following line, or various programs
# that require network functionality will fail. localhost.localdomain localhost gnlserv01.getec gnlserv01
::1 localhost.localdomain localhost gnlserv01

Question 3)
My public interface is configured (hm, that's how I get on the internet), should it be seen in the /etc/hosts or not?
Old 03-09-2009, 09:48 AM   #2
LQ Guru
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,232
Blog Entries: 5

Rep: Reputation: 190Reputation: 190
1. Setting the Linux Hostname

2. the short name would be the hostname, the long version would be the Fully Qualified Domain name.. the hostname is the first part of the fqdn, and therefor should match..

mypc = hostname = FQDN

3. if you needed to assign a name to the external interface that would typically be done with a DNS server. I wouldn't bother putting anything for it in the hosts file.


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
ipv6 redirecting to loopback address vikasmca05 Linux - Newbie 7 05-06-2009 03:24 AM
Changing Hostname.../etc/hosts...? vous Linux - Networking 13 01-16-2008 09:38 PM
Strange loopback entries in /etc/hosts Passions Linux - Networking 1 04-13-2007 09:37 PM
internal modem loopback address sumathi Linux - Hardware 3 07-28-2005 07:50 AM
changing IP address and hostname ashley75 Linux - General 7 05-19-2005 11:26 AM

All times are GMT -5. The time now is 09:20 PM.

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