How to Disable IPv6 on CentOS?

In this article we’ll learn how to disable IPv6 on CentOS.

How to check if I have IPv6 enabled or not?

To check if you have IPv6 enabled or not, execute the following command:

ip -6 addr

If you have IPv6 enabled, it will output something like in the picture below.

IPv6 Enabled Output
IPv6 enabled output

whereas if the IPv6 disabled, there will be no output upon executing the command.

No Output When IPv6 Disabled 1
No output when IPv6 disabled

How do I temporarily disable IPv6 on CentOS?

To disable IPv6 temporarily in CentOS execute the following commands:

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

or if you wish to disable for a particular network device replace deviceName with the name of the device and execute:

sudo sysctl -w net.ipv6.conf.deviceName.disable_ipv6=1

But in this method, it will revert upon rebooting.

How do I permanently disable IPv6 on CentOS?

There are two permanent ways to disable IPv6 in CentOS:

1. using ‘sysctl’

Add the following lines to /etc/sysctl.conf using your favorite text editor.

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

or if you wish to disable for a particular network device replace deviceName with the name of the device, and add it to /etc/sysctl.conf

net.ipv6.conf.deviceName.disable_ipv6=1

and execute the following command for the changes to take effect.

sudo sysctl -p

To make sure that your SSH doesn’t break, make following change in /etc/ssh/sshd_config

#AddressFamily any

to

AddressFamily inet
Changes Made In Sshd Config
Changes made in /etc/ssh/sshd_config

Then restart the SSH service by:

systemctl restart sshd

2. With grub

The other method is through grub by editing /etc/default/grub and adding ipv6.disable=1 in GRUB_CMDLINE_LINUX and then save it.

Add In Grub Config
Add in /etc/default/grub

Then execute the following command to apply changes in grub for BIOS:

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

or to apply changes for UEFI execute:

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

Then reboot your machine.

sudo reboot

This should disable IPv6 on your machine, verify it with ip -6 addr

Conclusion

It is very easy to disable IPv6 in CentOS just follow the procedure exactly as mentioned above.

Thank you for reading! 😀