LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 03-09-2009, 08:34 AM   #1
Azazwa
Member
 
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


Hi!

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/127.0.0.1.*/127.0.0.1 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 192.168.1.254 would I type the following into a terminal for line 1:

ip_address = `/bin/gnlserv01 -i`

or

192.168.1.254 = `/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
gnlserv01
[root@gnlserv01 ~]# ping -c1 gnlserv01
PING gnlserv01.getec (192.168.1.254) 56(84) bytes of data.
64 bytes from gnlserv01.getec (192.168.1.254): 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.
127.0.0.1 localhost.localdomain localhost
192.168.1.254 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, 08:48 AM   #2
farslayer
Guru
 
Registered: Oct 2005
Location: Willoughby, Ohio
Distribution: linuxdebian
Posts: 7,228
Blog Entries: 5

Rep: Reputation: 189Reputation: 189
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
mypc.mydomain.com = 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.
 
  


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


All times are GMT -5. The time now is 11:28 PM.

Main Menu
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