Disable in current session:
$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
The above IPv6 disable settings would not persist after the reboot. The usual way on how to load the above settings is to edit the /etc/sysctl.conf configuration file by adding the following lines:
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
WARNING: Please note, that at the time of writing this method to disable IPv6 after reboot using /etc/sysctl.conf configuration file on Ubuntu 18.04 does Not work. However, this seems to be a bug so feel free to try.
The recommend method to disable IPv6 on Ubuntu 18.04 after reboot is to configure the GRUB boot loader to pass kernel parameter during the boot time.
To do so open the /etc/default/grub using your favorite text editor with root privileges and change/add:
FROM:
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""
TO:
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"
update-grub
Reboot the system to disable IPv6 support.