Cisco IOS Loopback Interface

A loopback interface is a virtual interface on a Cisco router. It’s software-only: there is no port, no cable, and no hardware that can fail. Once you create it, it stays up until you shut it down with the shutdown command (or the router itself goes down).

This makes the loopback interface perfect for an IP address that should always be available, no matter which physical interfaces are up or down. Some examples:

  • A stable address to manage the router with SSH, SNMP, syslog, or NTP.
  • The router ID of routing protocols like OSPF and EIGRP.
  • The source address of BGP sessions between loopbacks.
  • An IP address that you “borrow” for other interfaces with IP unnumbered.
  • In labs, a quick way to create networks that you can advertise or route to.

Let me explain the idea with an example. Imagine a router with two physical interfaces, each with an IP address. Which address do you use to manage the router? If you pick the address of one physical interface and that interface goes down, you can’t reach the router on that address anymore, even though the router itself is fine and reachable through its other interface.

When you configure a loopback interface and make its address reachable in your network, the router stays reachable on that one address as long as at least one path to the router works.

Don’t confuse the loopback interface with the 127.0.0.1 loopback address. On a host, the 127.0.0.0/8 range is reserved for internal loopback (RFC 1122), and traffic to those addresses never leaves the host. On a Cisco router, you choose the address of a loopback interface yourself. Other devices can only reach it if it’s a routable address and they have a route to it.

In this lesson, I’ll show you how to configure loopback interfaces, how they work, and how to use the loopback address as the source of traffic.

Configuration

Here is the topology we’ll use:

R1 R2 Loopback0 Loopback1 Topology

R1 and R2 are connected with a single link. Each router will get two loopback interfaces.

I’m using two routers running Cisco IOS Software [IOSXE], Linux Software (X86_64BI_LINUX-ADVENTERPRISEK9-M), Version 17.18.2.

Configurations

Want to take a look for yourself? Here you will find the startup configuration of each device.

R1

hostname R1
!
interface Ethernet0/0
 ip address 192.168.12.1 255.255.255.0
!
end

R2

hostname R2
!
interface Ethernet0/0
 ip address 192.168.12.2 255.255.255.0
!
end

Create Loopback Interfaces

Here is what R1 looks like right now:

R1#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol
Ethernet0/0            192.168.12.1    YES TFTP   up                    up
Ethernet0/1            unassigned      YES unset  administratively down down
Ethernet0/2            unassigned      YES unset  administratively down down
Ethernet0/3            unassigned      YES unset  administratively down down

There is no loopback interface yet. You create one with the interface loopback command and a number. Let’s create two loopback interfaces and configure an IP address on each:

R1(config)#interface Loopback 0
R1(config-if)#ip address 1.1.1.1 255.255.255.255
R1(config-if)#exit
R1(config)#interface Loopback 1
R1(config-if)#ip address 11.11.11.11 255.255.255.0

That’s all there is to it. The number is only a name: you can create as many loopback interfaces as you need, and each one needs a unique IP address.

Let’s check the interfaces:

R1#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol
Ethernet0/0            192.168.12.1    YES TFTP   up                    up
Ethernet0/1            unassigned      YES unset  administratively down down
Ethernet0/2            unassigned      YES unset  administratively down down
Ethernet0/3            unassigned      YES unset  administratively down down
Loopback0              1.1.1.1         YES manual up                    up
Loopback1              11.11.11.11     YES manual up                    up

Notice that both loopback interfaces are up/up right away. I didn’t have to use the no shutdown command: a new loopback interface is enabled as soon as you create it.

Here is a closer look at one of them:

R1#show interfaces Loopback0
Loopback0 is up, line protocol is up
  Hardware is Loopback
  Internet address is 1.1.1.1/32
  MTU 1514 bytes, BW 8000000 Kbit/sec, DLY 5000 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation LOOPBACK, loopback not set
  Keepalive set (10 sec)
  Last input never, output never, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/0 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     0 packets input, 0 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     0 packets output, 0 bytes, 0 underruns
     Output 0 broadcasts (0 IP multicasts)
     0 output errors, 0 collisions, 0 interface resets
     0 unknown protocol drops
     0 output buffer failures, 0 output buffers swapped out

