I'd like to setup a static hostname for an IPv6 address on local network. It seems, however, that /etc/hosts won't accept a zone ID - when I append a zone ID to an IPv6 address, it acts as if the host is not defined. Without the zone ID, applications are unable to connect to the host.Can I work around this somehow? Or is there some special syntax for zone IDs in /etc/hosts?
IPv6 Zone ID in /etc/hosts
ipv6
This is a limitation of GNU C Library (and possibly others). It has a plugin API which won't even convey the scope ID (or ifindex/ifname) reliably. Then there's the actual nss_files plugin which is AFAIK not ready for the syntax.I can certainly help in this area and amend the answer accordingly. First, I'm working on a more or less experimental replacement for the glibc name resolution APIs in the form of open source project netresolve. It can be used for experiments but also for everyday work if you know what you're doing. It doesn't seem to support IPv6 scope ID in /etc/hosts either but I'm adding it on my TODO list. Second, I can provide patches towards support for glibc itself. You can apply them locally or hope the project will accept them.Then there are protocols like Multicast DNS which can theoretically provide this but are not implemented in nss_mdns and are blocked by the same issue.Workaround using netresolveSo I realized I have already implemented this in netresolve but I had to fix a couple of tiny bugs to get it actually working. Thanks for bringing them to attention by making me try it.You need to build the project from git. A live ebuild for Gentoo and an Arch AUR package are provided. Dependency checking is not perfect, yet. The package provides you a netresolve command for performing name resolution queries and a wrapresolve command for running programs with libc resolution routines replaced by reimplementations based on libnetresolve. It is achieved using the LD_PRELOAD environment variable, so you can even run the whole shell by running wrapresolve bash or similar.Configuration/etc/hosts:fe80::2677:3ff:fe40:db38%wlan0 test-link-local-with-scope-idNote: You can write the link-local addresses with scope-id the standard way, i.e. appending a percent sign and then either an interface name (ifname) or an interface index (ifindex) as reported by e.g. ip link.Test using netresolve# netresolve --node testxxxresponse netresolve 0.0.1name testxxxip 1:2:3:4:5:6:7:8%eth0 any any 0 0 0 0secureTest using wrapresolve and getaddrinfoThe netresolve package also provides a tool for testing getaddrinfo() called getaddrinfo.# wrapresolve getaddrinfo test-link-local-with-scope-idquery:  nodename = test-link-local-with-scope-id  servname = (null)status = 0#0:  family = 10  addrlen = 28  address:    family = 10    port = 0    flowinfo = 0x00000000    address = 0xfe80000000000000267703fffe40db38    scope_id = 3  nodename = test-link-local-with-scope-idTest using wrapresolve and getentThis is the first test that uses a tool that is already present in your system. Otherwise it is very close to the previous test.# wrapresolve getent ahosts test-link-local-with-scope-id fe80::2677:3ff:fe40:db38 0      test-link-local-with-scope-idTest using wrapresolve and ping6# wrapresolve ping6 test-link-local-with-scope-idPING test-link-local-with-scope-id(fe80::2677:3ff:fe40:db38) 56 data bytes64 bytes from fe80::2677:3ff:fe40:db38: icmp_seq=1 ttl=64 time=0.029 ms64 bytes from fe80::2677:3ff:fe40:db38: icmp_seq=2 ttl=64 time=0.075 ms64 bytes from fe80::2677:3ff:fe40:db38: icmp_seq=3 ttl=64 time=0.072 ms64 bytes from fe80::2677:3ff:fe40:db38: icmp_seq=4 ttl=64 time=0.078 ms^CNote: You need to run ping and ping6 as root. Their job requires additional privileges and they are suid root because of that, which doesn't play well with wrapresolve.Test using wrapresolve and ssh# wrapresolve ssh test-link-local-with-scope-id# logoutYou can also test with tools like curl. This works for non-privileged users as well.Multicast DNSI have mDNS on my TODO list for netresolve, probably via both Avahi and systemd-resolved which is going to serve DNS, LLMNR and mDNS at once.Fixes for GNU C LibraryThis is on my longer term TODO list and I'm in contact with other people working on parts of it. There are more options and I'm going to fill in more information in this answer later.