-1
$ dig @127.0.0.1 localhost  
$ dig @127.0.0.1 localhost.

;localhost.         IN  A
;; ANSWER SECTION:
localhost.      604800  IN  A   127.0.0.1
;; AUTHORITY SECTION:
localhost.      604800  IN  NS  localhost.
;; ADDITIONAL SECTION:
localhost.      604800  IN  AAAA    ::1
ping localhost.

$ ping localhost.
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.061 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.058 ms

and:

$ ping localhost 
PING localhost.pl (46.105.234.97) 56(84) bytes of data.

$ whois localhost
No whois server is known for this kind of object.

$ whois localhost.pl

DOMAIN NAME:           localhost.pl
registrant type:       organization
nameservers:           ns1.goo.pl. [178.33.152.98]
                       ns2.goo.pl. [94.23.111.174]

$ cat /etc/hosts
127.0.0.1   localhost

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1


$ cat /etc/host.conf 
# The "order" line is only used by old versions of the C library.
order bind,hosts
multi on

why my INTERNAL network is resolving localhost to public ip ???

edit:

$ cat  /etc/nsswitch.conf 

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

#hosts: dns files
#networks: files

hosts: files dns
networks: files dns

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

why setting dns over files makes this difference especially when i set localhost zone and resolving to loop-back (127.0.0.1) ?

$ ping localhost   # hosts: files dns 
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=64 time=0.075 ms
64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=2 ttl=64 time=0.149 ms

how i can get rid of using /etc/hosts ? and use only named service ? or its existence is highly linked to the server functioning???

  • BIND 9.10.3-P2-Ubuntu
  • Ubuntu Server 15.10

To help us understand why your problem exists in the first place, can you possibly explain your incentive to not use local files for localhost resolution? - SmallLoanOf1M

background:

i set a host on nginx "host.domain.tld" one of many but one acting as a proxy to "webmin" with below definition

    location / { 
        proxy_redirect http://host.domain.tld:10000/ https://host.domain.tld/; 
        proxy_pass http://localhost:10000/;
        proxy_set_header Host $host;
    }

webmin bind to 127.0.0.1:10000

one day I visit the page and i get 504 - gateway timeout so i start digging through logs what is wrong why i dont see my page :D

in logs i saw upstream connect "some weird public ip" - it was looking like man in middle attack :D

more testing did show that ping is directing to this public ip "localhost".pl so i was searching how and why my server is cheating me :D

6
  • 1
    'grep ^hosts /etc/nsswitch.conf' ? And what difference between first output of the ping (correct) and the second (wrong)? Are they from the same server?
    – ALex_hha
    Mar 22, 2016 at 16:53
  • @alex-hha yes i manage to trace that is a nsswitch issue . but why ? (question see my edit)
    – ceph3us
    Mar 22, 2016 at 17:02
  • What are you trying to achieve excluding /etc/hosts from the name resolution?
    – ALex_hha
    Mar 22, 2016 at 17:13
  • @alex-hha - what is the reason to have 10 garages next to each other how they feel about one car :) and what if you forget where you parked the car?
    – ceph3us
    Mar 22, 2016 at 17:25
  • @ALex_hha - can u look at this unix.stackexchange.com/questions/271353/… ?
    – ceph3us
    Mar 22, 2016 at 17:26

1 Answer 1

2

From what I read above, it seems like you want to ignore the /etc/hosts file entirely when attempting a localhost resolution on this server. In general, localhost should only ever resolve to that machines localhost, which is statically in the 127.0.0.0/8 network. With that in mind, any incentive to use DNS to resolve localhost would be technically possible but ultimately pointless. You'd only be risking pointing to a localhost that is not actually 127.0.0.1 via forwarded DNS.

Perhaps you are trying to point to localhost as a nameserver on the DNS box itself for its own resolution? That's still possible with localhost being defined in /etc/hosts, as the named service can simply listen on localhost for queries (and this has nothing to do with how localhost itself is resolved).

While that seems like it answers the base question, I somewhat doubt that it's satisfactory in this case. To help us understand why your problem exists in the first place, can you possibly explain your incentive to not use local files for localhost resolution?

1
  • - hi see my edit :)
    – ceph3us
    Mar 22, 2016 at 21:22

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