How to Disable IPv6 on CentOS 7

Overview

IPv6 is a 64-bit address space that exponential increases the network address. It was introduced when it was clear the explosive growth of the Internet couldn’t be sustained on IPv4’s 32-bit address space.

Not all networks run IPv6, even though it has been available for a few decades, and sometimes leaving it enabled can cause issues.

This tutorial will show you how to disable and enable IPv6 on CentOS 7 servers.

Disable IPv6

Disabling the IPv6 stack can be done using the the following kernel parameter. However, this isn’t recommended as this could cause issues with packages that expect the IPv6 stack.

Disable IPv6 stack on all network interfaces.

sysctl -w net.ipv6.conf.all.disable_ipv6=1

Disable IPv6 by default on all network interfaces.

sysctl -w net.ipv6.conf.default.disable_ipv6=1

Enable IPv6

To re-enable the IPv6 stack, the same kernel parameters are used with the value set to 0.

Enable IPv6 stack on all network interfaces.

sysctl -w net.ipv6.conf.all.disable_ipv6=0

Enable IPv6 stack by default on all network interfaces.

sysctl -w net.ipv6.conf.default.disable_ipv6=0

Disable IPv6 Address Assignment

Rather than completely disabling IPv6 all together, the IPv6 stack can be enabled, but prevented from assigning network addresses to network interfaces.

This is the recommended approach, as you are likely to have fewer issues. Some application expect the IPv6 stack to be enabled, and if the stack is not then errors could encountered.

To keep IPv6 stack enabled on all network interfaces, but to disable address assignment, set the following kernel parameter.

systctl -w net.ipv6.conf.all.disable_ipv6=1

To disable IPv6 address assignment by default on all network interfaces, set the following kernel parameter.

sysctl -w net.ipv6.conf.default.disable_ipv6=1

Enable IPv6 Address Assignments

To re-enable IPv6 address assignments on the network interfaces, we set the disable_ipv6 values to 0.

sysctl -w net.ipv6.conf.all.disable_ipv6=0

To enable IPv6 address assignment by default on all network interfaces, set the following kernel parameter.

systectl -w net.ipv6.conf.default.disable_ipv6=0

Disable IPv6 on Specific Network Interfaces

If you need to be more granular about which network interfaces IPv6 is enabled or disabled on, you can specify it in the net.ipv6.conf configuration. For example, to disable IPv6 on network interface nic0 you would use the following configuration.

sysctl -w net.ipv6.conf.nic0.disable_ipv6=1

And to enable IPv6 on the same interface, set the disable_ipv6 value to 0.

sysctl -w net.ipv6.conf.nic0.disable_ipv6=0