Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let's use getent ahosts instead of dig +short #355

Open
vazhnov opened this issue Dec 9, 2024 · 2 comments
Open

Let's use getent ahosts instead of dig +short #355

vazhnov opened this issue Dec 9, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@vazhnov
Copy link

vazhnov commented Dec 9, 2024

Hello!

Thank you for the project!

I recommend to use getent ahosts NAME instead of dig +short NAME in this course, for both: manual steps in the documentation and scripts.

getent is a tool usually included into even very minimalistic OS setup.

getent follows /etc/nsswitch.conf rules (reads /etc/hosts, mDNS, etc.), while dig is mainly designed to troubleshoot external DNS servers. Much more details about the difference can be found in https://unix.stackexchange.com/questions/20784/ (or in my brief summary).

I think using dig is a bad practice when custom records in /etc/hosts are used. getent is designed for such cases.

I'm currently in step 08 and I see no issues with this replacement.

Also I've checked: using getent ahosts is compatible with both Vagrant images, Ubuntu and Debian, to do steps of this course.

Currently script vagrant/ubuntu/update-dns.sh fails to apply in Debian let's skip this for dedicated issue.

@vazhnov vazhnov added the bug Something isn't working label Dec 9, 2024
@fireflycons
Copy link
Collaborator

I'm using dig +short because it returns only the IP address with no need to muck about with awk to get it. getent will return IP+HOST
The lab's not millisecond performance critical so if dig does waste time getting a negative response from DNS before checking hosts file, not really an issue.

@vazhnov
Copy link
Author

vazhnov commented Dec 10, 2024

I'm using dig +short because it returns only the IP address with no need to muck about with awk to get it. getent will return IP+HOST

I agree, I have to use getent ahosts example.com | awk '{ print $1 ; exit }' to return only one IP-address without name.

The lab's not millisecond performance critical so if dig does waste time getting a negative response from DNS before checking hosts file, not really an issue.

The thing is — dig doesn't use /etc/hosts at all. In case of the lab, I think that systemd-resolved is doing that.

This change is also about to teach people to use proper tools.

vazhnov added a commit to vazhnov/kubernetes-the-hard-way__vagrant that referenced this issue Dec 18, 2024
…` rules (reads `/etc/hosts`, mDNS, etc.), instead of `dig +short`

See mmumshad#355
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants