Internet protocol version 6 (IPv6) is released long time ago, But still most of organisation are using ipv4 only.In CentOS8, By default ipv6 is enabled in CentOS8, which is show in various command output, like below. In this post we will wee how we can disable Ipv6.

[root@srv16 ~]# pifconfig ens2
ens2
        HWaddr 52:54:00:68:74:49
        inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
**      inet6 addr: fdec:aea1:e763:0:5054:ff:fe68:7449/64 Scope: global
**      inet6 addr: 2a02:c7f:c61f:5300:5054:ff:fe68:7449/64 Scope: global
**      inet6 addr: fe80::5054:ff:fe68:7449/64 Scope: link
        UP BROADCAST RUNNING MULTICAST

SetUp

This machine is CentOS8 updated as of now June 2020.

[root@srv16 ~]# uname -r
4.18.0-193.6.3.el8_2.x86_64
[root@srv16 ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core) 

How to Disable IPv6

On CentOS8 ipv6 is enabled by-default but most of time organisation only using ipv4. We can disable ipv6 through mainly two ways

  • Disable kernel module
  • via sysctl settings

Disable ipv6 built-in-kernel module

TO disable ipv6 on CenTOS8 or RHEL8, we need to edit /etc/default/grub and append GRUB_CMDLINE_LINUX with ipv6.disable=1 like below. This method will need reboot

GRUB_CMDLINE_LINUX="crashkernel=auto ... ipv6.disable=1"

After changing any kernel parameter we rebuild grub.cfg through grub2-mkconfig

[root@srv16 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
[ 7181.952730] fuse init (API version 7.27)
done

If you have UEFI systems, run below command

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

Further reboot Machine will disable ipv6 on all interface. As it need reboot, so i don’t suggest to use this method, instead we have another way which don’t need reboot.

Disable through sysctl settings

We can also disable through sysctl settings, which will apply without reboot. For this we need to edit /etc/sysctl.conf and append some lines to it.

# Disable ipv6 on all interfaces
net.ipv6.conf.all.disable_ipv6 = 1

# Disable ipv6 on specific interface only
net.ipv6.conf.ens2.disable_ipv6 = 1

To apply these settings, we need to run sysctl -p.

[root@srv16 ~]# sysctl -p
net.ipv6.conf.ens2.disable_ipv6 = 1

We can also check it like below command

[root@srv16 ~]# pifconfig ens2
ens2
        HWaddr 52:54:00:68:74:49
        inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
        UP BROADCAST RUNNING MULTICAST

Above two methods are persistent across reboots and will not change after reboot. But we have another way which is not persistent, I just like explore this idea just to understand Linux better, how CentOS8/RHEL8 distribute files in /proc file-system.

[root@srv16 ~]# pifconfig ens2
ens2
        HWaddr 52:54:00:68:74:49
        inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
        inet6 addr: 2a02:c7f:c61f:5300:5054:ff:fe68:7449/64 Scope: global
        inet6 addr: fdec:aea1:e763:0:5054:ff:fe68:7449/64 Scope: global
        inet6 addr: fe80::5054:ff:fe68:7449/64 Scope: link
        UP BROADCAST RUNNING MULTICAST

[root@srv16 ~]# echo 1 > /proc/sys/net/ipv6/conf/ens2/disable_ipv6
[root@srv16 ~]# pifconfig ens2
ens2
        HWaddr 52:54:00:68:74:49
        inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
        UP BROADCAST RUNNING MULTICAST