Fix hosts file bug and tests

Thanks to @Danack