How to disable IPv6 on Ubuntu?

vi /etc/sysctl.conf

and add these lines to sysctl.conf file

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

Then run commadn:
sysctl -p