0

I'm setting up a mail server on my debian by following the tecmint tutorial.

In step 4 the ip should be added in the hosts file.

# hostnamectl set-hostname mail.mydomain.com
# echo "192.168.0.102 mydomain.com mail.mydomain.com" >> /etc/hosts

what kind of IP i have to use here? is that the locale ip of the machine or the IP of the server(Internet ip)?

if it is the local IP, can I also use localhost here?

1
  • Shouldn't it be # echo "192.168.0.102 mail mail.mydomain.com" >> /etc/hosts ?
    – alexfvolk
    Feb 20, 2020 at 18:46

2 Answers 2

1

You must put IP address there, localhost or any other name is not allowed. It must be IP address available locally on your server. If your server has internet IP assigned to one of its interfaces, use it here, otherwise you may use local IP. There is no much difference as long as this IP is assigned to your server - use ip addr show to check if unsure.

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .