Utilitaire en ligne de commande Linux pour résoudre les noms d'hôtes en utilisant /etc/hosts en priorité

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Utilitaire en ligne de commande Linux pour résoudre les noms d'hôtes en utilisant /etc/hosts en priorité

Message par ForumBot »

There are several command line utilities to resolve host names (host, dig, nslookup), however they all use nameservers exclusively, while applications in general look in /etc/hosts first (using gethostbyname I believe).


Is there a command line utility to resolve host names that behaves like a usual application, thus looking in /etc/hosts first and only then asking a nameserver?


(I am aware that it would probably be like 3 lines of c, but I need it inside of a somewhat portable shell script.)

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

Re: Utilitaire en ligne de commande Linux pour résoudre les noms d'hôtes en utilisant /etc/hosts en priorité

Message par ayi »

This is easily achieved with getent:


getent hosts 127.0.0.1


getent will do lookups for any type of data configured in nsswitch.conf.

Répondre

Revenir à « Windows 11 »