I've been tasked with writing a document on IPv6 for my colleagues to learn how to configure IPv6 addresses on our hosts. We primarily use RHEL6.x/7.x, ESXi, and Ubuntu Server. This only pertains to RHEL/Ubuntu.

The Argument: How should you display the IPv6 Address in /etc/hosts.

I've seen it displayed as:

2001:4860:4860::1:8888 google.com
# Gateway:IPv6 Address <hostname_here>


Write it the same way IPv4 would be written.


The hosts file format consists of lines, each of which contains the IP address, followed by whitespace, then one or more hostnames, also separated by whitespace.

Nothing changes when the address is an IPv6 address instead of a legacy IPv4 address. The format is the same.

For example:

2001:db8:1::1 example.com www.example.com
2001:db8:2::1 mail.example.com

See also the hosts(5) man page.

  • Hey Michael, I totally get this. My work uses a highly customized RHEL6.x / 7.x Image. I've been running across hosts with the IPv6 address stated in both ways above. I've never messed with IPv6 on Windows or Linux, so this is a bit new to me. I guess it would be correct to assume that; gateway_ip:last_hextet of the IPv6 address goes here (2001:db8:2::1:1000). This is what threw me off, I've never seen it this way.
    – BinaryData
    Apr 12 '18 at 14:12
  • @BinaryData If you've seen something in some other format, then it's wrong and probably has no effect (or an undesirable effect). Apr 12 '18 at 16:40

IPv6 addresses have their own formatting system because they represent an 128-bit addressing space: that's 16 octets, which would be extremely unwieldly! As well, at this time there are a lot of runs of embedded zeroes, so it's handy to be able to compress those out. To indicate that octets aren't being used, a colon is used instead of a period; as well, hexadecimal digits are used instead of decimal.

An IPv6 address looks like the following:


netmask works the same as IPv4, except that it can go up to 128.

The %int is required for scoped addresses, which are not global addresses and only have meaning inside a local network, and specifies which network interface owns the address as two interfaces may have the same address.

Leading zeroes are allowed to be omitted, and a single run of zeroes in an address (the longest one, by convention) can be compressed by using :::

Leading zeroes removed: 2001:db8:1523:0:1334:0:0:193
Longest run of zeroes compressed: 2001:db8:1523:0:1334::193

There are some special cases:

  • Any address that starts completely with zeroes can be compressed to ::, then the non-zero portion (0:0:0:0:0:0:0:0/128 becomes ::/128 and 0:0:0:0:0:0:0:1/128 becomes ::1/128).

  • IPv4-compatible and IPv4-mapped IPv6 addresses look like ::a.b.c.d/96 and ::ffff:a.b.c.d/96 (or ::ffff:aabb:ccdd/96).

For your /etc/hosts usage, almost nothing changes between IPv4 and IPv6 addresses: you won't have to worry about the network mask, and almost certainly won't have to worry about scoped addresses or IPv4-compatible addresses. Just follow the zero-compression rules and you should usually be fine. If you have a dual-homed address (where a host listens to both IPv4 and IPv6), you will have to enter it twice, once for the IPv4 address and once for the IPv6 address:

::1 localhost localhost
2001:db8:123:456::78 example.com www.example.com example.com www.example.com
fe80::12:34:56:78%eth0 printer.example.com

I won't discuss network masks and ranges, but if you want a reference to the standard ranges, RIPE produced a PDF with them if you would like a quick overview of them.

  • Strictly speaking, the 2001:db8:123:456::78/64 notation combines two things: the address and the associated 2001:db8:123:456::/64 routing prefix. This notation is used, for example, when an address is added to an interface. The /64 part is not part of the address, and you can not include it when just an address is required, like in a /etc/hosts record. In the case of a remote address the routing prefix doesn't even make sense. Apr 11 '18 at 16:26
  • ErikF, I totally get this, however I was referring more towards why the host file on several hosts were; default_ipv6_gateway:Last_hextet_of_IPv6_Address. I haven't seen this before, and I've configured thousands of hosts. I'm writing a doc using our tools at my work to show others how to handle IPv6, I'm trying to cover everything I can, and have it be accurate info. I wrote it as; IP<space>FQDN. That brings up another question; do I have to list the default_gateway. The man pages don't give it as an example. I wish I could post my works configuration, that'd make things so much easier.
    – BinaryData
    Apr 12 '18 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.