LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-25-2013, 12:47 AM   #1
rohithsharma
LQ Newbie
 
Registered: Sep 2010
Location: bangalore
Posts: 5

Rep: Reputation: 0
Smile How "hostname -i" works


Hi guys,

I want to know how the "hostname -i" works.

In one of my machine, when I have /etc/hosts mapping for the ip.

When I execute "hostname -i", I get IP address.
i.e rohith:~#hostname -i
10.10.10.11

But, when there is duplicate entry in the /etc/hosts mapping
Example :
10.10.10.11 rohith
10.10.10.11 rohith

I get result for "hostname -i" 2 ip addresses.
i.e rohith:~#hostname -i
10.10.10.11 10.10.10.11



Can someone please help me to resolve this problem?

Regards
Rohith Sharma K S
 
Old 01-25-2013, 12:58 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
see man hostname: a host may have several ip addresses, hostname -i will print all of them. You need to fix it by removing the second entry or by parsing the result
 
Old 01-25-2013, 02:05 AM   #3
rohithsharma
LQ Newbie
 
Registered: Sep 2010
Location: bangalore
Posts: 5

Original Poster
Rep: Reputation: 0
Hi pan,

Thank for your immidiate reply :-)

I would like to know that in some of the machine, eventhough I have duplicate entries "hostname -i" is giving single IP address.

I am facing this issue only in some machines and both the machine OS are same.
 
  


Reply



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
"Minicom -s" works, but it always show "Offline", then cannot communicate with others reflecter_chen Linux - Hardware 8 05-14-2016 02:05 PM
evdev/xorg help? USB mouse/kbd: 2.6.24="just works">2.6.25="unplug/replug to work". GrapefruiTgirl Linux - Hardware 4 12-13-2012 02:23 PM
Hostname issue - showing "localhost" instead of actual hostname. ryes31 Linux - Server 9 12-12-2012 08:19 PM
Hostname defined in file "network" changes after change to file "hosts" qwkfish Linux - Networking 2 10-14-2009 04:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:54 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
Open Source Consulting | Domain Registration