What are the IPv4 and IPv6 loopback addresses?
Loopback refers to the process by which a request sent to a destination returns back to the initiator. Each operating system has a special IP address known as a loopback address.
If you send a post to your home address, it will return to your home. Therefore, your home address is the loopback address for you.
A message over the network having 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 network card 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, where each address value is four bytes long. You can have a maximum of 0xFFFFFFFF number of values. At the start of the internet, the number looks pretty good to hold the IP addresses of all devices worldwide.
As the number of devices is increasing every day, mainly following the introduction of the Internet of Things(IoT). It is anticipated that IoT will bring millions of devices over the Internet within a short period of time, resulting in the overflow of the four-byte IP address space very soon.
IPv6 is a newer version with a much broader IP address space. Each address 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?
Each operating system has a loopback interface named “lo”. This is a software-only 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 the loopback address and associated domain names?
An operating system has commands and utilities to list the IP addresses. In this tutorial, we use the Linux operating system to demonstrate the examples. There is a command (ifconfig
) in Linux, which you can use along with the option “-a” to list all interfaces. In the output, 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 loopback addresses are working?
We can use the ping command to check if loopback addresses are active. For IPV4, Linux has 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 Advantages of loopback addresses?
- Check network modules in the operating system without a physical network interface card.
- Network applications can communicate with each other over an operating system without any special hardware.
- We can test network applications with a single box.
- They are not exposed to the external network, so they are safe.