Sub topic 9
Loopback and unspecified addresses
This chapter assumes you know how IPv6 addresses are written and compressed, and that you can read a prefix length such as /128. Two addresses are reserved for special jobs: ::1, which a host uses to talk to itself, and ::, which means "no address yet" or "any address".
The loopback address ::1
The loopback address is 0:0:0:0:0:0:0:1, written ::1. It is a single address with a /128 prefix. IPv4 differs here: it reserves the whole block 127.0.0.0/8 for loopback, and IPv6 reserves one address.
Traffic sent to ::1 never leaves the host. The operating system hands it to a virtual loopback interface, usually named lo, and delivers it back to a local program. Two rules follow from this:
- A router must never forward a packet whose source or destination is
::1. ::1cannot identify another machine, so every host has its own::1.
Pinging ::1 therefore tests only the local IPv6 software stack. It does not test your network card, cable, or router.
The unspecified address ::
The unspecified address is 0:0:0:0:0:0:0:0, written ::, with a /128 prefix. It means "no address". It has three uses:
- Source address before configuration. A host that has not yet been assigned an address can use
::as the source of a packet. - Duplicate address detection. Before a host uses a new address, it asks the local link whether anyone else holds it. That request comes from
::, because the host does not yet own the address it is testing. The next chapters on Neighbor Discovery cover this. - "Any address" when listening. A server that binds to
::accepts connections on every IPv6 address of the host.
You must not assign :: to an interface, and it must never be a destination. Do not confuse it with ::/0, the default route, which matches every address.
Checking both addresses in code
The ipaddress module has a property for each special address.
import ipaddress
for text in ["::1", "::", "0:0:0:0:0:0:0:1"]:
a = ipaddress.ip_address(text)
print(text, a.compressed, a.is_loopback, a.is_unspecified)
# ::1 ::1 True False
# :: :: False True
# 0:0:0:0:0:0:0:1 ::1 True FalseThe third line shows that the expanded form and ::1 are the same address.
Binding a socket shows the two roles of these addresses. This code needs IPv6 enabled on the host, and the port numbers it prints will vary.
import socket
for host in ["::1", "::"]:
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
s.bind((host, 0)) # port 0 lets the OS pick a free port
print(host, s.getsockname()[:2])A service bound to ::1 is reachable only from the same machine. A service bound to :: is reachable on every address the host has, so check your firewall before you use it.
Exercise
A colleague runs ping -6 ::1 and gets replies, but cannot reach a neighbor's IPv6 address. What does the successful ping show, and what does it not show?
Show answer
It shows that the local IPv6 stack and the loopback interface work. It does not test the network interface, cabling, or routing, because packets to ::1 never leave the host. The fault is somewhere between the host and the neighbor.