Getting an ip for a host without nslookup - Sat, Oct 29, 2022
Getting an ip for a host without nslookup
When working with containerized applications you often find yourself using operating systems stripped down to the essentials needed to run the application. For example a Debian slim
or an alpine linux
. Since these containers might miss some of basic commands it is sometimes difficult to debug or troubleshoot issues at runtime.
In my particular case I was missing nslookup
for resolving host names in a bare centos
image. So I was searching for an alternative that would allow me name resolution. The getent
commands has an option called hosts
or for IpV4 ahostsv4
that does exactly that:
getent ahostsv4 google.com
142.251.209.142 STREAM google.com
142.251.209.142 DGRAM
142.251.209.142 RAW
Since this command is part of most of these slimed down linux variants it is an easy to use alternative to nslookup
.
P.S: Kubernetes offers ephemeral containers that allow you to attach any image (including one that contains more commands needed for troubleshooting) to a running Pod