How to Disable IPv6 in RHEL, Rocky & AlmaLinux

Brief: This guide explores how to disable IPv6 on RHEL, Rocky Linux, and AlmaLinux distributions.

In computing, there are two types of IP addressing; IPv4 and IPv6.

IPv4 is a 32-bit address that contains 4 octets segmented by three periods. It is the most widely used IP addressing scheme and supports up to 232 IP addresses. There is a good chance that your device is using IPv4 addressing to connect to any network – wired or wireless.

On the other hand, IPv6 is a 128-bit address with 16 octets. It’s a lot longer than IPv4 and provides 2128 IP addresses. This amounts to 340 undecillion IP addresses, while IPv4 is limited to 4.3 billion IP addresses.

In most cases, IPv4 and IPv6 work hand in hand without any problem. However, there are times you might need to temporarily disable IPv6 addressing, for example, when troubleshooting network faults.

In this guide, we will demonstrate how to disable IPv6 on RHEL, Rocky, and AlmaLinux distributions.

Permanently Disable IPv6 on RHEL, Rocky & AlmaLinux

In this section, we will walk you through how to permanently disable IPv6. Before anything else, confirm that your Linux system is using IPv6 using the following ip command as follows:

$ ip a | grep inet6

From the output below, you can see that IPv6 is enabled. The next step is to disable IPv6.

Check IPv6 Support in Linux
Check IPv6 Support in Linux

We are going to disable IPv6 by making changes to the grub configuration file.

So, access the GRUB settings file as shown.

$ sudo vim /etc/default/grub

Add the line below at the very end.

Disable IPv6 in Grub Configuration
Disable IPv6 in Grub Configuration

Save the changes and exit.

For the change to be applied, we need to generate a new GRUB configuration file. To do so, run the command:

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Generate GRUB Configuration
Generate GRUB Configuration

In addition, generate an EFI GRUB configuration file for EFI systems as shown.

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

Thereafter, reboot your system

$ sudo reboot

and, once again, check if IPv6 is supported.

$ ip a | grep inet6

If you get no output that means IPv6 is now disabled.

Temporarily Disable IPv6 on RHEL, Rocky & AlmaLinux

The other option is to disable IPv6 temporarily, which can be achieved by editing the /etc/sysctl.conf file or adding a configuration file in the /etc/sysctl.d directory.

You can make changes to the /etc/sysctl.conf file using the following command:

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

Then verify that IPv6 is disabled.

$ ip a | grep inet6

Alternatively, you can manually edit the /etc/sysctl.conf file.

$ sudo vim /etc/sysctl.conf

Append the following lines to disable IPv6 for all network adapters.

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

Save the changes and exit. Then run the following command to apply the changes.

$ sudo sysctl -p

Re-enabling IPv6 on RHEL, Rocky & AlmaLinux

Open /etc/default/grub file and remove the entry ipv6.disable=1 from the GRUB_CMDLINE_LINUX as shown.


Run the grub2-mkconfig command to regenerate the grub.cfg file:

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

Alternatively, on UEFI systems, run the following:

# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

Make sure to replace redhat with your distribution name rocky or almalinux.

Reboot the system to disable IPv6 support.

If you’ve temporarily enabled IPv6, just remove the following lines from /etc/sysctl.conf file and reboot the system.

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

Unless required, it is generally not recommended to disable IPv6 on your Linux system as it might lead to issues, especially when using a DHCP server that still supports IPv6.

In this tutorial, We have covered various ways in which you can disable IPv6 on RHEL, Rocky, and AlmaLinux. Your feedback on this guide is highly welcome.

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

1 Comment

Leave a Reply
  1. Hi

    Nice tutorial, tried it on my centos.

    It works, however, there are a few inconsistencies I noticed.

    -w key doesn’t necessarily write changes to /etc/sysctl.conf, in my case it didn’t.

    Then, if I append some lines to /etc/sysctl.conf through vim and reboot the system, these changes are still applied. This means, the method with manual editing configs in /etc/sysctl.conf isn’t temporary, but rather permanent change.


Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.