Command for resolving ip address for host entry in /etc/hosts?

Solution 1:

On macOS you can use dscacheutil, the Directory Service Cache Utility, for this purpose.

dscacheutil -q host -a name localhost                                                                     

The output looks like:

name: localhost
ipv6_address: ::1

name: localhost
ip_address: 127.0.0.1

(On Linux, the equivalent is getent.)