dns.reverse uses /etc/hosts, but not the first entry · Issue #64257 · nodejs/node · GitHub
Skip to content

dns.reverse uses /etc/hosts, but not the first entry #64257

Description

@FlavorsDev

Version

v22.20.0

Platform

Linux MY_LAPTOP 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux

Subsystem

dns

What steps will reproduce the bug?

An /etc/hosts file with the contents,

127.0.0.1    localhost

And the following Node script,

const dns = require("dns");

dns.reverse("127.0.0.1", (err, results) => { console.log(err, results) }); // null []

If the /etc/hosts file instead looks like this,

127.0.0.1    localhost my-domain.local sub.my-domain.local # etc, etc,

Then the same node script will instead print out null, ['my-domain.local', 'sub.my-domain.local' /* etc */ ]

How often does it reproduce? Is there a required condition?

This is 100% reproduceable and confirmed with another person over Discord.

What is the expected behavior? Why is that the expected behavior?

This expected behavior would either to have dns.reverse return no results at all, as per the documentation, or to have it return all records associated an address, and not just the aliases.

What do you see instead?

Instead, I see the results from the /etc/hosts file sans the canonical name.

null, ['my-domain.com', /* etc */]

Additional information

The documentation for the dns module states that dns.resolve states that this function doesn't use the "configuration" from the etc/hosts file. Evidently it does use this file, but it ignores the canonical name of an address there, and instead only shows aliases.

From the documentation it is unclear if this is intended behavior or not

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions