Linux – IPv6 link-local address in /etc/hosts

hostsipv6linux

I have an entry like this in /etc/hosts:

fe80::XXXX:XXff:feXX:XXXX%enp0s25 test-ipv6

This is a link-local address. I've masked out my MAC address (with the 7th most significant bit flipped) for this post.

I can ping the address, but pinging test-ipv6 gives ping: test-ipv6: Name or service not known. Why doesn't it work? Is there a different way to assign an IPv6 link-local address to a hostname?

I'm using Arch Linux with kernel version 4.17.2.

EDIT: this is mostly a duplicate of IPv6 Zone ID in /etc/hosts.

Best Answer

Use Link-local Multicast Name Resolution (LLMNR) or Multicast DNS (mDNS) (implemented by systemd-resolved) on your network. With LLMNR or mDNS, the hosts on the local network respond with their own hostnames. On a modern Linux distribution, the scope id for a link-local IPv6 address is returned by the resolver and everything should work even when using link-local IPv6 addresses.

Depending on your Linux distribution, you may already have LLMNR enabled: try

ping -6 somehost

(or ping6) where somehost is the host on the same LAN you are trying to reach.

Related Question