Ubuntu defaults to IPv6, should default to IPv4

Ubuntu 16.04.5 with kernel 4.4 used to work as intended: IPv4 is default. Since changing to kernel (hwe) 4.15, it uses IPv6 as default.

It has IPv6 available via Tunnelbroker, broadcasted by the router.

It is now defaulting to IPv6: curl ifconfig.co returns the machine's IPv6. Only curl -4 ifconfig.co returns the desired IPv4 address. (curl -6 ifconfig.co as expected returns IPv6)

$ ip rule list
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default

$ ip -6 rule list
0:      from all lookup local
32766:  from all lookup main

$ ip route list
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.x

$ ip -6 route list
2001:470:x:999::9999:f6a dev eth0  proto kernel  metric 256  pref medium
2001:470:x:999::/64 dev eth0  proto kernel  metric 256  expires 42905sec pref medium
fe80::/64 dev eth0  proto kernel  metric 256  pref medium
default via fe80::2ac6:8eff:fe65:d117 dev eth0  proto ra  metric 1024  expires 1505sec hoplimit 64 pref medium

PS: Some providers still report IPv4, for example curl ipinfo.io/ip. I've used ifconfig.co for a long time, so I am not sure if they changed their setup (less likely) or the kernel upgrade makes Ubuntu prefer IPv6.

How do I find out what is causing IPv6 to be preferred?


Set name resolving to prefer v4. For users of glibc's getaddrinfo, uncomment the precedence line after the "prefer IPv4" comment in /etc/gai.conf. The one with the IPv4 /96.