localhost domain bypasses /etc/hosts file

You can't. The localhost is already reserved as a Special-Use Domain Name (RFC 6761, 6.3).

The domain localhost. and any names falling within .localhost. are special in the following ways: - -

  1. Name resolution APIs and libraries SHOULD recognize localhost names as special and SHOULD always return the IP loopback address for address queries and negative responses for all other query types. Name resolution APIs SHOULD NOT send queries for localhost names to their configured caching DNS server(s).

You may have confused this with .local, widely used in private networks and reserved special-use domain name for Multicast DNS (mDNS) in RFC 6762. When using .local, try avoid resolving those names using global DNS. Using .local in Active Directory is a classic example of very bad implementation causing unnecessary queries to L root name server.