74

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?

13
  • 6
    Why do you want to disable IPv6 permanently? Jun 17, 2013 at 23:59
  • 2
    There are absolutly (well, I can actually find one, on MS Windows) no reason to turn IPv6 off. Why would you want to do that?
    – Anders
    Jun 20, 2013 at 1:00
  • 10
    Disabling IPv6 doesn't make you immune to IPv6 attacks. It is much better to have it enabled, deal with it and learn from it, that is the only way make your environment a bit safier. It is better for everybody to learn "How to to disable IPv4 permanently", instead. IPv6 is far much easier than IPv4, to begin with, there no NAT anymore, so, one less thing to manage... The Internet is growing really fast, in a few years, the IPv6 network will be bigger than IPv4, so, with IPv4, you'll be out of the real Internet. Go ahead man! Upgrade your IP!! Change is a good thing.
    – ThiagoCMC
    Feb 24, 2014 at 6:12
  • 2
    @AndersonGreen I need to do this. Bug Workaround, wireless won't connect in newer Ubuntu versions with it enabled, works fine when disabled
    – cmc
    Nov 21, 2014 at 11:18
  • 11
    @JonathanS.Fisher and others - These comments are no helpful. Just because you may not be aware of a reason to disable IPv6, doesn't mean there isn't one. One major case is for VPN services that don't support IPv6. If you don't disable it, you will leak your IPv6 address.
    – Scone
    Jan 26, 2017 at 1:44

6 Answers 6

91

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
13
  • 14
    After these adding lines to sysctl.conf, run sudo sysctl -p or reboot to let changes take effect. Mar 13, 2014 at 18:14
  • 6
    I need to do this only on wireless as a bug workaround so I can connect again. Here's how to do it for one adapter only: net.ipv6.conf.wlan0.disable_ipv6 = 1
    – cmc
    Nov 21, 2014 at 11:20
  • 2
    This does not work on Ubuntu 17.10. See NullNoname comment below for the grub fix.
    – Luke
    Jan 1, 2018 at 4:54
  • 3
    Doesn't work on Ubuntu 16.04 as well. Grub method works. Mar 26, 2018 at 21:12
  • 1
    @hellomoto That's not a command. You have to put those lines in the file /etc/sysctl.conf. May 2, 2018 at 4:56
72

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
7
  • 12
    +1 this works and disables IPv6 completely, so there are no traces of /proc/sys/net/ipv6/ left which may produce problems like X11 forwarding request failed because sshd tries to bind to a non-configured IPv6 interface. Note that similarly you can get rid of IPv4 this way on pure IPv6 VMs. Thanks.
    – Tino
    May 29, 2014 at 7:48
  • 2
    This works for me on 20.10. A cleaner way is to create a file /etc/default/grub.d/disable-ipv6.cfg with the contents GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} ipv6.disable=1". Don't forget update-grub. Feb 21, 2021 at 10:28
  • @Tino did a find a solution to the sshd problem? Feb 28, 2021 at 18:07
  • @AbhishekAnand There might be, but I tried nothing else, as disabling IPv6 at boot time fixes it for me.
    – Tino
    Mar 1, 2021 at 2:07
  • @schieferstapel on ubuntu 18.04 now my system wont boot anymore after creating your file
    – Freedo
    May 28, 2021 at 7:15
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.

3
  • 2
    Upvote for mentioning that disabling different devices is sometimes required.
    – Scone
    Jan 26, 2017 at 1:47
  • The lack of the default line is probably the problem here. If your driver wasn't loaded yet at the point in the boot process when the sysctl was executed, then it wasn't included in all -- but setting the default would have meant it would have gotten the setting later, when it was loaded. Mar 15, 2017 at 20:11
  • 2
    I had the default entry and I had to configure the specific device to successfully disable it. May 14, 2018 at 18:55
9

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.

2
  • This answer assumes that the kernels ipv6 feature is a kernel module (using blacklist.local to prevent its loading). There is a case that ipv6 is compiled into the kernel (not a module) in which case it is necessary to boot the kernel with ipv6.disable=1 boot paremeter (to do so one would: (1) sudo gedit /etc/default/grub (2) search for the line GRUB_CMDLINE_LINUX_DEFAULT=<args> and (3) add ipv6.disable=1 to the boot parameters ) May 19, 2017 at 10:32
  • @humanityANDpeace You may be interested in this more comprehensive answer: unix.stackexchange.com/a/190189
    – mchid
    May 21, 2017 at 20:29
8

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

5
  • 2
    this is the cleanest way to do it - don't understand why was downvoted. it works on fedora/centos/redhat, too. it has the advantage that it does not alter system defaults files (like directly sysctl.conf as suggested in most popular answer) Nov 9, 2017 at 9:23
  • @Costin I didn't downvote, but this won't always work. Sometimes you have to put the specific device name (e.g. in case of custom driver installations). See Alfonso Nishikawas comment on my answer. Oct 3, 2018 at 19:09
  • I'm thankful I followed this approach, because I ended up losing my connection on a remote server (it needed IPv6), and it was very easy to direct my assistant on site to remove the one file and reboot. Mar 2, 2019 at 15:32
  • 1
    i had to run service procps restart instead on ubuntu 18.04
    – iPherian
    May 28, 2019 at 2:12
  • Putting it in sysctl.d doesn't persist through reboots, in my experience. Nov 7, 2020 at 0:21
0

On a raspberry pi running Ubuntu, prepend

ipv6.disable=1

to

/boot/firmware/cmdline.txt

to disable IPv6 at the kernel level.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .