Ubuntu uses the Avahi Daemon to rewrite .local domains to always be localhost. This can be prevented by editing the config file sudo gedit /etc/avahi/avahi-daemon.conf
and setting changing #domain-name=local
into domain-name=.localhost
(note that there needs to be a . between the name you select and the = mark. After doing this run sudo service avahi-daemon restart
to make the changes happen.