Ubuntu defaults to IPv6, should default to IPv4
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.
Comments
-
Gaia over 1 year
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. Onlycurl -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?
-
Michael Hampton almost 6 yearsIPv6 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
. -
kasperd almost 6 yearsThe 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.
-
-
Gaia almost 6 years/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.
-
Sander Steffann almost 6 yearsIPv6 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.
-
Gaia over 2 yearsYour answer is the same as the accepted answer. Consider adding a different answer, or maybe a similar answer with more detail.
-
Dave M over 2 yearsThis does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review