ipv4 and ipv6 loopback address

What are the IPv4 and IPv6 loopback addresses?


Loopback addresses for IPv4 and IPv6
Loopback addresses for IPv4 and IPv6

Loopback is the process in which a sent request comes back to the initiator. In the computer network, each node has an address over a network, known as an IP address.

An IP address is similar to a postal address where each mail needs to have the address for the destination to get it delivered. If you send a post to your address, it will come back to your home. Means your home address is the loopback address for you.

A message/packet over the network needs to have the destination IP address to reach another node. A loopback address is a special IP address that is configured in the operating system with no hardware associated with it.

If a network client program sends a packet to the loopback address, the operating system routes the packet back to the userspace.

What is IPv4 and IPv6 address?

The IPv4 and IPv6 are the versions of the network addresses.  IPv4 is the older version, it provides four bytes long address space for the IP address. You can have a maximum of 0xFFFFFFFF number of values.  At the start of the internet, the number looks plenty.  But this range will not be sufficient as the number of devices increasing day by day, mainly after the Internet Of Things (IoT) came into the picture.

IPv6 is a newer version for a much larger user space. It is 16 bytes long, so a total of 2^128 are possible addresses with the IPv6 address scheme.

What are the loopback addresses for IPv4 and IPv6?

An operating system has a loopback interface named “lo”. This is a software interface that does not have any associated network hardware. The loopback addresses are mapped to the “lo” interface.

  • For IPv4 the loopback address is 127.0.0.1 the domain name is localhost.
  • For IPv6 the loopback address is ::1 and the domain name is localhost6.

How to check loopback address and associated domian names?

In an operating system, there are commands and utilities you can find what is the address. In this tutorial, we are using Linux operating system to demonstrate the example. There is a command (ifconfig) in Linux, you can use along with the option “-a”, to display the interfaces. From there you can see a “lo” interface.

#ifconfig -a
 
 lo: flags=73  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         inet6 ::1  prefixlen 128  scopeid 0x10
         loop  txqueuelen 1000  (Local Loopback)
         RX packets 101  bytes 7844 (7.6 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 101  bytes 7844 (7.6 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Check associated domain names.

#vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

How to check if loop back addresses are working?

We can use the ping command to check if loopback addresses are active. For IPV4 Linux have ping and for IPv6 it has ping6 commands. The following example shows how we can check the status of addresses.

#ping 127.0.0.1
 PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.056 ms
 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.065 ms
 ^C
 --- 127.0.0.1 ping statistics ---
 2 packets transmitted, 2 received, 0% packet loss, time 1000ms
 rtt min/avg/max/mdev = 0.056/0.060/0.065/0.009 ms

#ping6 ::1
 PING ::1(::1) 56 data bytes
 64 bytes from ::1: icmp_seq=1 ttl=64 time=0.075 ms
 64 bytes from ::1: icmp_seq=2 ttl=64 time=0.077 ms
 64 bytes from ::1: icmp_seq=3 ttl=64 time=0.075 ms
 ^C
 --- ::1 ping statistics ---
 3 packets transmitted, 3 received, 0% packet loss, time 2000ms
 rtt min/avg/max/mdev = 0.075/0.075/0.077/0.010 ms

The ping is getting a reply, which means loop bac addresses 127.0.0.1 and::11 are active. Any application can bind on these addresses and many send/receive data.

What are the Advatages of loop back addresses?

  • Can check network module in the operating system without having network interface card.
  • Network processes can communicate to each other over operating system without any special hardware.
  • We can test network application with a single box.
  • Not exposed to the external network, so these are safe.