Hostfile not working for subdomain

dnshostsNetwork

I'm trying to setup custom A records for domains via /etc/hosts on my OSX 10.13.2 MBP.

It usually works just fine, first time that it works only for 1 of the 2 domains:

  • 1.2.3.4 dev.com (works; points to 1.2.3.4)
  • 1.2.3.4 admin.dev.com (doesn't work; points to live IP 5.6.7.8)

I tried flushing DNS cache as well without success using:

sudo dscacheutil -flushcache

Pinging both domains returns 100% packet loss

PING dev.com (1.2.3.4): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5

Also tried different browsers (Opera, Firefox, Safari) as I know Chrome is pretty agressive with DNS caching.

Any idea?

EDIT: IP adresses and domains are pure fiction here.

Best Answer

Based on @user3439894 comment to the original question, directly killing mDNSResponder processes fixed the issue for me.

Command used was:

sudo killall -HUP mDNSResponder

From the killall manual page:

killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent.

Signals can be specified either by name (e.g. -HUP or -SIGHUP ) or by number (e.g. -1) or by option -s.