0

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

hostname -i
198.105.244.11 198.105.254.11

My host file entry is in default configuration, below are the contents of my /etc/hosts file entry

 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Actual IP of this machine is 192.168.2.31

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

 192.168.2.31   myhost

I might get expected output,

 hostname -i
 192.168.2.31

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

Update:

ip r

192.168.2.0/24 dev eth0  proto kernel  scope link  src 192.168.2.31 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 192.168.2.1 dev eth0

ifconfig eth0

eth0      Link encap:Ethernet  HWaddr ##removed##  
          inet addr:192.168.2.31  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feca:24c2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          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)

10
  • Can you post output of ifconfig or "ip a" also.
    – StefanR
    Aug 29, 2016 at 8:39
  • Also make sure you have full name of the host (FQDN) in the hosts file
    – StefanR
    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. 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.
    – Spike
    Aug 29, 2016 at 8:55
  • @Spike did you notice my answer?
    – jlliagre
    Aug 29, 2016 at 8:58

2 Answers 2

1

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>
1

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 4.2.2.2
Server:     4.2.2.2
Address:    4.2.2.2#53

Non-authoritative answer:
Name:   whatever-unknown-name
Address: 198.105.244.11
Name:   whatever-unknown-name
Address: 198.105.254.11

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 .