How to Disable IPv4 and Only Use IPv6

Validated on 28 October 2019 • Posted on 19 June 2018

IP addresses let machines communicate across a network. DigitalOcean Droplets are assigned IPv4 addresses by default. Enabling IPv6 on a Droplet gives you access to its 16 additional IPv6 addresses.

When you enable IPv6 on a Droplet, both the IPv4 and IPv6 interfaces are available. You can disable IPv4 and rely solely on IPv6, although you will still need to have IPv4 available for the localhost so your programs operate as expected.

Note DigitalOcean blocks all SMTP traffic over IPv6. If you disable IPv4 on a Droplet that hosts a mailserver, mail delivery will stop.

Disable IPv4 on Boot

To disable IPv4, you need to modify the file that configures your network at boot. The file you edit and what you change in it depends on which distribution your Droplet is running.

Ubuntu 18.04

Debian and Ubuntu 16.04

CentOS and Fedora On Ubuntu 18.04, you need to edit /etc/netplan/50-cloud-init.yaml . If you enabled IPv6 when the Droplet was created, remove the IPv4 address and gateway4 lines. If you enabled IPv6 after creation, you need to add the IPv6 address and gateway6 lines. In both cases, add the IPv6 nameservers as well. When you're done, the file should look like this: network: version: 2 ethernets: eth0: addresses: - public_ipv6_address/64 - anchor_ip gateway6: public_ipv6_gateway match: macaddress: droplet_mac_address nameservers: addresses: - 2001:4860:4860::8844 - 2001:4860:4860::8888 search: [] set-name: eth0 On Debian 9 and Ubuntu 16.04, you need to edit /etc/network/interfaces.d/50-cloud-init.cfg . On Ubuntu 14.04, you need to edit /etc/network/interfaces . If you enable IPv6 when you created your Droplet, you'll see two sections beginning with iface eth0 , and maybe more if you also enabled private networking. In this case, you should delete or comment out the inet section for eth0 so that only the inet6 section is defined for eth0 . If you enabled IPv6 after creation, you won't see the iface eth0 inet6 static section. In this case, you should delete or comment out the inet section for eth0 and add in the inet6 section as below. When you're done, the file should look like this: iface eth0 inet6 static address public_ipv6_address netmask 64 gateway public_ipv6_gateway autoconf 0 dns-nameservers 2001:4860:4860::8844 2001:4860:4860::8888 209.244.0.3 # iface eth0 inet static # . . . On CentOS and Fedora, you need to edit /etc/sysconfig/network . If it isn't already there, add NETWORKING_IPV6=yes on a new line to enable IPv6: NETWORKING=yes HOSTNAME=centafter NETWORKING_IPV6=yes Next, edit /etc/sysconfig/network-scripts/ifcfg-eth0 , which specifies how the network should be configured when it is brought up. Comment out the IPv4 information so that it isn't taken into account at boot by adding a # at the beginning of those lines: #IPADDR=128.199.175.162 #NETMASK=255.255.192.0 #GATEWAY=128.199.128.1 If you enabled IPv6 after the Droplet was created, you need to add your IPv6 information ( IPV6ADDR=... and IPV6_DEFAULTGW=... ) and adjust the DNS directives ( DNS1=... ) so they point to IPv6 name servers: IPV6INIT=yes IPV6ADDR=public_ipv6_address/64 IPV6_DEFAULTGW=public_ipv6_gateway IPV6_AUTOCONF=no . . . DNS1=2001:4860:4860::8844 DNS2=2001:4860:4860::8888 DNS3=209.244.0.3

These steps will disable IPv4 at next boot. You can also disable IPv4 immediately.

Disable IPv4 Immediately

To disable IPv4 immediately, you need to delete the rule that configures your IPv4 address.

If you enabled IPv6 after you created your Droplet, you first need to edit the /etc/resolv.conf file to use IPv6 DNS servers. Set the nameserver directives to Google's IPv6 name servers by changing the file to look like this:

nameserver 2001:4860:4860::8844 nameserver 2001:4860:4860::8888 nameserver 209.244.0.3

After the Droplet is set to use IPv6 name servers, find its IPv4 address and CIDR routing prefix.

ip -4 addr show eth0

This is the information after inet , which is 198.51.100.0/24 in this example:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 198.51.100.0/24 brd 128.199.191.255 scope global eth0

Warning If you are connecting to the Droplet through an IPv4 connection, disabling the IPv4 interface will drop your connection. You will need to reconnect using IPv6 (if your local configuration supports it) or log in using the control panel

To disable IPv4 immediately, remove the rule configuring your IPv4 address, using the Droplet's IP address and CIDR routing prefix:

ip addr del 128.199.175.162/18 dev eth0

Unless you disable IPv4 on boot, these changes will be reverted the next time you reboot.