There is no hardware behind this interface, and the encapsulation is LOOPBACK. The output also says “loopback not set”. This has nothing to do with the loopback interface: it refers to loopback mode, a test feature of physical interfaces that sends everything they transmit back to themselves. You can find this line in the output of every interface. If you want to learn more about this output, take a look at the show interface explained lesson.

The router can reach both loopback addresses:

R1#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
R1#ping 11.11.11.11
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 11.11.11.11, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

Subnet Mask

You might have noticed that I used a different subnet mask on each loopback interface. It’s typical to configure a /32 subnet mask on a loopback interface. A loopback interface is not connected to anything, so there are no other devices that need an address in its subnet. A single address is all you need.

You can use any subnet mask you like, though. Loopback1 has a /24 subnet mask, and that works fine. Let’s look at the routing table to see the difference:

R1#show ip route connected
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
C        1.1.1.1 is directly connected, Loopback0
      11.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        11.11.11.0/24 is directly connected, Loopback1
L        11.11.11.11/32 is directly connected, Loopback1
      192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.12.0/24 is directly connected, Ethernet0/0
L        192.168.12.1/32 is directly connected, Ethernet0/0

Loopback0 has a single connected (C) entry for 1.1.1.1/32. Loopback1 looks just like the Ethernet interface: a connected entry for the 11.11.11.0/24 subnet and a local (L) entry for its own address.

The other addresses in the 11.11.11.0/24 subnet are not usable, though. There is nothing behind a loopback interface, and packets routed out of a loopback interface that are not addressed to the loopback itself are dropped. Here is an example:

R1#ping 11.11.11.12
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 11.11.11.12, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)

So a larger subnet mask doesn’t give you any extra addresses. Why use one then? In labs, a loopback with a /24 is a quick way to simulate a LAN that you can route to or advertise in a routing protocol, without adding switches and hosts.

Some routing protocols ignore the subnet mask of a loopback interface. For example, OSPF advertises a loopback interface as a /32 host route, even when you configured a /24. The OSPF network type loopback lesson explains this.

Reach the Loopback Interfaces

Let’s configure the same on R2:

R2(config)#interface Loopback 0
R2(config-if)#ip address 2.2.2.2 255.255.255.255
R2(config-if)#exit
R2(config)#interface Loopback 1
R2(config-if)#ip address 22.22.22.22 255.255.255.0
R2#show ip interface brief | include Loopback
Loopback0              2.2.2.2         YES manual up                    up
Loopback1              22.22.22.22     YES manual up                    up

Can R2 reach the loopback addresses of R1?

R2#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
R2#show ip route 1.1.1.1
% Network not in table

No, it can’t. A loopback address is just like any other network: other routers need a route to reach it. We can use a routing protocol or static routes. Let’s keep it simple and use static routes:

R1(config)#ip route 2.2.2.2 255.255.255.255 192.168.12.2
R1(config)#ip route 22.22.22.0 255.255.255.0 192.168.12.2
R2(config)#ip route 1.1.1.1 255.255.255.255 192.168.12.1
R2(config)#ip route 11.11.11.0 255.255.255.0 192.168.12.1

Each static route matches the subnet mask of the loopback interface. Here is what R2 has now:

R2#show ip route static | begin Gateway
Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
S        1.1.1.1 [1/0] via 192.168.12.1
      11.0.0.0/24 is subnetted, 1 subnets
S        11.11.11.0 [1/0] via 192.168.12.1

Let’s try those pings again:

R2#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
R2#ping 11.11.11.11
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 11.11.11.11, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

And from R1 to R2:

R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
R1#ping 22.22.22.22
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 22.22.22.22, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

All loopback addresses are reachable.

Independent of Physical Interfaces

A loopback interface doesn’t depend on any physical interface. Let’s see what happens when I shut the only physical interface of R1:

R1(config)#interface Ethernet0/0
R1(config-if)#shutdown
R1#show ip interface brief | exclude unassigned
Interface              IP-Address      OK? Method Status                Protocol
Ethernet0/0            192.168.12.1    YES TFTP   administratively down down
Loopback0              1.1.1.1         YES manual up                    up
Loopback1              11.11.11.11     YES manual up                    up

Ethernet0/0 is down, but both loopback interfaces are still up. R1 can still reach its own loopback address:

R1#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

Of course, R1 can’t reach R2 anymore, because there is no path left between them:

