how to disable ipv6 on redhat-based systems

if grep NETWORKING_IPV6 /etc/sysconfig/network >/dev/null
then
    ed -s /etc/sysconfig/network <<-EOM
    /NETWORKING_IPV6/s/=.*/=no/
    w
    q
EOM
else
    echo NETWORKING_IPV6=no >> /etc/sysconfig/network
fi

if grep net-pf-10 /etc/modprobe.conf >/dev/null
then
    ed -s /etc/modprobe.conf <<-EOM
    /net-pf-10/s/net-pf-10.*/net-pf-10 off/
    w
    q
EOM
else
    echo alias net-pf-10 off >>/etc/modprobe.conf
fi

if grep ipv6 /etc/modprobe.conf >/dev/null
then
    ed -s /etc/modprobe.conf <<-EOM
    /ipv6/s/ipv6.*/ipv6 off/
    w
    q
EOM
else
    echo alias ipv6 off >>/etc/modprobe.conf
fi

chkconfig ip6tables off
service ip6tables stop

updated: 2011-11-30