Why does *.localhost resolve to 127.0.0.1 and ::1?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I discovered by chance (trying to access a proxied service in a Docker container on a Vagrant box using servicename.docker.localhost from the host) that any hostname ending in ".localhost" resolves to 127.0.0.1 or ::1 on my machine:
$ ping -4 -c1 -n foo.localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.147 ms
--- localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.147/0.147/0.147/0.000 ms
$ ping -6 -c1 -n foo.localhost
PING foo.localhost(::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.072 ms
--- foo.localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.072/0.072/0.072/0.000 ms
However, there is no DNS entry for this:
$ nslookup -type=AAAA foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
$ nslookup -type=A foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
/etc/hosts doesn't look particularly relevant:
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
::1 localhost.localdomain localhost
Neither does /etc/resolv.conf:
domain my-work-domain
search my-work-domain
nameserver 192.[â¦]
nameserver 192.[â¦]
Why does *.localhost magically resolve?
This is similar but possibly distinct from this question.
$ getent hosts
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
$ getent hosts foo.localhost
::1 localhost
arch-linux dns
add a comment |Â
up vote
3
down vote
favorite
I discovered by chance (trying to access a proxied service in a Docker container on a Vagrant box using servicename.docker.localhost from the host) that any hostname ending in ".localhost" resolves to 127.0.0.1 or ::1 on my machine:
$ ping -4 -c1 -n foo.localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.147 ms
--- localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.147/0.147/0.147/0.000 ms
$ ping -6 -c1 -n foo.localhost
PING foo.localhost(::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.072 ms
--- foo.localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.072/0.072/0.072/0.000 ms
However, there is no DNS entry for this:
$ nslookup -type=AAAA foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
$ nslookup -type=A foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
/etc/hosts doesn't look particularly relevant:
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
::1 localhost.localdomain localhost
Neither does /etc/resolv.conf:
domain my-work-domain
search my-work-domain
nameserver 192.[â¦]
nameserver 192.[â¦]
Why does *.localhost magically resolve?
This is similar but possibly distinct from this question.
$ getent hosts
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
$ getent hosts foo.localhost
::1 localhost
arch-linux dns
What doesgetent
say?
â Ignacio Vazquez-Abrams
May 28 at 0:16
Are you using systemd? It has a last resort resolver that (if none other nameserver resolved it before) resolves localhost to::1
.
â Isaac
May 28 at 9:04
@Isaac I think you can write that as an answer. From the page you linked to: "systemd-resolved synthesizes DNS resource records (RRs) for the following cases: [...] any hostname ending in ".localhost" or ".localhost.localdomain") are resolved to the IP addresses 127.0.0.1 and ::1"
â Johan Myréen
May 28 at 15:47
Also just FYI, before/etc/resolv.conf
and/etc/hosts
there is/etc/nsswitch.conf
which controls what sources the libc resolver uses, and in what order.grep '^hosts:' /etc/nsswitch.conf
.
â Patrick
May 28 at 19:54
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I discovered by chance (trying to access a proxied service in a Docker container on a Vagrant box using servicename.docker.localhost from the host) that any hostname ending in ".localhost" resolves to 127.0.0.1 or ::1 on my machine:
$ ping -4 -c1 -n foo.localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.147 ms
--- localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.147/0.147/0.147/0.000 ms
$ ping -6 -c1 -n foo.localhost
PING foo.localhost(::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.072 ms
--- foo.localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.072/0.072/0.072/0.000 ms
However, there is no DNS entry for this:
$ nslookup -type=AAAA foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
$ nslookup -type=A foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
/etc/hosts doesn't look particularly relevant:
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
::1 localhost.localdomain localhost
Neither does /etc/resolv.conf:
domain my-work-domain
search my-work-domain
nameserver 192.[â¦]
nameserver 192.[â¦]
Why does *.localhost magically resolve?
This is similar but possibly distinct from this question.
$ getent hosts
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
$ getent hosts foo.localhost
::1 localhost
arch-linux dns
I discovered by chance (trying to access a proxied service in a Docker container on a Vagrant box using servicename.docker.localhost from the host) that any hostname ending in ".localhost" resolves to 127.0.0.1 or ::1 on my machine:
$ ping -4 -c1 -n foo.localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.147 ms
--- localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.147/0.147/0.147/0.000 ms
$ ping -6 -c1 -n foo.localhost
PING foo.localhost(::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.072 ms
--- foo.localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.072/0.072/0.072/0.000 ms
However, there is no DNS entry for this:
$ nslookup -type=AAAA foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
$ nslookup -type=A foo.localhost
Server: 192.168.2.82
Address: 192.168.2.82#53
** server can't find foo.localhost: NXDOMAIN
/etc/hosts doesn't look particularly relevant:
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
::1 localhost.localdomain localhost
Neither does /etc/resolv.conf:
domain my-work-domain
search my-work-domain
nameserver 192.[â¦]
nameserver 192.[â¦]
Why does *.localhost magically resolve?
This is similar but possibly distinct from this question.
$ getent hosts
127.0.0.1 my-machine-name.my-work-domain my-machine-name localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
$ getent hosts foo.localhost
::1 localhost
arch-linux dns
edited May 28 at 3:39
asked May 27 at 23:34
l0b0
26k17104226
26k17104226
What doesgetent
say?
â Ignacio Vazquez-Abrams
May 28 at 0:16
Are you using systemd? It has a last resort resolver that (if none other nameserver resolved it before) resolves localhost to::1
.
â Isaac
May 28 at 9:04
@Isaac I think you can write that as an answer. From the page you linked to: "systemd-resolved synthesizes DNS resource records (RRs) for the following cases: [...] any hostname ending in ".localhost" or ".localhost.localdomain") are resolved to the IP addresses 127.0.0.1 and ::1"
â Johan Myréen
May 28 at 15:47
Also just FYI, before/etc/resolv.conf
and/etc/hosts
there is/etc/nsswitch.conf
which controls what sources the libc resolver uses, and in what order.grep '^hosts:' /etc/nsswitch.conf
.
â Patrick
May 28 at 19:54
add a comment |Â
What doesgetent
say?
â Ignacio Vazquez-Abrams
May 28 at 0:16
Are you using systemd? It has a last resort resolver that (if none other nameserver resolved it before) resolves localhost to::1
.
â Isaac
May 28 at 9:04
@Isaac I think you can write that as an answer. From the page you linked to: "systemd-resolved synthesizes DNS resource records (RRs) for the following cases: [...] any hostname ending in ".localhost" or ".localhost.localdomain") are resolved to the IP addresses 127.0.0.1 and ::1"
â Johan Myréen
May 28 at 15:47
Also just FYI, before/etc/resolv.conf
and/etc/hosts
there is/etc/nsswitch.conf
which controls what sources the libc resolver uses, and in what order.grep '^hosts:' /etc/nsswitch.conf
.
â Patrick
May 28 at 19:54
What does
getent
say?â Ignacio Vazquez-Abrams
May 28 at 0:16
What does
getent
say?â Ignacio Vazquez-Abrams
May 28 at 0:16
Are you using systemd? It has a last resort resolver that (if none other nameserver resolved it before) resolves localhost to
::1
.â Isaac
May 28 at 9:04
Are you using systemd? It has a last resort resolver that (if none other nameserver resolved it before) resolves localhost to
::1
.â Isaac
May 28 at 9:04
@Isaac I think you can write that as an answer. From the page you linked to: "systemd-resolved synthesizes DNS resource records (RRs) for the following cases: [...] any hostname ending in ".localhost" or ".localhost.localdomain") are resolved to the IP addresses 127.0.0.1 and ::1"
â Johan Myréen
May 28 at 15:47
@Isaac I think you can write that as an answer. From the page you linked to: "systemd-resolved synthesizes DNS resource records (RRs) for the following cases: [...] any hostname ending in ".localhost" or ".localhost.localdomain") are resolved to the IP addresses 127.0.0.1 and ::1"
â Johan Myréen
May 28 at 15:47
Also just FYI, before
/etc/resolv.conf
and /etc/hosts
there is /etc/nsswitch.conf
which controls what sources the libc resolver uses, and in what order. grep '^hosts:' /etc/nsswitch.conf
.â Patrick
May 28 at 19:54
Also just FYI, before
/etc/resolv.conf
and /etc/hosts
there is /etc/nsswitch.conf
which controls what sources the libc resolver uses, and in what order. grep '^hosts:' /etc/nsswitch.conf
.â Patrick
May 28 at 19:54
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
This is caused by the myhostname
NSS module which defines the hostname and any name ending in .localhost as 127.0.0.1 in ipv4 and ::1 in ipv6.
https://www.freedesktop.org/software/systemd/man/nss-myhostname.html
nss-systemd could theoretically do something similar but not only is Arch Linux not configured like this by default nor is systemd.
â jdwolf
May 28 at 20:49
You nailed it - /etc/nsswitch.conf enablesmyhostname
.
â l0b0
May 28 at 20:58
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
This is caused by the myhostname
NSS module which defines the hostname and any name ending in .localhost as 127.0.0.1 in ipv4 and ::1 in ipv6.
https://www.freedesktop.org/software/systemd/man/nss-myhostname.html
nss-systemd could theoretically do something similar but not only is Arch Linux not configured like this by default nor is systemd.
â jdwolf
May 28 at 20:49
You nailed it - /etc/nsswitch.conf enablesmyhostname
.
â l0b0
May 28 at 20:58
add a comment |Â
up vote
3
down vote
accepted
This is caused by the myhostname
NSS module which defines the hostname and any name ending in .localhost as 127.0.0.1 in ipv4 and ::1 in ipv6.
https://www.freedesktop.org/software/systemd/man/nss-myhostname.html
nss-systemd could theoretically do something similar but not only is Arch Linux not configured like this by default nor is systemd.
â jdwolf
May 28 at 20:49
You nailed it - /etc/nsswitch.conf enablesmyhostname
.
â l0b0
May 28 at 20:58
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
This is caused by the myhostname
NSS module which defines the hostname and any name ending in .localhost as 127.0.0.1 in ipv4 and ::1 in ipv6.
https://www.freedesktop.org/software/systemd/man/nss-myhostname.html
This is caused by the myhostname
NSS module which defines the hostname and any name ending in .localhost as 127.0.0.1 in ipv4 and ::1 in ipv6.
https://www.freedesktop.org/software/systemd/man/nss-myhostname.html
answered May 28 at 20:48
jdwolf
2,362116
2,362116
nss-systemd could theoretically do something similar but not only is Arch Linux not configured like this by default nor is systemd.
â jdwolf
May 28 at 20:49
You nailed it - /etc/nsswitch.conf enablesmyhostname
.
â l0b0
May 28 at 20:58
add a comment |Â
nss-systemd could theoretically do something similar but not only is Arch Linux not configured like this by default nor is systemd.
â jdwolf
May 28 at 20:49
You nailed it - /etc/nsswitch.conf enablesmyhostname
.
â l0b0
May 28 at 20:58
nss-systemd could theoretically do something similar but not only is Arch Linux not configured like this by default nor is systemd.
â jdwolf
May 28 at 20:49
nss-systemd could theoretically do something similar but not only is Arch Linux not configured like this by default nor is systemd.
â jdwolf
May 28 at 20:49
You nailed it - /etc/nsswitch.conf enables
myhostname
.â l0b0
May 28 at 20:58
You nailed it - /etc/nsswitch.conf enables
myhostname
.â l0b0
May 28 at 20:58
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446371%2fwhy-does-localhost-resolve-to-127-0-0-1-and-1%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What does
getent
say?â Ignacio Vazquez-Abrams
May 28 at 0:16
Are you using systemd? It has a last resort resolver that (if none other nameserver resolved it before) resolves localhost to
::1
.â Isaac
May 28 at 9:04
@Isaac I think you can write that as an answer. From the page you linked to: "systemd-resolved synthesizes DNS resource records (RRs) for the following cases: [...] any hostname ending in ".localhost" or ".localhost.localdomain") are resolved to the IP addresses 127.0.0.1 and ::1"
â Johan Myréen
May 28 at 15:47
Also just FYI, before
/etc/resolv.conf
and/etc/hosts
there is/etc/nsswitch.conf
which controls what sources the libc resolver uses, and in what order.grep '^hosts:' /etc/nsswitch.conf
.â Patrick
May 28 at 19:54