Disable IPv6 Centos/Debian/Ubuntu

To completely disable IPv6 on your Linux system, side note you shouldn’t but it’s your choice, you can do so simply editing the 99-sysctl.conf file at the location ‘/etc/sysctl.d/99-sysctl.conf’
 
Copy and paste the following 3 lines at the bottom of the file.

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

 
After editing the file you need to then reboot the machine or run the following command as root

sysctl -p

To verify that you have ipv6 disabled you can run

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

 
If it’s disabled the output should be ‘1’, and it will output ‘0’ if enabled

If you just want to disable IPv6 from a specific interface, while still not advisable is better than disabling it globally, you just need to chance the commands to be more specific.

net.ipv6.conf.<INTERFACE_NAME>.disable_ipv6 = 1

*Note for people running Ubuntu, it has a bug and sysctl doesn’t correctly reload on reboot so to persist the configuration you could create an rc.local script with the command bellow:
 

echo '
# Load kernel variables from /etc/sysctl.d
/etc/init.d/procps restart
exit 0
' >> /etc/rc.local
chmod +x /etc/rc.local

Sources:

https://www.configserverfirewall.com/ubuntu-linux/ubuntu-disable-ipv6/
https://www.linuxbabe.com/ubuntu/disable-ipv6-on-ubuntu
https://support.purevpn.com/how-to-disable-ipv6-linuxubuntu
https://www.admintome.com/blog/disable-ipv6-on-ubuntu-18-04/