The loopback device is a special, virtualnetwork 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 Purpose of Loopback
When a network interface is disconnected--for example, when an Ethernet port is unplugged or Wi-Fi is turned off or not associated with an access point--no communication on that interface is possible, not even communication between your computer and itself. The loopback interface does not represent any actual hardware, but exists so applications running on your computer can always connect to servers on the same machine.
This is important for troubleshooting (it can be compared to looking in a mirror). The loopback device is sometimes explained as purely a diagnostic tool. But it is also helpful when a server offering a resource you need is running on your own machine.
For example, if you run a web server, you have all your web documents and could examine them file by file. You may be able to load the files in your browser too, though with server-side active content, it won't work the way it does when someone accesses it normally.
So if you want to experience the same site others do, the best course is usually to connect to your own server. The loopback interface facilitates that.
Addresses on Loopback
For IPv4, the loopback interface is assigned all the IPs in the 127.0.0.0/8address block. That is, 127.0.0.1 through 127.255.255.254all represent your computer. For most purposes, though, it is only necessary to use one IP address, and that is 127.0.0.1. This IP has the hostname of localhost mapped to it.
Thus, to log in as bob via SSH to the SSH server running on your own machine, you would use:
ssh bob@localhost
Like other network adapters, the loopback device shows up in the output of ifconfig. Its name is lo.
One common, production (i.e., not just diagnostic) use of localhost on Ubuntu is to perform advanced printer configuration. In a web browser, go to:
http://localhost:631
CUPS runs a web server on port 631, and this can be used to configure printing, regardless of what GUI you are running (or even if you are not running a GUI at all).
If you try connecting to http://127.0.0.1:631, this will work too. However, if you try to connect to http://127.0.0.2, it will not. All the 127.*.*.* addresses identify your computer on the loopback interface, but a server program can decide to bind just to a specific IP address.
A Notable Difference from Windows
If you come from a Windows background, you might expect loopback to itself be a synonym of localhost (and thus to be able to ping loopback, connect to servers on loopback, and so forth). That behavior is peculiar to Windows.
But you canadd any name including loopback to your /etc/hosts file, with 127.0.0.1 as its address, and it will act like localhost.
Other Meanings of "Loopback"
The general concept of loopback is a mechanism through which a message or signal ends up (or loops) back to where it started.
So there are a few other ways loopback is use in Ubuntu that should not be confused with the loopback device in networking.
Loop Mounts
To mount a disk image in Ubuntu, you could run:
sudo mount -o loop image.iso /media/label
This is usually called a loop device (and not a loopback device), but the term loopback file interface is occasionally used.
This has nothing to do with the loopback device in networking.
Sound
Pulseaudio and other sound systems provide a mechanism to "connect" line-in to line-out, so that audio input is echoed back to your speakers/headphones. Pulseaudio's loopback module facilitates this.
Here, it is correct to use the term loopback, but like loop mounts, this also has nothing to do with the loopback device in networking. (And nothing to do with loop mounts, either.)
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 Purpose of Loopback
When a network interface is disconnected--for example, when an Ethernet port is unplugged or Wi-Fi is turned off or not associated with an access point--no communication on that interface is possible, not even communication between your computer and itself. The loopback interface does not represent any actual hardware, but exists so applications running on your computer can always connect to servers on the same machine.
This is important for troubleshooting (it can be compared to looking in a mirror). The loopback device is sometimes explained as purely a diagnostic tool. But it is also helpful when a server offering a resource you need is running on your own machine.
For example, if you run a web server, you have all your web documents and could examine them file by file. You may be able to load the files in your browser too, though with server-side active content, it won't work the way it does when someone accesses it normally.
So if you want to experience the same site others do, the best course is usually to connect to your own server. The loopback interface facilitates that.
Addresses on Loopback
For IPv4, the loopback interface is assigned all the IPs in the
127.0.0.0/8
address block. That is,127.0.0.1
through127.255.255.254
all represent your computer. For most purposes, though, it is only necessary to use one IP address, and that is127.0.0.1
. This IP has the hostname oflocalhost
mapped to it.Thus, to log in as
bob
via SSH to the SSH server running on your own machine, you would use:Like other network adapters, the loopback device shows up in the output of
ifconfig
. Its name islo
.An Example: CUPS
One common, production (i.e., not just diagnostic) use of
localhost
on Ubuntu is to perform advanced printer configuration. In a web browser, go to:CUPS runs a web server on port 631, and this can be used to configure printing, regardless of what GUI you are running (or even if you are not running a GUI at all).
If you try connecting to
http://127.0.0.1:631
, this will work too. However, if you try to connect tohttp://127.0.0.2
, it will not. All the127.*.*.*
addresses identify your computer on the loopback interface, but a server program can decide to bind just to a specific IP address.A Notable Difference from Windows
If you come from a Windows background, you might expect
loopback
to itself be a synonym oflocalhost
(and thus to be able to pingloopback
, connect to servers onloopback
, and so forth). That behavior is peculiar to Windows.loopback
to your/etc/hosts
file, with127.0.0.1
as its address, and it will act likelocalhost
.Other Meanings of "Loopback"
The general concept of loopback is a mechanism through which a message or signal ends up (or loops) back to where it started.
So there are a few other ways loopback is use in Ubuntu that should not be confused with the loopback device in networking.
Loop Mounts
To mount a disk image in Ubuntu, you could run:
This is usually called a loop device (and not a loopback device), but the term loopback file interface is occasionally used.
This has nothing to do with the loopback device in networking.
Sound
Pulseaudio and other sound systems provide a mechanism to "connect" line-in to line-out, so that audio input is echoed back to your speakers/headphones. Pulseaudio's loopback module facilitates this.
Here, it is correct to use the term loopback, but like loop mounts, this also has nothing to do with the loopback device in networking. (And nothing to do with loop mounts, either.)
Further Reading