24

I was putting the following in /etc/sysctl.conf in Ubuntu 16.04 and ipv6 was disabled.

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

In Ubuntu 18.04 I have to add the following to grub.

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"

Just wanted to have confirmation whether this is the new way in Ubuntu 18.04 to disable IPv6.

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
gagan singh
  • 343
  • 1
  • 3
  • 4

4 Answers4

17

You only need to add this to /etc/default/grub

GRUB_CMDLINE_LINUX="ipv6.disable=1"

I also did it on GRUB_CMDLINE_LINUX_DEFAULT to be safe. Modifying sysctl only partially worked, and noticed the bug show-up in netplan, I even tried dhcp6=false to no avail. Netplan seems to have too many bugs for 18.04 STABLE IMO but that's another story...half tempted to remove netplan also.

Just don't forget to update grub before rebooting!

sudo update-grub
Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
VTChevalier
  • 346
  • 2
  • 4
  • 2
    Can you clarify how this answers the question? I am confused by your answer. – Stephen Rauch Jun 13 '18 at 03:19
  • 2
    Please consider reporting the netplan bugs you found on launchpad.net! It will help the developers making it better. – Sebastian Stark Jun 13 '18 at 05:11
  • Sebastian Stark - I will try to get to it, it just does not seem to pay attention to kernel settings hence why the grub command was needed, everything else used sysctl.conf except netplan. – VTChevalier Jun 14 '18 at 19:21
16

To clarify Stephan Rauch (for 18.04 only) - If using grub method to disable ipv6, the /etc/sysctl.conf configuration changes were not needed. I ended up leaving them in, (in case netplan is fixed in future) but all that is needed is the following:

sudo vi /etc/default/grub

Modify the GRUB_CMDLINEs to look like:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"

Then execute:

sudo update-grub
sudo reboot

Enjoy ipv4.

VTChevalier
  • 346
  • 2
  • 4
  • Thanks for the info. Do we think this would be worthy of a netplan bug or is configuring things like this through `sysctl.conf` deprecated anyway? I couldn't find a relevant bug in https://bugs.launchpad.net/netplan but perhaps I missed it? – sxc731 Dec 25 '18 at 12:03
4

I think a different aproach in Ubuntu 18.04 is this one: https://pscl4rke.wordpress.com/2019/10/01/disabling-ipv6-on-ubuntu-18-04-the-netplan-version/

Just add link-local: [] within the interface you want to disable the ipv6 link local address option. Save and test the new config with: sudo netplan try and if everything was okay enforce it with: sudo netplan apply.

Take into account that you can loss your network connection to the box if you don't know well what you are doing.

  • 1
    This doesn't actually disable IPv6 on the host. It just disables it in Netplan, but the IPv6 modules are still loaded, other code still see's IPv6, etc. – Stefan Lasiewski Nov 07 '20 at 01:47
  • 1
    I needed to disable ipv6 on one interface for a storage-only LAN that only uses ipv4, while still allowing ipv6 on other interfaces. By far the easiest method, totally convenient and effective. I think I'm actually starting to like netplan! – AveryFreeman Feb 17 '21 at 10:12
  • 1
    Disabling IPv6 totally as mentioned in /etc/default/grub can give problem with some apps requesting ipv6 compatibility out-of-the-box (i.e dovecot). – dienteperro Aug 04 '21 at 05:58
  • This disable the ipv6 on interface, nice answer. To disable all ipv6, you need disable it on /etc/default/grub. – Marcelo Guedes May 16 '22 at 19:54
0

Let sed do the work :D

sudo sed -i -e 's/GRUB_CMDLINE_LINUX_DEFAULT="maybe-ubiquity"/GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 maybe-ubiquity"/' /etc/default/grub
sudo sed -i -e 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="ipv6.disable=1"/' /etc/default/grub
sudo update-grub
uav
  • 313
  • 1
  • 11