ping localhost give back foreign address?

I discover a strange problem with ping localhost and I can not find out why.
ping localhost with namserver bind9 running or without bind9 (stopped) gives me an external address.
$ ping localhost
PING localhost.de (91.202.43.26): 56 data bytes
64 bytes from 91.202.43.26: icmp_seq=0 ttl=114 time=6.841 ms
64 bytes from 91.202.43.26: icmp_seq=1 ttl=114 time=6.915 ms
Webbroser: http://91.202.43.26/ goes to http://localhost.de

$ ping -c2 localhost.de
PING localhost.de (91.202.43.26): 56 data bytes
64 bytes from 91.202.43.26: icmp_seq=0 ttl=114 time=6.838 ms
64 bytes from 91.202.43.26: icmp_seq=1 ttl=114 time=6.801 ms

ping -c2 127.0.0.1 -> "64 bytes from 127.0.0.1:..."


with bind9 running:
$ nslookup localhost
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: localhost
Address: 127.0.0.1
Name: localhost
Address: ::1

$ nslookup 127.0.0.1
1.0.0.127.in-addr.arpa name = localhost.

$ dig @"my server IP" 127.0.0.1
; (1 server found)
;; global options: +cmd
;; Got answer:
...
;; QUESTION SECTION:
;127.0.0.1. IN A

$ dig @"my server IP" localhost

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57309
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;localhost. IN A

;; ANSWER SECTION:
localhost. 10800 IN A 127.0.0.1

in
/etc/hosts is defined
127.0.0.1 localhost localhost."myservername".de
...
::1 localhost localhost."myservername".de

How can I find out, what is going wrong with "ping localhost"?
 
why are you pinging "localhost.de" - that's of course a valid domain under the .de TLD and has nothing to do with 'localhost'

whats your localdomain and the contents of your resolv.conf?
 
You should look at /etc/nsswitch.conf. It should have a line like so:
hosts: files dns
If the order is reversed (dns before files), ping will ask your DNS server to resolve "localhost", and it may be set wrong. If the order is as shown, make sure these following lines are in /etc/hosts:
::1 localhost localhost.my.domain
127.0.0.1 localhost localhost.my.domain
 
Thanks for help.
1) As I wrote, I set the settings in /etc/hosts as shown.
2) in /etc/nsswitch.conf I have
#HL ori: hosts: files dns
hosts: dns files
I have changed the order because I want that my DNS server comes first, before looking in /etc/hosts. But also without running my DNS server the ping to localhost is wrong.

3) sko pinging "localhost.de" is misunderstood. I have done this only to match the IP addresses
from ping -c2 localhost and ping -c2 localhost.de. They are the same.

4) ping -c2 -4 "local domain" give the correct IP.

5) $ grep -r '91.202.43.26' /etc and
$ grep -r '91.202.43.26' /usr/local/etc
$ grep -r '91.202.43.26' "chroot"/named/etc
gives no result.

I can not find out from where I get these wrong IP for localhost?
 
You can try "ktrace -di ping -c 1 localhost" and look at the output of "kdump" to see what is going on. Even without running bind9 locally, there may be other valid DNS entries in /etc/resolv.conf
 
Thanks for help.
I found some interesting by truss ping -c1 localhost:
in /etc/nsswitch.conf "– name-service switch configuration file"
I had changed "hosts: files dns" to "hosts: dns files", because I want that first my name server will be called and then /etc/hosts. But it seems that is a wrong assumption. I don't know why, but when I changed it back to the origin entry "hosts: files dns"
ping -c1 localhost gives me "::1" respectively
ping -4 -c1 localhost
"64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.095 ms"
So now it is OK.

in /etc/resolv.conf are this entries
nameserver 127.0.0.1
nameserver 8.8.8.8 # google
nameserver 208.67.222.222 #dns.opendns.com
 
I'm betting the DNS server that runs on 127.0.0.1 tacked .de on the short name. That caused it to resolve localhost.de.
 
Back
Top