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 dev eth0 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?

  • 1
    IPv6 has been preferred for a long time and is how every OS has been shipped for a decade or more. This is the default and expected behavior. Making IPv4 preferred requires explicit configuration. If you really need to make this misconfiguration, edit /etc/gai.conf. Jul 26 '18 at 13:31
  • 1
    The proper way to deal with this is to use RFC 6555 and not change any preferences. I found this page daniel.haxx.se/docs/curl-vs-wget.html saying that curl already supports that. So assuming that page is correct, there is no need to change anything, curl already does the right thing.
    – kasperd
    Jul 29 '18 at 16:44

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.

  • /etc/resolv.conf nor /etc/gai.conf have been altered. I would like to know if this change is caused by the kernel upgrade OR ifconfi.co, which i usually use to check the IP, has changed the way it operates. Please see revised question.
    – Gaia
    Jul 26 '18 at 5:24
  • IPv6 has always been preferred if available. That's the way the migration is designed: use IPv6 when possible so we move away from IPv4. If you want to force IPv4 usage then using the -4 option is the correct solution. Jul 26 '18 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.