R1#ping 2.2.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)

Our topology has only one link, so there is no other path. In a real network, a router usually has multiple paths. Here is an example:

R1 R2 Two Subnets R1 Loopback0

R1 has two physical interfaces, each in a different subnet. R1 advertises its loopback address 1.1.1.1/32 in a routing protocol like OSPF, so R2 learns that it can reach 1.1.1.1 through both links.

Now imagine that Ethernet0/0 of R1 goes down. Address 192.168.12.1 is gone, so R2 can’t reach R1 on that address anymore. The loopback interface is still up, though. The routing protocol notices the failure and R2 now reaches 1.1.1.1 through the 192.168.21.0/24 subnet. R1 stays reachable on its loopback address. That’s why we use the loopback address to manage routers and to set up sessions between routers.

Let’s enable the interface again:

R1(config)#interface Ethernet0/0
R1(config-if)#no shutdown

Source Address

There is one more thing to consider. Reaching the loopback address is one thing, but what source address does the router use when it sends traffic itself? Let’s find out. I’ll enable a debug on R2 so we can see the ICMP packets:

R2#debug ip icmp
ICMP packet debugging is on

And I’ll send a ping from R1 to the loopback address of R2:

R1#ping 2.2.2.2 repeat 2
Type escape sequence to abort.
Sending 2, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!
Success rate is 100 percent (2/2), round-trip min/avg/max = 1/1/1 ms

Here is what R2 sees:

R2#
ICMP: echo reply sent, src 2.2.2.2, dst 192.168.12.1, topology BASE, dscp 0 topoid 0
ICMP: echo reply sent, src 2.2.2.2, dst 192.168.12.1, topology BASE, dscp 0 topoid 0

R1 used 192.168.12.1 as the source address, the IP address of its outgoing interface Ethernet0/0. That’s the default: a router uses the IP address of the outgoing interface as the source of packets that it creates. On a router with multiple interfaces, the source address depends on which interface the packet leaves.

You can change this. Let’s send the ping with the loopback interface as the source:

R1#ping 2.2.2.2 source Loopback0 repeat 2
Type escape sequence to abort.
Sending 2, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
Packet sent with a source address of 1.1.1.1
!!
Success rate is 100 percent (2/2), round-trip min/avg/max = 1/1/1 ms
R2#
ICMP: echo reply sent, src 2.2.2.2, dst 1.1.1.1, topology BASE, dscp 0 topoid 0
ICMP: echo reply sent, src 2.2.2.2, dst 1.1.1.1, topology BASE, dscp 0 topoid 0

Now the source is 1.1.1.1, and R2 replies to the loopback address. This only works because R2 has a route to 1.1.1.1.

The ping command is just an example. Services such as SSH, syslog, NTP, and SNMP also have a command to use the loopback interface as the source. Your servers then always see the same address for R1, no matter which interface the traffic leaves from.

BGP works the same way. When two routers in the same AS peer with each other’s loopback addresses, you configure update-source to make BGP use the loopback as the source of the session. You can see this in action in the internal BGP lesson.

Shut Down a Loopback Interface

The only way to bring a loopback interface down is to shut it yourself:

R1(config)#interface Loopback 1
R1(config-if)#shutdown
R1#show ip interface brief | include Loopback
Loopback0              1.1.1.1         YES manual up                    up
Loopback1              11.11.11.11     YES manual administratively down down

Use no shutdown to enable it again:

R1(config)#interface Loopback 1
R1(config-if)#no shutdown
R1#show ip interface brief | include Loopback
Loopback0              1.1.1.1         YES manual up                    up
Loopback1              11.11.11.11     YES manual up                    up

If you want to remove a loopback interface completely, use the no interface Loopback command with its number.

Loopback Interfaces in Action

You’ll find loopback interfaces in many lessons on this website. Here are a few where the loopback interface plays a key role:

Sign up for FREE to Continue Reading

Here's what you'll get:

  • Full Access to this lesson + 446 more.
  • Learn CCNA, CCNP and CCIE R&S. Explained as simple as possible.
  • Unlock Access to 425 lessons by becoming a member.
  • New Lessons Added Regularly. You'll Be the First to Know.
  • Content created by Rene Molenaar (CCIE #41726)

Takes 1 minute - No credit card needed