89

How can we disable IPv6 system wide via terminal commands?

I've read editing /etc/modprobe.d/aliases and replacing:

alias net-pf-10 ipv6

with:

alias net-pf-10 off
alias ipv6 off

Is this safe to apply and does it permanently disable ipv6 across reboots?

Eric Carvalho
  • 55,453

7 Answers7

115

I successfully disabled IPv6 once putting the following lines in /etc/sysctl.conf:

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

also run this command to load changes

sudo sysctl -p
abu_bua
  • 11,313
Eric Carvalho
  • 55,453
83

If your PC doesn't load /etc/sysctl.conf at boot time (which is the case for me), disabling IPv6 from grub is needed. Linux kernel has a boot option named "ipv6.disable=1" which disables IPv6 from startup.

To edit the boot options, edit "/etc/default/grub" with any text editor as root user:

sudo nano /etc/default/grub

Find the line that contain "GRUB_CMDLINE_LINUX_DEFAULT":

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Add "ipv6.disable=1" to the boot option, then save your grub file:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet splash"

Finally, update grub:

sudo update-grub
NullNoname
  • 1,531
11

If you are using a modern version (I'm on 16.04 LTS) of Ubuntu then you can use this tidy solution:

Create /etc/sysctl.d/60-ipv6-disable.conf containing the following text:

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

Run service procps start

user10550
  • 221
10

Here's how to check to see if ipv6 is enabled on your computer

test -f /proc/net/if_inet6 && echo "Running kernel is IPv6 ready"

If you see

Running kernel is IPv6 ready

it is enabled.

If you see no output, it is not.

To disable ipv6 if the other answers on this page don't work for you, blacklist ipv6 all-together. To do this, use the following command:

echo 'blacklist ipv6' | sudo tee -a '/etc/modprobe.d/blacklist.local' >/dev/null 

Also, this might help as well:

echo 'install ipv6 /bin/true' | sudo tee -a '/etc/modprobe.d/blacklist.local' >/dev/null

Reboot for the changes to take effect. To check if it's enabled after startup run this command again:

test -f /proc/net/if_inet6 && echo "Running kernel is IPv6 ready"

There should be no output.

Click here for info on how to disable IPV6 at boot.

mchid
  • 44,904
  • 8
  • 102
  • 162
10

Carvalho's answer including the comment about having to run sudo sysctl -p has helped me the most.

However, in my case at least:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.<mydevice>.disable_ipv6 = 1

and it seems the second line was necessary.

Maybe this has to do with the fact that I am using the TP-Link Archer T2U, for which I had to customly build a driver from source.

My assumption is that as a result, <mydevice> doesn't count as one of "all".

So, in a nutshell, if you have customly added a (custom) networking driver, net.ipv6.conf.all.disable_ipv6 = 1 might not be sufficient to disable IPv6 networking.

Have to admit though, that I didn't try the line net.ipv6.conf.default.disable_ipv6 = 1.

yaobin
  • 399
2

On a raspberry pi running Ubuntu, prepend

ipv6.disable=1

to

/boot/firmware/cmdline.txt

to disable IPv6 at the kernel level.

Chadi
  • 209
0

Because some services could suffer without IPv6 enabled. So I found as suitable solution - to get rid of IPv6 while I do not want to care about it right now, - to disable the INPUT and FORWARD chains via the firewall. In my case it is iptables and I used the following commands:

sudo ip6tables -P INPUT DROP
sudo ip6tables -P FORWARD DROP
sudo ip6tables-save | sudo tee /etc/iptables/rules.v6
  • Note: the ip6tables-save command requires sudo apt install iptables-persistent
pa4080
  • 30,621