You need the NSS (name service switch, see man 5 nss) module "mymachines" installed and enabled in /etc/nsswitch.conf like this. Place "mymachines" before the "resolve" or "dns" entry of the "hosts:" line of /etc/nsswitch.conf (see man 8 nss-mymachines):
hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns OnIf "mymachines" is already present in /etc/nsswitch.conf and still doesn't work - its priority is too low. Try moving it before "resolve" or "dns".
On Debian, you need the libnss-mymachines package, for example.