Config Server Firewall

How to Disable IPv6 in Ubuntu Server 18.04/16.4 LTS

IPv6 is enabled by default in Ubuntu. But you may want to disable IPv6 for many reasons. Some programs may cause problems when IPv6 is enabled, So if you are not planning to use IPv6, simply disable it and not worry about any potential problems.

This tutorial explains how to disable IPv6 in Ubuntu 18.04/16.04 (compatible with both Ubuntu server and Desktop version). There are a couple of ways we can disable IPv6 on Ubuntu server. One method is to turn off IPv6 using sysctl, the second method is to edit the grub config file. We will look at both methods.

Permanently Disable IPv6 on Ubuntu 18.04/16.04 with sysctl

Easiest and safest method is to add configurations to the /etc/sysctl.conf file. To disable IPv6 using sysctl, Open the Ubuntu terminal and Perform the following steps:

Open the /etc/sysctl.conf file:

vim /etc/sysctl.conf

Add the following lines at the end of the sysctl.conf file:

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

In Ubuntu server 18.04, you will need to add additional lines for each interface you want to disable IPv6:

net.ipv6.conf.<ifname>.disable_ipv6 = 1

For example, if the interface name is enp0s3, Then:

net.ipv6.conf.enp0s3.disable_ipv6 = 1

For change to be effected, run the sysctl -p command.

sysctl -p

Then, run the following command to check the IPv6 status:

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

If the output is 1 then IPv6 is disabled, the command will output 0 when IPv6 is enabled.

If you want to re enable IPv6 addresses, remove the above configuration from the sysctl.conf and execute the sysctl -p command.

How it Works..

When system reboot, the kernel creates the /proc filesystem which handle the kernel parameters. By editing sysctl.conf we can edit the kernel parameters in /proc filesystem.

By adding the following lines to the sysctl.conf, we disabled the ipv6 in the /proc filesystem.

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

Disable IPv6 using GRUB

Perform the following steps with root privileges to disable IPv6 in Ubuntu 18.04/16.04 Permanently using grub method.

  1. Open the /etc/default/grub, Modify GRUB_CMDLINE_LINUX and  GRUB_CMDLINE_LINUX_DEFAULT to append ipv6.disable=1:

    GRUB_CMDLINE_LINUX="ipv6.disable=1"
    GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"
  2. Update the grub configuration:

    update-grub
  3. Reboot the server:

    systemctl reboot

What is IPv6 and The Need for IPv6 Addresses

IPV4 been around for awhile, since the beginning of the internet. IPv4 uses 32 bit address space which can Provide almost 4.3b IP Addresses. But, by 1992 it was realized IPV4 address scheme not going to be enough for fast growing internet.

So the main reason we are moving to IPV6 is because we are running out of IP addresses. IPV6 use 128 bit address space written in hexadecimal. IPv6 has larger address space and can provide 340 undecillion addresses.

Why Disable IPv6?

There is no single reason why you should disable IPv6 in your Ubuntu server, nor it must. It depends on your requirement.

It has been reported for a while  that IPv6 in Ubuntu cause DNS related problems. For example, the apt package manager occasionally tries to initiate the connection over IPv6 and fails.

Other than that, some softwares may require you to disable IPv6 as part of their configuration setup.