13

I have the following block in my /etc/hosts:

# The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts 

They were inserted by some automagic in Ubuntu and not written by me. I've found lots of documents that say that you should have these lines. But why? Why are they desirable?

My suspicion is that they aren't and are just cruft (except for the first one). Because if you google one of the names, eg ip6-allrouters, all you find are references to /etc/hosts but no one is actually using them.

Another way of phrasing this question is, what harm will come unto me or what feature will not function properly if I remove these lines? If the answer is none, can we conclude that they are redundant?

4
  • 1
    I'm pretty sure someone in Debian just made up those names. They don't appear in any official documents and no other distributions, not derived from Debian, have them. If something does break from removing them, it's most likely a bug. Commented Mar 8, 2017 at 2:27
  • Cool! Let's try and find a source for that. If it is true, then that is proof that they are redundant. Commented Mar 8, 2017 at 16:55
  • How do you prove something doesn't exist? Commented Mar 8, 2017 at 19:41
  • 1
    Perhaps we can find the commit which added the names and ask whoever committed it why he or she did it? Commented Mar 9, 2017 at 19:47

3 Answers 3

15

According to RFC 4291, Section 2.7: Multicast Addresses, the first 8 bits (FF in FF0X) at the beginning of identifies the address as a muticast address.


The flags, the next 4 bits, (the first 0 in FF0X) in the question indicate:

... a permanently-assigned ("well-known") multicast address, assigned by the Internet Assigned Numbers Authority (IANA).


The next 4 bits, (the last hex value 0 or 2 in FF00 or FF02) define the scope:

 0 reserved [...] 2 Link-Local scope [...] 

The reserved scope is reserved for future use.

The Link-local scope means, that packets within that scope will never be routed and therefore cannot leave the subnet.


So the addesses mean he following:

  • ::1: This is the loopback address, whose IPv4-equivalent is 127.0.0.1.
  • fe00::0: Can be compared to the Class E address space in IPv4, therefore it's in the reserved scope; reserved for future use.
  • ff02::1: The group of all IPv6 nodes (including the routers) in the Link-local scope, whose IPv4-equivalent is 224.0.0.1.
  • ff02::2: The group of all IPv6 routers in the Link-local scope, whose IPv4-equivalent is 224.0.0.2.
  • ff02::3: This exists no longer an is unassigned at the moment. Earlier it stood for the group of all hosts (excluding the routers) in the Link-local scope.

Further reading / References:

6

I think their purpose is so you can more easily i.e. ping all routers or all hosts etc without having to remember the multicast addresses. I haven't seen them being used anywhere else either.

1

To answer the question as asked, which is about the lines in /etc/hosts rather than about the use of the IP address ranges (which is not altered by adding or deleting things from /etc/hosts):

The point of these lines is to handle the address→name lookups of those addresses, and show these names to humans in output.

What is doing the address→name lookups

Every time that a tool like netstat -r or ifconfig or arp (or various others, varying by operating system and networking toolset) runs it performs reverse lookups on the IP addresses assigned to network interfaces, routing table entries, and ARP table entries; in order to display names instead of numbers to humans. Some of these tools are smart about loopback, link-local, unique-local, and site-local IP addresses; and will not try to display domain names for them, as they do (absent the tools's various -n options being employed) for other IP addresses (both versions 4 and 6).

Some are not.

A non-smart tool, with no -n option, ends up calling the C library's old gethostbyaddr() function or more modern getnameinfo() function with these IP addresses. In turn (but with a notable exception), according to the C library's NSS configuration, this ends up as either a files lookup in /etc/hosts or a dns lookup in the Domain Name System, or both. (Or more besides. If there's a systemd source in the NSS switch, the lookup ends up going through a Desktop Bus broker process and a systemd-resolved process and thence back to the Domain Name System, mDNS, LLMNR, et al.)

What the public DNS has

The public Domain Name System does not contain address→name mappings for these IP addresses.

The ip6.arpa. content DNS servers run by ICANN and the IAB simply respond "no such domain" for 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa. (the domain name that is actually looked up when something tries to use the DNS to map the IP address ff02::1 to a name) and its ilk. Usually this results in NSS falling back to its next lookup method, listed after dns (or systemd-resolved trying something else).

Just saying no to doing these lookups

It is to varying extent problematic that these lookups are even made at all.

  • It is a leak to the outside world of local operations.
  • Although individually tiny, the cumulative load on the ip6.arpa. content DNS servers from all of the systems in the world leaking these address→name lookups for these IP addresses is significant.
  • Because of the way that the Domain Name System works, there is also a significant global load on IAB's+ICANN's arpa. content DNS servers and the . content DNS servers.
  • Going to mDNS, LLMNR, DNS, et al. for this is pointless, as the resultant names given to humans are — ironically — well-known, invariant, and common to many systems.

Four major coping strategies have been around for decades:

  1. The notable exception, mentioned above, is the BSDs. getnameinfo() in at least FreeBSD and NetBSD (and their derivatives) simply short-circuits address→name lookups for IP (4 and 6) link-local and multicast addresses, entirely. They do not even get as far as the NSS switch in the C library, let alone out to any DNS server. (localhost is short-circuited in the name→address direction, for comparison.)
  2. Since just past the start of the 21st century, Felix von Leitner has provided modifications to Daniel J. Bernstein's dnscache program from djbdns, to make it internally synthesize answers for these address→name mapping queries. Any DNS lookup that goes through such a dnscache will never hit the outside world and never load any ICANN/IAB server. The Bernstein original was already synthesizing a name→address result for 127.0.0.1.

    (Other DNS server softwares synthesize answers to special domain names to greater or, mostly, lesser extent, too. There was an RFC on this in 2013, encouraging such synthesis after djbdns pioneered it. Sadly, it was in the usual state for DNS RFCs: half-baked. It completely omitted any consideration of ip6.arpa. and forgot about 127.in-addr.arpa. even though it discussed 10.in-addr.arpa. et al..)

  3. For about the same length of time I have been providing instructions on the bare minimum for split-horizon DNS service; including splitting out the special domain names used for such IPv4 and IPv6 domain name mappings of loopback and local IP addresses.

Indeed, there is so much routine use of non-public IP addresses, both version 4 and 6, nowadays that everyone should employ one of these. If one is not using one of those BSDs, then one should definitely deploy a minimal split-horizon DNS service to prevent all of this non-public stuff leaking off one's LAN. It is a less heavyweight mechanism than having a PiHole or stuffing different firmware on a router are, and people have no qualms about those.

  1. As a sledgehammer-to-walnut measure, several operating systems have this stuff pre-loaded into /etc/hosts as you have observed.
    1. Not everyone agrees on these de facto names. The BSDs do not have them, obviously. But it's not just Debian Linux and its derivatives that has/had them. SuSE Linux had them at one point, too.
    2. The names seem to originate in Debian with the netbase package from the days when it was being maintained by Andrew Towns. Some, but not all, of them were taken out in mid-2013 (although that change wouldn't have crawled through the process to a stable Debian by the time of the question).
    3. In fairness, this stuff is from January 1999 according to the old netbase package changelog, and pre-dates djbdns by 11 months. ☺ And the removal of some of the names post-dated Felix von Leitner's work (using the same Debian names) by over a decade.

If you go and read RFC 882 from 1983, you will see that Paul Mockapetris's original idea was to obviate a HOSTS.TXT file that everyone had to have a copy of, with common universal names in. And yet it is 2025 and here we are. ☺

jdebp@debian %tail -n 4 /etc/hosts # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters jdebp@debian % 

Further reading

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.