Nov 012016

Internet Protocol version 6 (IPv6)

In the course of troubleshooting a pseudo-distributed mode installation of Apache Hadoop on my Ubuntu 16.04 vm, one of the tips I stumbled across suggested disabling IPv6.

For any networking neophytes, Internet Protocol version 6, aka IPv6, is the most recent version of the Internet Protocol (IP), the system governing the assignment of addresses to networks and computers on the Internet. IPv6 was created to replace IPv4 which, why still predominantly used by most systems, is quickly running out available addresses. Unlike IPv4, which is a 32 bit addressing scheme offering 2^{32} or roughly 4.3 billion addresses, IPv6 addresses are 128 bits, meaning that there are theoretically 2^{128} or roughly 3.4 \times 10^{38} addresses.

While IPv6 provides more than enough addresses to allow the Internet to continue to grow at its breakneck pace, the two protocols, IPv6 and IPv4, aren’t interoperable, and sometimes conflicts arise when both are active on the same computer. I’m honestly unsure yet whether or not IPv6 is causing my difficulties with Hadoop, but since I am not connected to an IPv6 network, there is not any reason for me to not disable it entirely.

UPDATE 2017-02-02: For a better solution than mine below, see Dave Bevan’s comment.

The steps to follow in order to disable IPv6 in Ubuntu 16.04 are:

  1. First check to see if IPv6 is already disabled. To do so, open up the Terminal, and at the command line enter: /proc/sys/net/ipv6/conf/all/disable_ipv6. If the return value is 1, then IPv6 is already disabled, and you are done. A return value of 0 indicates IPv6 is active, and you need to continue on to Step 2.

    Disable IPv6
  2. Open the file /etc/sysctl.conf in your text editor of choice. I chose to edit the file using Bluefish, but you can use vi, gedit, emacs, etc., but because the file is only writable by the root user (it should have 644 permissions), you will need to have superuser access in order to save your changes.

    Launching Bluefish as a superuser
  3. At the end of sysctl.conf, add the following three lines:
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    net.ipv6.conf.lo.disable_ipv6 = 1


  4. Now run sudo sysctl -p to update to reconfigure the kernel parameters with the new values set in Step 3. The output of sysctl will be the parameters that have changed, so unless you made other edits to sysctl.conf, the output will simply be the lines you added above.

    sysctl -p
  5. If you run /proc/sys/net/ipv6/conf/all/disable_ipv6 now, it should now return 1 indicating that IPv6 has been disabled.

    Disable IPv6

  15 Responses to “How to Disable IPv6 in Ubuntu 16.04 Xenial Xerus”

  1. typo, it will say 1 to confirm that ipv6 is disabled in the final step (not 0)

  2. This never “sticks” for me. All of the above works but at reboot it reverts back tto IPV6. The config is there but I have to type ‘sudo sysctl -p’ again in the terminal for it to pick up the config. Any suggestions?

    • Have you tried this?

      In short, you may need to edit /usr/lib/pm-utils/power.d/laptop-mode. In the laptop_mode_ac() function, comment out the line:

      Reboot and hopefully sysctl now picks up your changes.

  3. The more formal way of doing this, which fits in with the don’t-change-a-core-system-file-otherwise-it-could-be-replaced-when-you-upgrade-packages-and-your-changes-could-be-lost methodology, and such that it continues across a reboot, is as follows:

    # create the long-life config file
    echo "net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee /etc/sysctl.d/99-my-disable-ipv6.conf

    # ask the system to use it
    sudo service procps reload

    # check the result
    cat /proc/sys/net/ipv6/conf/all/disable_ipv6

    • Thanks for sharing, Dave! I’ve linked to this comment from the body of the post as this is definitely a safer way to do it.

    • sudo service procps reload

      sysctl: permission denied on key ‘kernel.kptr_restrict’
      sysctl: permission denied on key ‘kernel.sysrq’

      Any Help

  4. Daves’ suggestion doesn’t work. Did he leave out something important like is this a file or does it belong in a file… Three tries at it and i finally figures out that all that stuff went on one line. Maybe using a line indicator other than the # would be better.

    • All i get is no such file or directory.

      • Hi Gary.

        You need to copy/paste the three blocks into a terminal window. You can either do it all at once, or one section at a time.

        When you paste the 1st section it will ask for your password.


  5. Came accross this because internal machine tried to contact ubuntu repo servers via ipv6 when using apt.
    Used Dave Bevan’s suggestion and it worked out of the box.
    No reboot was needed. Simply put the lines above into one script file and run the file.

    After this ifconfig did not show any ipv6 address on the interface anymore. Apt worked now using solely ipv4.


  6. Hii Buddy 🙂 You’re article is awesome. But this method is not working with Ubuntu 17.04. I found this article useful and works well with ubuntu 17.04 How to Disable IPv6 on Ubuntu 17.04

  7. This really helped me thanks for the “How To Guide”

  8. Hi, Thx for the post it’s very useful!
    There is just a typo on the line : “At the end of sysctl.conf, at the following three lines:” (I believe it should be “add” instead of “at”) 🙂

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">