How to Disable IPv6 on Redhat / CentOS 6 / CentOS 7

This howto will show you how to disable ipv6 on RHEL 6/7, CentOS 6 and CentOS7.

IPv6 is enabled by default. In this article I summarize 3 configuration which needs to be changed to completely disable ipv6.

Check the configuration of the existing network with the “ifconfig” command. If inet6 appears in the configuration, means IPv6 is enabled.

Disable IPv6 on Redhat

Here are details on how to disable IPv6 on Redhat / CentOS 6 / CentOS 7 :

1. Update /etc/sysctl.conf :

Method 1 :

# vi /etc/sysctl.conf

Add the following :

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

Run the following command to take effect.

# sysctl -p

Disable IPv6 on Redhat

Method 2 :

To disable ipv6 in the running system :

# echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
# echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6

or

# sysctl -w net.ipv6.conf.all.disable_ipv6=1
# sysctl -w net.ipv6.conf.default.disable_ipv6=1

2. Update config file in/etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/sysconfig/network-scripts/ifcfg-ens160 :

For CentOS 6 :

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:C5:36:7C
TYPE=Ethernet
UUID=f9db89e6-013a-4403-8893-ae0536c6306f
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.0.9
NETMASK=255.255.255.0
IPV6INIT=no

For CentOS 7 :

# vi /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE="Ethernet"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="no"
IPV6_AUTOCONF="no"
IPV6_DEFROUTE="no"
IPV6_FAILURE_FATAL="yes"
NAME="ens32"
UUID="ccfd7425-20ab-40c9-a141-b71828a1b8bf"
DEVICE="ens160"
ONBOOT="yes"
IPADDR="192.168.0.100"
PREFIX="24"
GATEWAY="192.168.0.1"
DNS1="8.8.8.8"
DOMAIN="ehowstuff.local"
IPV6_PEERDNS="no"
IPV6_PEERROUTES="no"
IPV6_PRIVACY="no"

Disable IPv6 on Redhat

3. Edit /etc/sysconfig/network file and add “no” to NETWORKING_IPV6.

# vi /etc/sysconfig/network
NETWORKING_IPV6=no

Disable IPv6 on Redhat

I would advise you to restart network configuration as below :

For CentOS 6 :

# service network restart

For CentOS 7 :

# systemctl restart network

Source : https://wiki.centos.org/FAQ/CentOS6

How To Disable The IPv6 on CentOS 5.8

By default, IPv6 has been set to enabled on linux CentOS 5.8 minimum installation. If you plan to disable this feature, you can follow these steps to completely disable it. This can avoid accidentally loaded IPv6 module. This steps may working on other CentOS version.

1. Create disable-ipv6.conf on /etc/modprobe.d/ and add the following line :

[root@centos58 ~]# vi /etc/modprobe.d/disable-ipv6.conf

Add the following line :

install ipv6 /bin/true

Whenever the system needs to load the ipv6 kernel module, it is forced to execute the command true instead of actually loading the module.

2. Edit /etc/sysconfig/network and modify as below :

Set NETWORKING_IPV6 value to “no” :

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

3. Do not forget to disable and stop the IPv6 firewall if exist :

Disable auto start at boot :

[root@centos58 ~]# /sbin/chkconfig ip6tables off

Stop ip6tables service if running :

[root@centos58 ~]# service ip6tables stop

4. Add “net.ipv6.conf.all.disable_ipv6 = 1” into /etc/sysctl.conf

[root@centos58 ~]# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf

or

[root@centos58 ~]# vi /etc/sysctl.conf

Add the following line at the bottom of sysctl.conf file :

..
...
net.ipv4.tcp_syncookies = 1
...

5. Reboot the server is required to complete the steps above.