CentOS System Administration

Disable IPv6 on CentOS 8

In this article, I am going to show you how to disable IPv6 on CentOS 8. So, let’s get started.

Checking for IPv6 Availability:

You can check whether IPv6 is enabled on your CentOS 8 machine with the following command:

$ ip a | grep inet6

If IPv6 is enabled, there will be some inet6 lines as shown in the screenshot below.

If the command does not print anything, then IPv6 should be disabled on all your network interfaces.

Disabling IPv6 Using Kernel Boot Option:

This is a permanent method of disabling IPv6 on CentOS 8. This method requires a system reboot in order for the configuration to take effect. This is also the best method of disabling IPv6 completely.

First, open the default GRUB configuration file /etc/default/grub with vi text editor as follows:

$ sudo vi /etc/default/grub

Now, go to the end of the file and press O to create a new line and switch to the vi INSERT mode.

Now, type in the following line.

GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX ipv6.disable=1"

Once you’re done, the configuration file should look as follows. Now, press <Esc> to switch to vi COMMAND mode. Then type in :wq! and press <Enter> to save the file.

Now, you have to update the GRUB CFG files.

You can find the path of the GRUB CFG files with the following command:

$ sudo ls -lh /etc/grub*.cfg

As you can see, the GRUB CFG file paths are /boot/grub2/grub.cfg and /boot/efi/EFI/centos/grub.cfg

Now, run the following command to generate a new GRUB configuration file and save it to /boot/grub2/grub.cfg file:

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Now, run the following command to generate a new GRUB configuration file and save it to /boot/efi/EFI/centos/grub.cfg file:

$ sudo grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

Now, reboot your CentOS 8 machine with the following command:

$ sudo reboot

As you can see, ipv6.disable=1 is appended to the kernel boot parameters. That’s great.

Now, either press <Esc> and <Enter> or press <Ctrl> + X to boot.

Once your CentOS 8 machine boots, run the following command to verify whether IPv6 is disabled.

$ ip a | grep inet6

As you can see, the command does not print anything. It means, IPv6 is disabled.

Disabling IPv6 Using sysctl:

You can also use sysctl options to disable IPv6. This method does not require a system reboot. So, if you want to disable IPv6 on the go (maybe for testing/troubleshooting), then this method may be very helpful for you. But, this method is a little bit more complicated than the kernel boot parameter method I’ve shown you earlier.

First, create a new sysctl configuration file /etc/sysctl.d/70-ipv6.conf with the following command:

$ sudo vi /etc/sysctl.d/70-ipv6.conf

Now, type in the following lines and save the file.

Before I apply the changes, I just want to show you the default values of net.ipv6.conf.all.disable_ipv6 and net.ipv6.conf.default.disable_ipv6 when IPv6 is enabled.

As you can see, the default value of net.ipv6.conf.all.disable_ipv6 is 0 when IPv6 is enabled.

$ sudo sysctl --values net.ipv6.conf.all.disable_ipv6

As you can see, the default value of net.ipv6.conf.default.disable_ipv6 is 0 when IPv6 is enabled.

$ sudo sysctl --values net.ipv6.conf.default.disable_ipv6

Now, disable IPv6 with the following command:

$ sudo sysctl --load /etc/sysctl.d/70-ipv6.conf

IPv6 should be disabled.

As you can see, the value of net.ipv6.conf.all.disable_ipv6 is 1 after IPv6 is disabled.

$ sudo sysctl --values net.ipv6.conf.all.disable_ipv6

As you can see, the value of net.ipv6.conf.default.disable_ipv6 is 1 after IPv6 is disabled.

$ sudo sysctl --values net.ipv6.conf.default.disable_ipv6

Now, run the following command to verify whether IPv6 is disabled.

$ ip a | grep inet6

As you can see, the command does not print anything. It means, IPv6 is disabled.

Now, you can reboot and the changes should persist.

$ sudo reboot

Troubleshooting sysctl IPv6 Disabling Problems:

If you’ve disabled IPv6 using the sysctl method, then one or more of your network interface may still use IPv6 once you reboot as you can see in the screenshot below.

$ ip a | grep inet6

This happens if the network interface is managed by Network Manager. This is the case for CentOS 8. CentOS 8 uses Network Manager by default.

As you can see, IPv6 is disabled for all the network interface but only one, the network interface ens160.

$ sudo sysctl --all | grep disable_ipv6

ens160 is managed by network manager. You can verify that with the following command:

$ sudo nmcli

As you can see, Network Manager configured an IPv6 address to the network interface ens160.

To disable IPv6 on the network interface ens160 from Network Manager, run the following nmcli command:

$ sudo nmcli connection modify ens160 ipv6.method ignore

Now, reboot your CentOS 8 machine for the changes to take effect.

$ sudo reboot

Once your CentOS 8 machine boots, you can verify whether IPv6 is disabled with the following command:

$ sudo ip a | grep inet6

As you can see, the command does not print anything. Which means IPv6 is disabled. Network Manager no longer assigns any IPv6 address to the network interface ens160.

So, that’s how you disable IPv6 on CentOS 8. Thanks for reading this article.

About the author

Shahriar Shovon

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.