How to disable Ipv6 on Ubuntu, Linux Mint, Debian

By | May 15, 2023

Ipv6

Ipv6 is the next version of the addressing scheme Ipv4 that is currently being used to assign numerical address to domain names like google.com over the internet.

Ipv6 allows for more addresses than what Ipv4 supports. However it is not yet widely supported and its adoption is still in progress.

Check if your system supports ipv6 ?

Check out http://testmyipv6.com/ to see if you network supports Ipv6.

For Ipv6 to work you need -

1. An OS that supports IPv6. Ubuntu and most modern Linuxes do that.
2. Your network hardware (router/modem) must support Ipv6. Many of the good brands do.
3. Your ISP must also support IPv6. This is something that is not present everywhere !

Check the output of ifconfig command to see the "inet6 addr" line.

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1c:c0:f8:79:ee  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:c0ff:fef8:79ee/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
.....

Problems if ipv6 not supported

So if ipv6 is not supported on your network infrastructure, it might be useful to disable it all together. It can cause issues like delayed domain lookups, un-necessary attempts to connect to ipv6 addresses causing delay in network connection etc.

I did come across some problems like that. The apt-get command occasionally tries to connect to ipv6 addresses and fails and then retries an ipv4 address. Take a look at this output

$ sudo apt-get update
Ign http://archive.canonical.com trusty InRelease
Ign http://archive.canonical.com raring InRelease                                                                                                    
Err http://archive.canonical.com trusty Release.gpg                                                                                                  
  Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1360:8c01::1b). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::1b 80]
Err http://archive.canonical.com raring Release.gpg                                                                                                  
  Cannot initiate the connection to archive.canonical.com:80 (2001:67c:1360:8c01::1b). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8c01::1b 80]

.....

Errors like those have been more frequent in the recent Ubuntu versions, probably because they try to use Ipv6 more than before.

I noticed similar issues happen in other applications like Hexchat and also Google Chrome which would sometimes take longer than usual to lookup a domain name.

So the best solution is to disable Ipv6 entirely to get rid of those things. It takes only a small configuration and can help you solve many network issues on your system. Users have even reported an increase in internet speed.

Method 1 - Disable Ipv6 from sysctl

The first method to disable Ipv6 is to edit kernel level parameters via sysctl interface.
The kernel parameters that enable ipv6 are as follows

$ sysctl net.ipv6.conf.all.disable_ipv6
net.ipv6.conf.all.disable_ipv6 = 0
$ sysctl net.ipv6.conf.default.disable_ipv6
net.ipv6.conf.default.disable_ipv6 = 0
$ sysctl net.ipv6.conf.lo.disable_ipv6
net.ipv6.conf.lo.disable_ipv6 = 0

Note that the variables control "disabling" of ipv6. So setting them to 1 would disable ipv6
Edit the file - /etc/sysctl.conf

$ sudo gedit /etc/sysctl.conf

And fill in the following lines at the end of that file

# IPv6 disabled
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Save the file and close it. Restart sysctl with

$ sudo sysctl -p

Check the output of ifconfig again and there should be no ipv6 address

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:5f:28:8b  
          inet addr:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1346 errors:0 dropped:0 overruns:0 frame:0
          TX packets:965 errors:0 dropped:0 overruns:0 carrier:0
.....

If it does not work, then try rebooting the system and check ifconfig again.

Method 2 : Disable ipv6 from GRUB

Ipv6 can also be disabled by editing the grub configuration file

$ sudo gedit /etc/default/grub

Look for the line containing "GRUB_CMDLINE_LINUX" and edit it as follows

GRUB_CMDLINE_LINUX="ipv6.disable=1"

The same can also be added to the value of the variable named "GRUB_CMDLINE_LINUX_DEFAULT" and either would work. Save the file, close it and regenerate the grub configuration

$ sudo update-grub2

Reboot. Now ipv6 should be disabled.

About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

14 Comments

How to disable Ipv6 on Ubuntu, Linux Mint, Debian
  1. Anthony Oresteen

    Thanks! Fixed my network issue. All of a sudden, Mint 18 had network issue. Most sites in Firefox would not work. When I checked, the IP was an IPV6 address, not the IPV4 I expected. Added your lines and all is good.

    Mint 18 doesn’t have gedit. The default editor is Xed. Yes, I’m a noob and I had to use Google to figure it out.

    Thanks for the explanation! Even 4 years latter it still helps.

  2. Linnux user

    Also for disabling it from linux kernel.
    Find if its installed, lsmod list the modules:

    lsmod

    Remove it with rmmode:

    rmmod ipv6

  3. Jim

    Thank you. I’m a super noob and this is the first thing I read and applied as far as linux that actually worked with no problems.

  4. Yousif

    Hi.
    On Linux Mint 17.2 or 17.3 when I try to use GRUB method I recieve error message after try to update GRUB !! I follow instructions above & change variables in configration file then “save” changes. But when I use:

    sudo update-grub
    then I recieved error message !!

    I try sudo update-grub2
    but It is not available !! Are you sure it is grub2 not grub ? I think it is just grub

    I try to invistigate this by just type in terminal:

    grub

    to see what output. Then I recieved message say “grub not installed” & command me to use:

    sudo apt-get install grub

    What is this?

    Please your kind reply.

  5. ApplePie

    It’s suffice with just net.ipv6.conf.all.disable_ipv6 = 1
    That will automatically imply net.ipv6.conf.*.disable_ipv6 = 1

  6. ak_hepcat

    Edit /etc/gai.conf and uncomment the line to prefer ipv4 over ipv6.

    Which is the correct way to deal with this.

  7. STR54

    Sorry but, how do you save the file? xD i mean i’m sorry i’m trying to learn.. I have Mint 17 cinammon

  8. Ronald Lee

    This does not work for me. $ sudo gedit /etc/default/grub. Will not recognize $ sudo. I’m running Mint 17 KDE. I was able to bring up the command to notice that I have the ipv6 running; but my ISP and the modem is not running it. How should I disable it in KDE?

Leave a Reply

Your email address will not be published. Required fields are marked *