Someone may argue that there is no reason to disable ipv6 on Linux. For me, the reason is that in some ipv6-enabled website, I frequently be classified as a bot who need to solve captcha which is really annoying :-( . Consider the ipv6 address is never change (assigned by service provider), disable ipv6 is the simplest solution.

Let's come to the solution. Just use your favorite editor to add one line in /etc/sysctl.conf:

net.ipv6.conf.<your.device.name>.disable_ipv6=1
where <your.device.name> maybe eth0, lo or the device name shown by ifconfig. Then you can use sysctl -p to take effect immediately or reboot to test if ipv6 has been persistently disabled.

The above solution is tested on Ubuntu 20.04 LTS.

Notes:

• net.ipv6.conf.all.disable_ipv6 = 1 is unnecessary.
• net.ipv6.conf.default.disable_ipv6 = 1 doesn't work on my server (maybe default is not well defined?).
• Personally I don't like the update-grub solution as we cannot re-enable ipv6 without reboot.