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.

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.

cat <<EOT > /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

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

Then save the file and apply rules with the command:

# 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

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 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:

# dracut -f

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_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_CMDLINE_LINUX="crashkernel=auto ipv6.disable=1 rhgb quiet"

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

# 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

Alternatively, on UEFI systems, run the following:

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

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

# reboot

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

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here