How to disable IPv6 on RHEL5, CentOS5 and RHEL6, CentOS6

Since there seems to be some confusion how to disable IPv6 on RHEL and CentOS, here is how to do it.

How not to do it

Do not disable the IPv6 kernel module. The reason is that IPv6 is quite integrated into the kernel in spite of being a kernel module. Things like SELinux need the IPv6 kernel module to be loaded. If you disable the IPv6 kernel module expect strange AVCs and generally things falling apart.

On up-to-date RHEL5 or CentOS5 (currently that means 5.10 aka 5U10)

Add the following line to /etc/sysctl.conf:

On a live system you can disable it with:

On up-to-date RHEL6 or CentOS6 (currently that means 6.4 aka 6U4)

Add the following lines to /etc/sysctl.conf:

On a live system you can disable it with:

In case of any sshd problems on RHEL6, CentOS6 edit /etc/ssh/sshd_config and change ‘#AddressFamily any’ to ‘AddressFamily inet’ *or* uncomment ‘#ListenAddress 0.0.0.0’.