Note: If your VM is in vCenter, you can disable IPV6 with the vSphere Client
This article explains how to disable IPv6 on Red Hat Enterprise Linux (RHEL) versions 7, 8, and 9, but should also work on Oracle Linux, Alma Linux, and Rocky Linux
1. Disable IPv6 Addressing
Before disabling IPv6, you need to remove any existing IPv6 addresses and gateways, and then disable the IPv6 addressing method.
For RHEL 7 and RHEL 8.0:
# nmcli connection modify <Connection Name> ipv6.addresses "" ipv6.gateway ""
# nmcli connection modify <Connection Name> ipv6.method "ignore"
For RHEL 8.1 and Later, and RHEL 9:
# nmcli connection modify <Connection Name> ipv6.addresses "" ipv6.gateway ""
# nmcli connection modify <Connection Name> ipv6.method "disabled"
To find the available connection names on your system, you can use the following command:
nmcli connection show
Here’s a one-liner command that automatically finds the active connection name and disables IPv6 for it:
nmcli connection modify $(nmcli -t -f NAME,DEVICE connection show --active | awk -F: '{print $1}') ipv6.addresses "" ipv6.gateway "" ipv6.method "disabled"
2. Comment Out IPv6 Addresses in /etc/hosts
-
Backup the
/etc/hosts
file:# cp -p /etc/hosts /etc/hosts.backup
-
Comment out any IPv6 addresses, including the
::1 localhost
address:# sed -i 's/^[[:space:]]*::/#::/' /etc/hosts
3. Disable IPv6 in the Kernel Using sysctl
-
Create a new configuration file
/etc/sysctl.d/ipv6.conf
with the following content:# Disable IPv6 for all interfaces net.ipv6.conf.all.disable_ipv6 = 1 # Disable IPv6 for the loopback interface net.ipv6.conf.lo.disable_ipv6 = 1 # Disable IPv6 for each network interface net.ipv6.conf.<interface>.disable_ipv6 = 1
Replace
<interface>
with the actual network interface name, e.g.,eth0
. -
Backup and Rebuild the
initramfs
:# cp -p /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).backup.img # dracut -f -v
-
Verify that the
ipv6.conf
file is included in theinitramfs
:# lsinitrd /boot/initramfs-$(uname -r).img | grep 'ipv6'
4. Disable IPv6 Protocol in GRUB
-
Edit
/etc/default/grub
and appendipv6.disable=1
to theGRUB_CMDLINE_LINUX
line:GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root ipv6.disable=1"
-
Update the GRUB configuration:
# grubby --update-kernel=ALL --args="ipv6.disable=1"
5. Reboot the System
Finally, reboot the system to apply all changes:
# reboot
Comments
0 comments
Article is closed for comments.