Assuming the following is defined in .../hosts:
127.0.0.1 localhost
What, if any, are the actual differences between using 127.0.0.1 and localhost as the server name, especially when hitting processes running locally that are listening for connections?
Well, the most likely difference is that you still have to do an actual lookup of
localhostsomewhere.If you use
127.0.0.1, then (intelligent) software will just turn that directly into an IP address and use it. Some implementations ofgethostbynamewill detect the dotted format (and presumably the equivalent IPv6 format) and not do a lookup at all.Otherwise, the name has to be resolved. And there’s no guarantee that your
hostsfile will actually be used for that resolution (first, or at all) solocalhostmay become a totally different IP address.By that I mean that, on some systems, a local
hostsfile can be bypassed. Thehost.conffile controls this on Linux (and many other Unices).