How to disable ubuntu 14.04 ipv6

Posted November 21, 2014 25.5k views


I want to disable ipv6 on my ubuntu 14.04 system.
I have tried to put the end of /etc/sysctl.conf file

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

these three lines and reboot but it can’t take ip address anymore.

How to disable ipv6 from my system?

  • I use Drupal SMTP module to send mails through Gmail. I noticed that it didn’t work with IPv6 enabled instances. The error message said that Drupal can’t connect Google SMTP (connection timeout). And here is what I discovered:

    The way of disabling IPv6 through /etc/sysctl.conf is a really bad idea.
    It crashed my system and I had to use restore kernel to rollback those changes.

    Thanks to @kamaln7 for his recommendation. Uncommenting the following line in the /etc/gai.conf has helped to make the mail system work:
    “` precedence ::ffff:0:0/96 100

    This is the best crutch by this time.
  • I have a WordPress site using Gmail SMTP plugin to send emails.
    Only this solution has solved my problem with slow emails.

    Just uncommenting the line in the file /etc/gai.conf has made the trick for me:

    precedence ::ffff:0:0/96 100

    Thanks @kamaln7 for this answer.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

Why do you want to disable the future?

  • <?php
    echo fsockopen(‘tls://’, 465, $n, $s) ? 'connected’ : $s;

    This gave me connection timeout. I tried

    telnet 465

    and it stuck with ipv6 address (2a03:b0c0:2:d0::18d:f001). I tried

    telnet 465

    and it works.

  • You can configure Ubuntu to prefer IPv4 over IPv6. This way you will be able to send emails and access IPv6-only sites. Edit /etc/gai.conf and uncomment (delete the ’#’) the following line:

    precedence ::ffff:0:0/96 100
    • This does not work for me. I deleted the ’#’ from:

      precedence ::ffff:0:0/96 100

      but the problem still persists.

  • Thanks! it is working now.

  • I’m not entirely sure why a staff member is recommending a workaround instead of solving the actual issue. Why does DigitalOcean allow port 465 over IPv4 but not IPv6?

  • @Woet: SMTP over IPv6 is currently blocked because each droplet is assigned 16 IPv6 IPs. Almost all mail providers blacklist the entire /64 subnet if there’s spam going out from even one IP address, so there’s a relatively high chance that if one user is spamming, another user’s droplet will be blacklisted along with the spammer’s droplet. There isn’t much we can do other than block SMTP until we start handing /64 subnets for each droplet.

I actually finished solving the exact same issue right now with a bit of help from a support person.

First of all let me say this, the support (so far) has been AMAZING and need I say FAST.

Once the support person indicated to me that IPV6 was causing the issue, I immediately searched Google and found this lovely thread. If this thread didn’t exist, I’d probably still have an opened ticket, but instead, @kamaln7 ’s post worked flawlessly.

Thanks once again @kamaln7 for helping the community out. I owe you one.

I was also using the MailGun API to send emails and IPv6 was the reason, it was giving the Gateway Timeout Error.

Error resolved when enabled precedence in /etc/gai.conf:

precedence ::ffff:0:0/96 100