You are not logged in.

#1 2014-07-01 15:28:02

nobicycle
Member
Registered: 2014-07-01
Posts: 15

Different results on each execution for hostname -I (Closed)

for i in $(seq 1 10) ; do  /usr/bin/hostname -i; sleep 5; done
118.98.96.151
118.98.96.151
192.168.1.11
118.98.96.151
118.98.96.151
118.98.96.151
118.98.96.151
118.98.96.151
118.98.96.151
118.98.96.151

192.168.1.11  is the address I expected. It is the address reported by Network Manager "Connection Information"
118.98.96.151 is some address belonging to my ISP, but neither Default Gateway:    180.251.160.1 nor Primary DNS Server: 202.134.1.10 nor Secondary DNS Server:    203.130.193.74
According to http://toolbar.netcraft.com/site_report … .98.96.151  it is an nginx webserver owned by the ISP.

Different ip addresses reported by hostname -i????
The only interface is  ethernet.

On a notebook running Live Manjaro, the above test reports 127.0.0.1, 10 times, but  Network Manager reports 192.168.1.12.

Obviously I am missing an understanding of how hostname gets its IP.
Why the ISP server IP appeared is mind boggling to me.

Last edited by nobicycle (2014-07-03 02:24:11)

Offline

#2 2014-07-02 06:40:54

bch24
Member
Registered: 2011-11-20
Posts: 27

Re: Different results on each execution for hostname -I (Closed)

I'm not super knowledgable on networking but I would think you do not have your host file setup and so you are asking your ISP for it IP address which it is not answering correctly for.

I'm not sure, but my understanding is that hostname binary calls the system gethostname function.

It will resolve its information by order dictated by /etc/nsswitch.conf

usually the hosts section is something similar to:

hosts: files dns ...etc 

So first it should go to /etc/hosts

192.168.1.11  myhostname.localdomain    myhostname

If it is not resolved there it will send a dns request to the dns server.

Your ISP's dns server most likely does not know how to answer for your local machine and for some reason returning that IP address.

Offline

#3 2014-07-02 08:06:49

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Different results on each execution for hostname -I (Closed)

$ hostname -i
127.0.0.1

Configure your /etc/hosts correctly, i.e. the first line:

127.0.0.1       localhost myhostname

Where "myhostname" is whatever you want to call the PC. Check *that* by just running "hostname".

Offline

#4 2014-07-03 02:23:32

nobicycle
Member
Registered: 2014-07-01
Posts: 15

Re: Different results on each execution for hostname -I (Closed)

Thanks guys.
I happened to need to reinstall, and afterwards the problem went away.
Actually, the hosts file was vanilla, untouched.
There was no wifi interface. But I do remember tying to get a USB wifi device running with hostapd and believe there was a bridge left around. At the time of the above tests no such device was present. Some bad configuration must have been left hanging.
Anyway, thanks for your help. Issue closed.

Offline

#5 2014-07-03 02:26:50

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Different results on each execution for hostname -I (Closed)

Please don't use (Closed), it denotes a locked thread. Solved or resolved is fine.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB