On Fri 28 Aug 2015 at 17:00:59 +0300, Reco wrote: > Hi. > > On Fri, 28 Aug 2015 14:35:09 +0100 > Brian <a...@cityscape.co.uk> wrote: > > > On Fri 28 Aug 2015 at 14:45:32 +0300, Reco wrote: > > > > > Hi. > > > > > > On Fri, 28 Aug 2015 12:09:08 +0100 > > > Brian <a...@cityscape.co.uk> wrote: > > > > > > > On Fri 28 Aug 2015 at 10:01:59 +0000, Curt wrote: > > > > > > > > > On 2015-08-28, David Wright <deb...@lionunicorn.co.uk> wrote: > > > > > > > > > > > > $ host localhost > > > > > > Host localhost not found: 3(NXDOMAIN) > > > > > > $ ping localhost > > > > > > PING localhost (127.0.0.1) 56(84) bytes of data. > > > > > > 64 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.032 ms > > > > > > > > > > curty@einstein:~$ host localhost > > > > > localhost has address 127.0.0.1 > > > > > localhost has IPv6 address ::1 > > > > > > > > To complete the picture: > > > > > > > > brian@desktop:~$ dig -x 127.0.0.1 > > > > > > > > ; <<>> DiG 9.9.5-9-Debian <<>> -x 127.0.0.1 > > > > ;; global options: +cmd > > > > ;; Got answer: > > > > ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7146 > > > > ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: > > > > 1 > > > > > > > > ;; OPT PSEUDOSECTION: > > > > ; EDNS: version: 0, flags:; udp: 4096 > > > > ;; QUESTION SECTION: > > > > ;1.0.0.127.in-addr.arpa. IN PTR > > > > > > > > ;; ANSWER SECTION: > > > > 1.0.0.127.in-addr.arpa. 10800 IN PTR localhost. > > > > > > > > ;; Query time: 24 msec > > > > ;; SERVER: 158.152.1.43#53(158.152.1.43) > > > > ;; WHEN: Fri Aug 28 12:03:15 BST 2015 > > > > ;; MSG SIZE rcvd: 74 > > > > > > > > host and dig use only the DNS. > > > > > > > > Elimar's suggestion to use 'host $(hostname)' will work if hostname is > > > > a FQDN. But it shouldn't (or wouldn't) be on a stock Debian system. > > > > > > Not unless said 'stock Debian system' has 'search <domain>' stanza > > > in /etc/resolv.conf. > > > > Does "search example.org" count? :) > > It should count for the hosts in this domain. Provided, of course, that > one needs to resolve 'bare' hostnames (i.e. non-FQDN). > > > > What is not understandable (to me) is why 'host localhost' resolves for > > some but not for others and why it is thought 'host $(hostname)' should > > resolve in the DNS. > > Stock Debian BIND configuration includes this wonderful snippet > (/etc/bind/db.local): > > ; > ; BIND data file for local loopback interface > ; > $TTL 604800 > @ IN SOA localhost. root.localhost. ( > 2 ; Serial > 604800 ; Refresh > 86400 ; Retry > 2419200 ; Expire > 604800 ) ; Negative Cache TTL > ; > @ IN NS localhost. > @ IN A 127.0.0.1 > @ IN AAAA ::1 > > Translating this to English - every BIND installed on Debian considers > itself the final authority on "localhost" zone and always returns > 127.0.0.1 for A queries (IPv4) and ::1 for AAAA queries (IPv6). > Other Linux distributions can store zone files elsewhere, but the > principle is the same. > Interpreting /etc/bind/db.127 (PTR entries) is left for an exercise for > the readers. > > > So - 'host localhost' *should* work given an ideal world (because in > ideal world everyone will use an ideal DNS, which is BIND). But: > > a) There are other DNSes. Some of them even may be configured in a sane > way, if you're lucky. In the case of doubt - use 'dig' or 'tcpdump'. > > b) There's endless amount of quirks in client resolvers. In layman > terms - 'which part of "search" should I append to the bare hostname'. > In the case of doubt - use 'tcpdump'.
Thanks for the nice explanation. It lead me to RFC 6761 https://tools.ietf.org/html/rfc6761 There it says: Name resolution APIs and libraries SHOULD recognize localhost names as special and SHOULD always return the IP loopback address for address queries and negative responses for all other query types. Name resolution APIs SHOULD NOT send queries for localhost names to their configured caching DNS server(s). I think I'll leave this topic at this point before I get in over my head, but the implication here is that a resolver not giving 127.0.0.1 for localhost is broken in some way.