How do I configure a network interface for IPv6?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 6
  • IPv6

Issue

  • How do I configure a network interface for IPv6?
  • How do I configure IPv6 IP addressing?
  • How do I do basic IPv6 setup?

Resolution

  • You can configure an IPv6 interface with the /etc/sysconfig/network-scripts/ifcfg-* files just like IPv4 addresses.

  • The following parameter is needed when configuring IPv6:

IPV6INIT=yes

Address

You can add an IPv6 address with:

IPV6ADDR=<IPv6 address>[/<prefix length>]

For example:
IPV6ADDR=fe80::2/64
  • The prefix is optional.

Gateway

You can add the IPv6 gateway with:

IPV6_DEFAULTGW=<IPv6 address[%interface]>

For example:
IPV6_DEFAULTGW=fe80::1/64

Or if you want to specify the gateway interfaces as well, you can add it:

IPV6_DEFAULTGW=fe80::1/64%eth0

DNS

You add a DNS server like normal:

DNS{1,2}=<ip address>

For example:
DNS1=fe80::1/64

Further reading

These options are described in /usr/share/doc/initscripts-*/sysconfig.txt, you can search for "IPV6" to see the relevant options.

Note

We can not set the link local address of IPv6 manually.

Diagnostic Steps

  • Example of ipv6 working with ipv4 in Red Hat Enterprise Linux 7 with NetworkManager.
[root@XXXXX network-scripts]# cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=XXXXX
DEVICE=eth0
ONBOOT=yes
DNS1=127.0.0.1
DOMAIN=XXXXX
IPV6ADDR=XXXXX
IPV6_DEFAULTGW=XXXXX
ZONE=
IPADDR=XXXXX
PREFIX=24
GATEWAY=XXXXX
IPV6_PRIVACY=no

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

6 Comments

You need at least this in ifcfg-* for ipv6 config to happen:
IPV6INIT=yes

For networks which uses Router Advertisements to set the IPv6 router/gateway RHEL presents a challenge if you want to configure a static IPv6 address and not having the autoconfigured IPv6 address available.

The IPV6_AUTOCONF config variable controls whether any Router Advertisements should be received, as a side effect this also disables the autoconfigured IPv6 address as the autoconfig process is based on the advertised network prefix.

IMHO, IPV6_AUTOCONF should really control the autoconf sysctl interface attribute instead of the current accept_ra attribute, and a properly named knob should be introduced to control the accept_ra attribute.

As a workaround, we added the following script as ifup-pre-local (which is run by the ifup script) to disable the autoconf attribute when a network device is configured (script revised to cater for virtual devices like bond0 etc):

#!/bin/bash

# Disable interface autoconf.
# Can't use IPV6_AUTOCONF=no since it disables router advertisements
# completely.

cd /etc/sysconfig/network-scripts
. ./network-functions

CONFIG=$1
[ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIG
source_config

REALDEVICE=${DEVICE%%:*}
DEVICE=$REALDEVICE

if [ "$DEVICE" = lo ]; then
        exit 0
fi

# Trigger loading of modules needed for virtual devices like bond0 etc.
is_available $DEVICE

modprobe ipv6
sysctl -q -w net/ipv6/conf/$DEVICE/autoconf=0

exit 0

This issue seems to still crop up (CentOS 7.6). It appears the cloudinit 18.2-1 is turning off autoconf via IPV6_AUTOCONF=no in it's sysconfig settings and breaking IPv6 RA.

Whether or not this particular configuration is a bug, cloud-init is triggering it by disabling AUTOCONF. I reported it to CentOS, https://bugs.centos.org/view.php?id=15833

Looks like IPV6_DEFAULTGW does not work in CIDR notation.

There is no documented option in this above case to autoconfigure DNS.

Is the solution applicable to Red Hat Enterprise Linux 8?