How to disable IPv6 on a VPS server without removing the interface
Often you want to completely disable IPv6, but without removing the interface eth0/ens3/enp1s0 and without breaking cloud providers (Hetzner, Vultr, DigitalOcean, Linode, etc.).
The most reliable and clean method (recommended)
- Disable IPv6 on all interfaces via sysctl
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
- Make the changes permanent
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
In some distributions it is also better to add:
echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
- Apply immediately (without reboot)
sudo sysctl -p
Alternative method — via GRUB (if sysctl did not work)
sudo nano /etc/default/grub
Add/change the line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet ipv6.disable=1"
# or
GRUB_CMDLINE_LINUX="ipv6.disable=1"
Then:
sudo update-grub
sudo reboot
Verification
ip -6 addr # there should be no global IPv6 addresses
ping6 google.com # should be "Network is unreachable"
sysctl net.ipv6.conf.all.disable_ipv6 # should return 1
When the sysctl method doesn’t help (very rare)
Add to /etc/sysctl.d/99-disable-ipv6.conf:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
And reboot.
Good luck!