We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How to disable IPv6 on Linux Systems

Learn how to – How to disable IPv6 on Linux Systems.

Do you have IPv6 enabled on your Linux server but it causes issues with some applications that don’t work well with IPv6?. In this guide, we’ll look at different ways to disable IPv6 on Linux Servers – CentOS, Debian/Ubuntu, Arch Linux e.t.c.

What is IPv6?

Internet Protocol version 6 (IPv6) is the next generation Internet Protocol address standard which in nutshell is a set of specifications from the Internet Engineering Task Force (IETF) that’s essentially an upgrade of IP version 4 (IPv4).

For some reasons, you may need to disable IPv6 on your server and stick with IPv4. Follow steps given below to get IPv6 disabled on your Linux/Unix system.

Option 1) Disable IPv6 usinggrubby

The grubby tool can be used to make persistent changes to the grub.cfg file, especially in Red Hat based systems. To disable IPv6 using grubby command line tool, run the following commands:

sudo grubby --update-kernel ALL --args ipv6.disable=1

Verify the settings after command has been executed:

$ grubby --info DEFAULT
index=0
kernel="/boot/vmlinuz-4.18.0-315.el8.x86_64"
args="ro crashkernel=auto quiet ipv6.disable=1 $tuned_params"
root="UUID=e25c8aa8-466a-495d-9358-70f0a81da587"
initrd="/boot/initramfs-4.18.0-315.el8.x86_64.img $tuned_initrd"
title="CentOS (4.18.0-315.el8.x86_64) 8"
id="9293fc4837174ce0b710ce177fa8d1fd-4.18.0-315.el8.x86_64"

Reboot the system for the change to take effect

sudo reboot

Confirm network address details in your system:

ip address show

Option 2) Disable IPv6 by modifying Kernel parameters with sysctl

It is good to note that almost all Linux Distributions enable Internet Protocol Version 6 (IPv6) by default. One method to disable it is using sysctl. You need to be aware that this may break SSH Xforwarding unless sshd_config contains AddressFamily inet.

This method works on most Distributions, I tested it on Ubuntu, Debian, Arch Linux, CentOS (6/7).

Add these line to /etc/sysctl.d/ipv6.conf to disable IPv6 on Linux.

sudo tee /etc/sysctl.d/ipv6.conf<<EOF
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
EOT

When applied, it will change the state of file /proc/sys/net/ipv6/conf/all/disable_ipv6 from 0 to 1. Check before applying the rules using cat command below.

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
0

Then save the file and apply rules with the command:

$ sudo sysctl -p /etc/sysctl.d/ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Check /proc/sys/net/ipv6/conf/all/disable_ipv6 again.

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1

The lines can be added to /etc/sysctl.conf file. Please note that files on /etc/sysctl.d/ override settings on /etc/sysctl.conf.

Note that define list all of the targeted interfaces explicitly, as disabling all.disable_ipv6 does not apply to interfaces that are already “up” when sysctl settings are applied. You should comment out the IPv6 hosts in your /etc/hosts:

$ sed -i 's/^[[:space:]]*::/#::/' /etc/hosts
$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

For CentOS 7 or RedHat systems, you can then rebuild the Initial RAM Disk Image using:

$ sudo dracut -f

Option 3) Disable IPv6 by modifying /etc/default/grub ( RedHat based distributions)

You can also disable IPv6 by editing grub configuration.  I tested this on CentOS 7 and RHEL 7. For this, you need to add the entry ipv6.disable=1 to GRUB_CMDLINE_LINUX.Then generate new grub file for boot and reboot your server.

$ cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto ipv6.disable=1 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

Note the entry ipv6.disable=1. Run the grub2-mkconfig command to regenerate the grub.cfg file:

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-6cf33e6e3d114c2d84099f344a386f6a
Found initrd image: /boot/initramfs-0-rescue-6cf33e6e3d114c2d84099f344a386f6a.img
done

Alternatively, on UEFI systems, run the following:

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

With this method, you need to reboot your server for changes to be applied.

sudo reboot

Re-enabling IPv6 is exactly the reverse of enabling it.

Cart

Your Cart is Empty

Back To Shop