How to Disable IPv6 on Ubuntu 18.04

Overview

In this tutorial, you will learn how to disable IPv6 on Ubuntu 18.04 and understand the different kernel parameters.

Kernel Parameters

All kernel parameters are can be found under /proc/sys, which isn’t exclusive to Ubuntu. This is common to all Linux distributions. For enabling and disabling IPv6 on Ubuntu 18.04, the following parameters are used.

  • net.ipv6.conf.all.disable_ipv6
  • net.ipv6.conf.default.disable_ipv6
  • net.ipv6.conf.[network_interface].disable_ipv6

When the values of these parameters are set to 1, IPv6 will be disabled. To enable IPv6 again, the value should be set to 0.

Disabling IPv6

Setting the kernel parameter for the target interfaces can be done two ways, by explicitly setting the value in /etc/sysctl.conf or by using the sysctl command.

Modifying Sysctl.conf

Open the sysctl.conf file in a text editor, and then add the following lines.

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1

The settings will take affect when the server is rebooted. However, they can be applied immediately with the sysctl command.

sysctl -p

Using the Sysctl Command

With the sysctl command we can target the kernel parameters to set their values. To disable IPv6 on all network interfaces, use the following commands.

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

Using the sysctl -w command, the changes take affect immediately.

Enabling IPv6

Setting the kernel parameter for the target interfaces can be done two ways, by explicitly setting the value in /etc/sysctl.conf or by using the sysctl command.

Modifying Sysctl.conf

Open the sysctl.conf file in a text editor, and then add the following lines.

net.ipv6.conf.all.disable_ipv6=0
net.ipv6.conf.default.disable_ipv6=0

The settings will take affect when the server is rebooted. However, they can be applied immediately with the sysctl command.

sysctl -p

Using the Sysctl Command

With the sysctl command we can target the kernel parameters to set their values. To disable IPv6 on all network interfaces, use the following commands.

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

Using the sysctl -w command, the changes take affect immediately.