How to Disable IPv4 and Only Use IPv6

When you enable IPv6 on a Droplet, both the IPv4 and IPv6 interfaces will be available. You can choose to 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.

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 Linux distribution your Droplet is running.

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

Debian and Ubuntu

Open /etc/network/interfaces with root privileges.

sudo nano /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
#    . . .

Save and close the file.

CentOS and Fedora

Open /etc/sysconfig/network with root privileges.

sudo nano /etc/sysconfig/network

If it is not already there, add the line that tells the server to enable IPv6.

NETWORKING=yes
HOSTNAME=centafter
NETWORKING_IPV6=yes

Next, you’ll need to modify the /etc/sysconfig/network-scripts/ifcfg-eth0 file. This specifies how the network should be configured when it is brought up.

sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0

Comment out the IPv4 information so that it isn’t taken into account at boot.

#IPADDR=128.199.175.162
#NETMASK=255.255.192.0
#GATEWAY=128.199.128.1

Next, if you enabled IPv6 after the Droplet was already created, you’ll need to add your IPv6 information and adjust the DNS directives so they mainly point to IPv6 name servers.

Add the following lines or confirm that they are set correctly.

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

Save and close the file.

Disable IPv4 Immediately

To disable IPv4 immediately, you can delete the rule that configures your IPv4 address. If you enabled IPv6 after you created your Droplet, you’ll also need to edit the /etc/resolv.conf file to use IPv6 DNS servers.

If you enabled IPv6 after you created your Droplet, first open /etc/resolf.conf with root privileges.

sudo nano /etc/resolv.conf

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

Save and close the file when you are finished.

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

ip -4 addr show eth0
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

You want the information after inet, which in the example above is 198.51.100.0/24.

If you are connecting to your 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.

You can then remove that from your active network connections by typing this.

Remove the rule configuring your IPv4 address. Substitute in your Droplet’s IP address and CIDR routing prefix.

ip addr del 128.199.175.162/18 dev eth0

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