Completely Disable IPv6 on Ubuntu

Introduction

Disabling IPv6 completely can be useful in LAN or Lab environments, or maybe you just decided to not use IPv6 for now. I will show you how to disable IPv6 using kernel boot parameters.


Disabling IPv6

Edit your /etc/default/grub configuration file with your favorite editor:

sudo vi /etc/default/grub

Your configuration should look similar to the following one:

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

Set the option ipv6.disable=1 in GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX. Both lines should then look like the following:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"

If there are already other options set you need to add new ones separated by a space:

GRUB_CMDLINE_LINUX_DEFAULT="maybe-ubiquity ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"

For our changes to take effect you have to update the GRUB bootloader:

sudo update-grub2

After the configuration files are updates without an error reboot your system:

sudo reboot now

Once your system is up again check the IP configuration. There should be no IPv6 addresses:

ip a

Quick extra note: If you are using a hypervisor like ESXi you may need to shut down your VM and boot it again for the IP changes to take effect in your GUI.


Conclusion

Using kernel boot parameters is the easiest way to disable IPv6. To enable it again remove the ipv6.disable=1 parameter and reboot your server.