Is there a config to change the behaviour of the name resolver of Amazon Linux 2 to not ignore entry about localhost
subdomains ?
i.e currently it does :
docker run -it amazonlinux:2023 /bin/bash -c "echo '172.4.0.2 app.localhost' >> /etc/hosts ; curl -v app.localhost "
* Trying 127.0.0.1:80...
while centos (or ubuntu) works "as expected"
docker run -it centos /bin/bash -c "echo '172.4.0.2 app.localhost' >> /etc/hosts ; curl -v app.localhost "
* Trying 172.4.0.2...
On our local development environment I have 2 docker
as the mock needs to be accessed both by the main application from the backend, but also by the frontend, having the mock being named app.localhost allows
getent hosts app.localhost
for both returns 172.4.0.2
2.34
and centos 2.28, and ubuntu 2.35 , so at least it's not a behaviour change in glibc/etc/nsswitch.conf
to match the one of my ubuntupasswd: files systemd
group: files systemd
shadow: files
gshadow: files
hosts: files mdns4_minimal [NOTFOUND=return] dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
Is there other places that may affect how localhost names are resolved ?
The difference comes from the version of curl
see https://daniel.haxx.se/blog/2021/05/31/curl-localhost-as-a-local-host/ and more specifically this commit https://github.com/curl/curl/commit/b5c0fe20e370ea2e5791fce4cedb34a71bc784e5#diff-e0b647f3e21a7fb58400dcec74f381d2fe16ca41e983240c15fc1243c574dbf9R733
i.e for domain name ending with .localhost
curl directly returns 127.0.0.1
and bypass all name resolving.
Their justification is that RFC 6761 explains
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)