If I run below command, I am getting some strange IP addresses.

hostname -i

My host file entry is in default configuration, below are the contents of my /etc/hosts file entry   localhost localhost.localdomain localhost4 localhost4.localdomain4
 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Actual IP of this machine is

I hope, once I added below entry in /etc/hosts file,   myhost

I might get expected output,

 hostname -i

But, Why its showing different range of IPs while running hostname -i?


ip r dev eth0  proto kernel  scope link  src dev eth0  scope link  metric 1002 
default via dev eth0

ifconfig eth0

eth0      Link encap:Ethernet  HWaddr ##removed##  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::20c:29ff:feca:24c2/64 Scope:Link
          RX packets:2153703 errors:0 dropped:0 overruns:0 frame:0
          TX packets:612859 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:189727756 (180.9 MiB)  TX bytes:761146814 (725.8 MiB)

(Using Cent 6.4)

  • Can you post output of ifconfig or "ip a" also.
    – StefanR
    Commented Aug 29, 2016 at 8:39
  • Also make sure you have full name of the host (FQDN) in the hosts file
    – StefanR
    Commented Aug 29, 2016 at 8:44
  • 1
    Can you use hostname -I instead, or do you want to understand the results of hostname -i ? Note from man page: "Avoid using this option; use hostname -I instead". With a quick test on my centos6 system, hostname -i returns an IP address which does not match the machine on which it is running. Commented Aug 29, 2016 at 8:47
  • @user4556274, I could see if I am using -I. And yes, why its showing some other IPs. As per StefanR answer, I have done the dig and getting those IPs. But, while other host is showing expected result using -i I am confused.
    – RBB
    Commented Aug 29, 2016 at 8:55
  • @Spike did you notice my answer?
    – jlliagre
    Commented Aug 29, 2016 at 8:58

2 Answers 2


You probably have previous DNS a records in the DNS server you are using for that hostname. YOu can verify this with dig:

dig <your.host.name>

It looks like a trick from your DNS server. Querying whatever unknown hostname/fqdn will return precisely the two IP addresses you get:

$ nslookup whatever-unknown-name

Non-authoritative answer:
Name:   whatever-unknown-name
Name:   whatever-unknown-name

Your server is configured to query first the DNS then look at the /etc/hosts files so whatever you put in the latter is be ignored if your DNS server is resolving your hostname. The issue is it is fooling you by "resolving" any unknown name to the fixed IP addresses you got.

To fix the issue, edit your /etc/nsswitch.conf file and put files before dns in the hosts line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .