How to disable IPv6 on Linux

Disabling IPv6 temporarily

Run the following command to disable IPv6 temporarily. This will be reset after a reboot.:

disable_ipv6.sh
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1

Re-enable IPv6

To re-enable IPv6, run the following command:

enable_ipv6.sh
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0

Disabling IPv6 permanently

To disable IPv6 permanently, you need to modify the sysctl configuration file. Open the file /etc/sysctl.conf with your preferred text editor (e.g., nano, vim):

edit_sysctl.conf.sh
sudo nano /etc/sysctl.conf

Add the following lines at the end of the file:

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

Check out similar posts by category: Linux