$ dig @ localhost  
$ dig @ localhost.

;localhost.         IN  A
localhost.      604800  IN  A
localhost.      604800  IN  NS  localhost.
localhost.      604800  IN  AAAA    ::1
ping localhost.

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


$ ping localhost 
PING localhost.pl ( 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. []
                       ns2.goo.pl. []

$ cat /etc/hosts   localhost

$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

$ 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 ???


$ 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 ( ?

$ ping localhost   # hosts: files dns 
PING localhost.localdomain ( 56(84) bytes of data.
64 bytes from localhost.localdomain ( icmp_seq=1 ttl=64 time=0.075 ms
64 bytes from localhost.localdomain ( 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


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

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

closed as off-topic by kubanczyk, Ward, mdpc, kasperd, Jenny D Apr 4 '16 at 8:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions should demonstrate reasonable business information technology management practices. Questions that relate to unsupported hardware or software platforms or unmaintained environments may not be suitable for Server Fault - see the help center." – kubanczyk, Ward, mdpc, Jenny D
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 '16 at 16:53
  • @alex-hha yes i manage to trace that is a nsswitch issue . but why ? (question see my edit) – ceph3us Mar 22 '16 at 17:02
  • What are you trying to achieve excluding /etc/hosts from the name resolution? – ALex_hha Mar 22 '16 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 '16 at 17:25
  • @ALex_hha - can u look at this unix.stackexchange.com/questions/271353/… ? – ceph3us Mar 22 '16 at 17:26

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

  • - hi see my edit :) – ceph3us Mar 22 '16 at 21:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.