May 12, 2024

How to Disable IPv6 on RHEL System

In computing, there are two types of IP addresses, IPv4 and IPv6. By default, IPv6 is enabled on RHEL 7,8 & 9 system.

However, in some situations, you may need to disable IPv6 address support for various reasons, such as application requirements or IPv6 not being needed.

IPv6 can be disabled in two methods, but this article will guide you to disable IPv6 by modifying the sysctl.conf file. It can be disabled for all network interfaces or for a specific interface based on your needs.

This method does not require a system restart, so you can use this method if you want to disable IPv6 on the fly. But you may need to follow additional steps to disable completely.

Step-1: Check if IPv6 is enabled or not

First check if your system is using IPv6 with ip command. If any 'inet6' entry is displayed in the below output, IPv6 is enabled on the devices.

ip a | grep -i inet6

    inet6 ::1/128 scope host 
    inet6 fe80::b5c2:565a:e972:e572/64 scope link noprefixroute

Step-2: Disabling IPv6 for all Interfaces

As I said at the beginning of the article, we will disable IPv6 using ‘sysctl.conf’ file. However, if you don’t want to add parameters to the sysctl.conf file, you can create a separate configuration file for this under ‘/etc/sysctl.d/ipv6.conf’. Both are the same and there is no harm either way.

Add the following two entries to disable IPv6 for all adapter. The value '1' means that IPv6 is disabled for the device.

echo "net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1" >> /etc/sysctl.conf

Step-2a: Disabling IPv6 for a Specific Interface (Optional)

Make a Note: If you want to disable IPv6 for a specific network interface, add the following entry, but replace the interface name ‘ens224’ with your own.

echo "net.ipv6.conf.ens224.disable_ipv6 = 1" >> /etc/sysctl.conf

Step-3: Reload kernel Parameters Settings

Finally, run the following command to reflect the changes.

sysctl -p

Sometimes, disabling IPv6 using the sysctl method can break SSH Xforwarding. To avoid this, make sure the /etc/ssh/sshd_config file contains the line 'AddressFamily inet'. To do so, add the line and restart the sshd service.

echo "AddressFamily inet" >> /etc/ssh/sshd_config

Restart sshd for changes to get effect.

systemctl restart sshd

Step-4: IPv6 Verification

Display the IP settings of the devices by using ip command.

ip a | grep -i inet6

If no 'inet6' entries are displayed in the above output, IPv6 is disabled on all the devices.

Step-5: Disabling IPv6 using nmcli (Troubleshooting)

Some of your interfaces may use IPv6 when you disable IPv6 using the sysctl method on a system that uses NetworkManager to manage network interfaces. Run the below command to check if any interface on your system is still using IPv6.

Make a Note: Do not disable IPv6 on ‘localhost’ as it’s important for multiple components, but if you still required then disable it.

sysctl -a | grep -i disable_ipv6
Disable IPv6 on RHEL

If yes, you can use the nmcli command to disable the IPv6 protocol. If you disable IPv6, NetworkManager automatically sets the corresponding sysctl values in the Kernel.

In my case, IPv6 is enabled on ‘ens224’ interface, but you need to replace actual interface of your own.

nmcli connection modify ens224 ipv6.method "disabled"

Restart the network connection.

nmcli con up id ens224

Hopefully when you check the ip command output again, you won’t find anything. Yes, it doesn’t print anything related to ‘inet6’, which means this system doesn’t have IPv6.

ip a | grep inet6

Final Thoughts

In this article, we covered how to disable IPv6 in RHEL 7, 8 and RHEL 9 systems using the ‘sysctl.conf’ file.

If you have any questions or feedback, feel free to comment below.

Leave a Reply

%d bloggers like this: