What is a loopback interface?

7

I was experiencing socket connection problems on my server:

What causes the error [could not bind to" tcp: //127.0.0.1: 8843 ". Can not assign request adress]?

I was able to solve the problem. The technician told me the problem was that "the loopback interface was stopped and had to be started."

As I said before, I'm very technical.

So I would like to understand what a loopback interface is.

And why, when I stopped running, did any code that used sockets with 127.0.0.1 stopped working, only being accepted 0.0.0.0 ?

    
asked by anonymous 12.01.2016 / 14:43

1 answer

3

The loopback interface is a virtual network interface used basically for two purposes:

  • Diagnostics;
  • For developing and testing systems that require a network interface with an IP (Webservers, etc.).

On a Linux system, type ifconfig to check its loopback interface:

ifconfig


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:353933 errors:0 dropped:0 overruns:0 frame:0
          TX packets:353933 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:584828381 (584.8 MB)  TX bytes:584828381 (584.8 MB)

Because it is a network interface, you can stop it:

sudo ifconfig lo down

As well as raising it:

sudo ifconfig lo up

The diagnostic part can be used, for example, to check if your machine is running the ssh server. Try this:

ssh user@localhost

If the machine in question has an SSH server listening on port 22, then the machine itself will be accessed from SSH via SSH (see the loopback going on). : -)

In the system development part, the loopback interface is widely used when it is desired to develop and run the server (web, tcp, etc) on the machine itself. Example of an address when developing Java + Tomcat: link or

It is interesting to note that the range of IPs associated with this interface is 127.0.0.0/8 . Therefore, you can ping any of the addresses from 127.0.0.1 to 127.255.255.254 that this interface will respond. However, the most famous is the first, 127.0.0.1 . It is usually at this IP that the famous hostname localhost is associated.

    
12.01.2016 / 19:05