How to Disable IPv4 and Use Pure IPv6 Networking in Ubuntu for Protocol Testing


3 views

When developing IPv6-compatible applications or testing network stack behavior, you often need to eliminate IPv4 entirely. Many developers need this for:

  • Protocol conformance testing
  • Dual-stack application validation
  • IPv6 transition mechanism verification
  • Network performance benchmarking

The most thorough approach is to disable IPv4 at kernel level. Add these parameters to /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=0 ipv6.disable_ipv4=1"

Then update GRUB and reboot:

sudo update-grub
sudo reboot

For temporary IPv4 disabling (per-interface), use nmcli:

nmcli connection modify eth0 ipv4.method disabled
nmcli connection up eth0

After making changes, verify with these commands:

ip -4 addr show      # Should show no IPv4 addresses
ping -4 8.8.8.8      # Should fail
ping -6 google.com   # Should succeed

If applications fail after disabling IPv4:

  • Check for hardcoded IPv4 addresses in config files
  • Verify DNS resolution works over IPv6 (use dig AAAA)
  • Test with 'curl -4' and 'curl -6' to isolate protocol issues

Some services need explicit IPv6 configuration. For Apache:

Listen [::]:80
<VirtualHost [::]:80>
    ServerName example.com
    ...
</VirtualHost>

Update your firewall rules to account for IPv6-only operation:

sudo ufw allow proto tcp from any to any port 80
sudo ufw allow proto tcp from any to any port 443

When developing IPv6-compatible applications or testing network stack behavior, you might need a pure IPv6 environment. While most modern systems support dual-stack configurations, forcing IPv6-only mode requires specific system modifications.

The simplest approach using NetworkManager:

nmcli connection modify "YourConnectionName" ipv4.method disabled
nmcli connection up "YourConnectionName"

For more granular control, disable IPv4 at kernel level:

sudo sysctl -w net.ipv4.conf.all.disable_ipv4=1
sudo sysctl -w net.ipv4.conf.default.disable_ipv4=1
sudo sysctl -w net.ipv4.ip_forward=0

Add these lines to /etc/sysctl.conf for permanent changes:

net.ipv4.conf.all.disable_ipv4 = 1
net.ipv4.conf.default.disable_ipv4 = 1
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0

Check your configuration with:

ip -6 addr show
ping6 google.com
curl --ipv6 https://ifconfig.co

If you encounter DNS resolution problems, modify /etc/resolv.conf:

nameserver 2001:4860:4860::8888  # Google IPv6 DNS
nameserver 2620:0:ccc::2         # OpenDNS IPv6

For applications still trying IPv4, use strace to debug:

strace -e network your_application

Update your firewall rules to reflect IPv6-only mode:

sudo ufw allow in proto ipv6
sudo ufw default deny incoming
sudo ufw default allow outgoing

Validate with these tools:

sudo apt install mtr-tiny
mtr -6 destination.host
sudo tcpdump -ni any ip6