In /etc/hosts
, you can define the (local) mapping of hostnames to IPs. Thus, you cannot put localhost
here, because you want to map the IP of your server to the hostname mail.mydomain.com
. You cannot map hostnames to hostnames this way.
Normally, you should map the Internet accessible IP to the Internet accessible (FQN) hostname (like mail.mydomain.com
).
In any case, it must be an IP that your server can access itself through. Sometimes, e.g, behind a NAT (like a home router connecting multiple devices to the Internet), it can make sense to use a local IP like 192.168.0.102
or even 127.0.0.1
here. This way, you do not necessarily need the NAT reflection of your router to work correctly.
In any case, the local IP can (additionally) be mapped to a local hostname. The loopback IP 127.0.0.1
usually is mapped to localhost
by default. You can additionally map local hostnames like mailserver1
to local IPs like 192.168.0.102
.