3

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?

Gaia
  • 1,777
  • 4
  • 32
  • 58
  • 2
    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`. – Michael Hampton 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 https://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

2 Answers2

1

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.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32
  • /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 05: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. – Sander Steffann Jul 26 '18 at 07:34
-1

To prefer IPv4 over v6, you can just uncomment or add the following line in /etc/gai.conf file:

precedence ::ffff:0:0/96 100

pdropi
  • 11
  • 2
  • Your answer is the same as the accepted answer. Consider adding a different answer, or maybe a similar answer with more detail. – Gaia Dec 23 '21 at 17:41
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://serverfault.com/help/whats-reputation) you will be able to [comment on any post](https://serverfault.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/507164) – Dave M Dec 24 '21 at 16:02