3

Why is macos ignoring etc/hosts

I have seen this: /etc/hosts file being ignored

And it is not a TAB but a space between ip address and domain.

Is there something special you need to do on MacOS to use etc/hosts.

I have a local sige mydns.com in etc/hosts:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
172.18.0.0 *.mydns.com

When I do curl subdomain.mydns.com it goes out to the nameservers getting the Internet ip address and not the local ip address specified in the etc/hosts?

Chris G.
  • 157
  • 5
  • 4
    Does this answer your question? [In my /etc/hosts/ file on Linux/OSX, how do I do a wildcard subdomain?](https://serverfault.com/questions/118378/in-my-etc-hosts-file-on-linux-osx-how-do-i-do-a-wildcard-subdomain) – vidarlo Jun 26 '21 at 12:59
  • Hmm interesting – Chris G. Jun 26 '21 at 13:00
  • 4
    You don't. Wildcards aren't valid in the hosts file. The linked question provides a variety of different workarounds that you may consider for your specific situation. – Michael Hampton Jun 26 '21 at 13:41

1 Answers1

1

The HOSTS file of all of todays operating systems can contain letters and some symbols. The is no such thing as "wildcards" in the basic internet naming system (rfc882), so as the most basic name resolution table. For example, it doesn't deal with providing additional information, wildcards, QCLASS=*, or overlapping zones.

If you want to redirect a large number of hostnames (*) I would recommend using a DNS server or at least a DNS proxy allowing that.

bjoster
  • 4,423
  • 5
  • 22
  • 32