How to fix when I can nslookup and dig an internal hostname, but I cannot ping or ssh to the internal machine?
Starting from Lion (except Yosemite between 10.10 and 10.10.3), the command for flushing the DNS cache is:

$ sudo killall -HUP mDNSResponder


There is a solution at https://superuser.com/questions/326848/strange-ns-behavior-on-os-x-cant-connect-to-ssh-server.