I am just learning using Ubuntu and when I tried to configure the DNS, I need to deal with something call localhost, loopback interface. Can anyone explain me the differences between them and the meaning of the addresses and, when should I use and when should I use


4 Answers 4


As your machine gets started, it will need to know the mapping of some hostnames to IP addresses before DNS can be referenced. This mapping is kept in the /etc/hosts file. In the absence of a name server, any network program on your system consults this file to determine the IP address that corresponds to a host name.

The loopback device is a special, virtual network interface that your computer uses to communicate with itself. It is used mainly for diagnostics and troubleshooting, and to connect to servers running on the local machine.

The loopback is interface lo and the IP address is by default. localhost

Debian, then Ubuntu, choose to define for mapping the IP address of your host_name in case that you have no network.

The host_name matches the hostname defined in /etc/hostname.

For a system with a permanent IP address, that permanent IP address should be used here instead of host_name
  • 1
    I understand the philosophy, but I disagree with the form of it in /etc/hosts. Commented Jul 1, 2019 at 14:53

It doesn't really mean anything in particular (it's just another IP in the block).

The reason it's used as the IP for your hostname is explained in Section 10.4 of the Debian Reference Manual.


Some software (e.g., GNOME) expects the system hostname to be resolvable to an IP address with a canonical fully qualified domain name. This is really improper because system hostnames and domain names are two very different things; but there you have it. In order to support that software, it is necessary to ensure that the system hostname can be resolved. Most often this is done by putting a line in /etc/hosts containing some IP address and the system hostname. If your system has a permanent IP address then use that; otherwise use the address


The following screen capture tells an interesting story.

Ubuntu default /etc/hosts file and ifconfig output

Effectively, it shows that is the true loopback address. Thus, is there for reasons other than that of basic IP networking.

As mentioned by @Videonauth, the line is there as a crutch, a fix, to make finicky software be happy.

In my view, the loopback entry should almost always be in /etc/hosts. If you change your hostname from the default of localhost, then change the host name on the line, not the line.

If you change your hostname and give your machine a static IP, change both the hostname and IP fields in the line.

In short, leave the record alone.

  • 2
    So to sum up, if you have applied a static ip say, then the line should be replaces with hostname.Is that correct? Commented Sep 19, 2019 at 20:58
  • 2 <hostname> Yes. Commented Sep 21, 2019 at 23:28
  • Thank you, I wasnt sure, im setting up a few vm's and the host files all had that in, i understood it was a loopback for some applications but then so was, so i wasnt sure if it had to stay or not. Commented Sep 22, 2019 at 1:05
2 is the loopback address, commonly known as localhost, which is the name that resolves to it by the local hosts file. This file is in different locations depending on the OS, but in most Linux distros it is in /etc/hosts. This address always refers to the computer which made the request, so is not a "real" address so to speak. Each device has it's own localhost. on the other hand is used by certain software to mean the same thing, an alias in a way, but not really. The loopback address used by your machine internally should be, so don't mess around with that address in your hosts file!

You must log in to answer this question.

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