Why not assign the hostname to the loopback address in /etc/hosts?
Solution 1:
It could be a bad idea, for several reasons
-
if you do have an ip (and communicate to other hosts), its highly recommended to put the hostname in front of the externally known ip.
Some protocols could say "tell the other guy your hostname and its ip address" "ok. Other guy, i'm foo.localnetwork(127.0.0.1)". The other guy will receive this packet with, at the IP level the external IP, but at the Protocol level, the 127.0.0.1 IP, so it could have a hard time to exchange if that protocol needs to use the advertised info instead of the IP level ones (SIP, for example, is likely to be problematic with this...)
Additionnaly some services bind only on the interface holding the ip associated to the hostname and therefore those services will only be able to talk with the host, via loopback device, no-one else...
Solution 2:
This is the default, at least on new Ubuntu releases.
Here is my /etc/hosts
configuration:
127.0.0.1 localhost.localdomain localhost
127.0.1.1 sprinkler.internal.lan sprinkler
It is not problematic in any way and, in fact, it has the bonus effect of not needing a working DNS for some operations.
I personally tend to add few more entries like local apt repo, some builders etc.