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...
Why do I need this
On our local development environment I have 2 docker
- one with our main application, running on a Amazon Linux 2 (to be as close as possible to production environment)
- one containing a mock of an other HTTP service
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
- on the frontend to use the fact that we don't need to create extra /etc/hosts entry
- both frontend and backend use the same name/env variable containing the hostname, which is also the case in production
What I've checked
- both have the same `/etc/host.conf config
getent hosts app.localhostfor both returns172.4.0.2- the glic version of Amazon Linux 2 is
2.34and centos 2.28, and ubuntu 2.35 , so at least it's not a behaviour change in glibc - change the
/etc/nsswitch.confto match the one of my ubuntu
passwd: 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
curlsee 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
.localhostcurl directly returns127.0.0.1and bypass all name resolving.Their justification is that RFC 6761 explains