localhost, 127.0.0.1, server IP, host name: which is best?

sysnop

Member
May 22, 2005
12
0
151
I realize this is a broad question if asked in the context of various daemons, services, scripts, etc. I'm relating to WHM's resolver setup, when it was adviseable to replace the local host IP (127.0.0.1) with the server's main IP for security reasons, which made sense. So when does it not make sense to replace localhost settings with something more specific?

Let's take my mail system as an example:

In squirrelmail/config/config.php, for the $domain, $imapServerAddress, and $smtpServerAddress entries, should 'localhost' be replaced by the server's host name or IP? When I look into it, some say to do it this way, others say to do it the other way, while nobody disagrees that 'localhost' will always work.

Another case in point are my courier-imap/imapd and pop3d files, which seem to be using 127.0.0.1. Would I be better off using the server's IP?
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
33
473
Go on, have a guess
You only need to use the servers IP address if you want to either put the requests through a local iptables firewall or because of other security concerns. I'm only aware of the bind issue because of the trusing nature of daemons with port 127.0.0.1 (i.e. the loopback device).

Normally, it's cheaper, performance wise (though very negligable) to route local IP traffic through 127.0.0.1, so you may as well use that. You can use localhost if you want, which is only there if for some bizarre reason you wanted to point localhost to some other IP address. If you do use localhost, make sure it's defined as 127.0.0.1 in /etc/hosts.
 

sysnop

Member
May 22, 2005
12
0
151
Thanks for the info.

If I use the server's host name in the imapd and Squirrelmail configs, will it speed up the lookup process? For now I've got DNS lookup disabled wherever it's an option. But mail in general seems too slow. Converting to maildir was supposed to help but I haven't noticed any enhancement over mbox in terms of speed.
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
33
473
Go on, have a guess
If speed is of concern then using IP addresses is best as it avoids the lookup. However, the main problem with that is if you change IP addresses and they'll then be stuffed ;)