How to Add Non-Loopback IPv6 Addresses to Windows Hosts File for Name Resolution


1 views

The Windows hosts file located at %SystemRoot%\System32\drivers\etc\hosts is a plain text file that maps hostnames to IP addresses. While it commonly handles IPv4 addresses, IPv6 entries are also supported but with some important considerations.

The example shows a valid IPv6 link-local address (fe80::215:afff:fec6:ea64) that fails to resolve when added to the hosts file. This occurs because:

  • Link-local addresses require zone identifiers (like %eth0) in Windows
  • The hosts file doesn't process these identifiers automatically
  • Windows may cache DNS entries differently for IPv6

Here are two approaches that actually work:

Method 1: Using Global Unicast Addresses

2001:db8::1        server1
2001:db8::2        server2

Global unicast addresses (non-link-local) work without zone identifiers.

Method 2: Using IPv6 Loopback Aliases

::1               localhost
::1               server.local
::2               db.local

You can create multiple aliases for the loopback address.

If you must use link-local addresses, you need to:

  1. Find your interface index with netsh interface ipv6 show interface
  2. Add the zone ID to your ping command:
ping fe80::215:afff:fec6:ea64%12

However, this won't work through the hosts file directly.

After modifying the hosts file:

  • Run ipconfig /flushdns
  • Check with nslookup hostname
  • Test connectivity with ping -6 hostname

For production environments, consider:

  • Setting up a proper DNS server
  • Using mDNS (Bonjour/ZeroConf)
  • Creating a local DNS resolver service

Windows supports IPv6 entries in the %SystemRoot%\system32\drivers\etc\hosts file, but there are specific formatting requirements for non-loopback addresses:

# This works (loopback)
::1             localhost
::1             hosta

# This WON'T work (link-local)
fe80::215:afff:fec6:ea64 realhost

The issue occurs because link-local IPv6 addresses (fe80::/64) require zone identifiers in Windows. Here's why your entry fails:

ping fe80::215:afff:fec6:ea64%12  # Works with interface index
ping realhost                      # Fails - missing zone ID

Option 1: Use Global Unicast Addresses

For non-link-local addresses, the standard format works perfectly:

2001:db8:85a3::8a2e:370:7334  realhost

Option 2: Interface-Specific Entries

If you must use link-local addresses, specify multiple entries per interface:

# For Ethernet interface with index 12
fe80::215:afff:fec6:ea64%12  realhost-eth

# For WiFi interface with index 15  
fe80::215:afff:fec6:ea64%15  realhost-wifi

Check your interface indexes using:

netsh interface ipv6 show interfaces

Sample output:

Idx     Met         MTU          State                Name
---  ----------  ----------  ------------  ---------------------------
  1          75  4294967295  connected     Loopback Pseudo-Interface 1
 12          25        1500  connected     Ethernet
 15          25        1500  connected     Wi-Fi

For more robust solutions consider:

  • Setting up a local DNS server
  • Using mDNS with hostnames ending in .local
  • Configuring DHCPv6 to register hostnames

For development environments, you might find it easier to use global IPv6 addresses or the Windows NAT interface which doesn't require zone IDs.