Cyberithub

How to Disable IPV6 on Linux(CentOS / RHEL 7/8) Using 4 Best Steps

In this article, I will take you through the Steps to Disable IPV6 on Linux (CentOS / RHEL 7/8) Using 4 Best Steps. You might have seen some program which requires IPV6 to be disabled in your System or else it will fail and will unable to execute. In those situations you need to manually disable IPV6 modules. While in most of the Linux/Unix Systems you will find IPV6 enabled by default so you might need to disable it. Here we will go through different steps that needs to be taken to disable IPV6 protocol in Linux/Unix Based Systems.

How to Disable IPV6 on Linux(CentOS / RHEL 7/8) Using 4 Best Steps 1

How to Disable IPV6 on Linux(CentOS / RHEL 7/8)

Also Read: How to Enable IPV6 on Linux(RHEL/CentOS) Using 4 Easy Steps

Step 1: Verify IPV6 is Disabled or not using ifconfig command

First you need to check and verify if IPV6 is disabled in your System. There are many ways through which you can verify that but here we will look into the most simplest way i.e by checking network interface details using ifconfig eth0 command as shown below. From the below output you can see inet6 address which verifies that IPV6 is currently enabled in this System.

[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.33.220  netmask 255.255.240.0  broadcast 172.31.47.255
        inet6 fe80::423:b3ff:fed6:e976  prefixlen 64  scopeid 0x20<link>
        ether 06:23:b3:d6:e9:76  txqueuelen 1000  (Ethernet)
        RX packets 924  bytes 113913 (111.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2029  bytes 206011 (201.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

Step 2: Disable IPV6 from /etc/sysctl.conf file

If you want to disable IPV6 from /etc/sysctl.conf file then you need to set net.ipv6.conf.all.disable_ipv6 and net.ipv6.conf.default.disable_ipv6 to 1 as shown below. If you do not find these parameters in /etc/sysctl.conf file then you need to manually add those parameters at the end of the file with the value mentioned below. Then Save and exit the File.

[root@localhost ~]# vi /etc/sysctl.conf
........................................................................
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

Now you need to run sysctl -p to reflect the changes done on /etc/sysctl.conf file as shown below.

[root@localhost ~]# sysctl -p
fs.inotify.max_user_watches = 524288
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
kernel.core_pattern = /cores/cores-%e-%s-%t-%p.core
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

After updating the changes now if you check again IPV6 got disabled or not using same ifconfig eth0 command which we used above then you can find that inet6 address is not visible now. This confirms that IPV6 is disabled in the System.

[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet 172.31.33.220 netmask 255.255.240.0 broadcast 172.31.47.255
ether 06:23:b3:d6:e9:76 txqueuelen 1000 (Ethernet)
RX packets 1536 bytes 164873 (161.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2715 bytes 269086 (262.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Step 3: Disable IPV6 from GRUB(/etc/default/grub)

If you want to disable IPV6 from GRUB then you need to edit /etc/default/grub file and put ipv6.disable=1 in GRUB_CMDLINE_LINUX Line as shown below.

[root@localhost ~]# vi /etc/default/grub
GRUB_TIMEOUT=1
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=115200"
GRUB_CMDLINE_LINUX="ipv6.disable=1 console=tty0 crashkernel=auto console=ttyS0,115200"
GRUB_DISABLE_RECOVERY="true"

After editing the /etc/default/grub file you need to regenerate the grub configuration again by using grub2-mkconfig -o /boot/grub2/grub.cfg command as shown below.

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1062.12.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.12.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.1.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.1.3.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-05cb8c7b39fe0f70e3ce97e5beab809d
Found initrd image: /boot/initramfs-0-rescue-05cb8c7b39fe0f70e3ce97e5beab809d.img
done

Once configuration file is regenerated you need to reboot the system using reboot or init 6 command to take the new configuration.

[root@localhost ~]# reboot

Step 4: Disable IPV6 through sysctl command

If you want to disable IPV6 protocol for any specific interface then you need to use below sysctl commands to set net.ipv6.conf.eth0.disable_ipv6 and net.ipv6.conf.default.disable_ipv6 to 1. In this example, we are trying to disable IPV6 setting of eth0 interface.

[root@localhost ~]# sysctl net.ipv6.conf.eth0.disable_ipv6=1
net.ipv6.conf.eth0.disable_ipv6 = 1
[root@localhost ~]# sysctl net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6 = 1

If you want to disable IPV6 protocol for all the interfaces then you need to use below sysctl commands to set the value of net.ipv6.conf.all.disable_ipv6 and net.ipv6.conf.default.disable_ipv6 to 1.

[root@localhost ~]# sysctl net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6 = 1
[root@localhost ~]# sysctl net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6 = 1

 

 

 

Popular Recommendations:-

How to Limit CPU Limit of a Process Using CPULimit in Linux (RHEL/CentOS 7/8)

How to Install Rust Programming Language in Linux Using 6 Best Steps

How to Install LEMP Stack on CentOS 8

Openssl Tutorial: Generate and Install Certificate on Apache Server in 8 Easy Steps

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)

25+ Popular Examples of Openssl commands in Linux (RedHat/CentOS 7/8)

12 Most Popular rm command in Linux with Examples

Create a Self Signed Certificate using OpenSSL

Top 12 Nmap Commands to Scan Remote Host with Best Practices

1 thought on “How to Disable IPV6 on Linux(CentOS / RHEL 7/8) Using 4 Best Steps”

Leave a Comment