Currently I am connected to Internet over IPv4, I am using tunnel from sixxs.net and I have got subnet and one of IPv6 assigned to my eth0 interface.
So, eth0 has IPv4 and IPv6:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:02:XX:XX:61:36 brd ff:ff:ff:ff:ff:ff
inet XXX.XXX.0.22/24 brd XXX.XXX.0.255 scope global eth0
inet6 2a01:XXXX:XXXX::1/64 scope global
valid_lft forever preferred_lft forever
When I am trying to connect to some eg. website which is IPv6 ready, it is fine, IPv6 is preferred, but If something happen and it's IPv6 is not available I would like to have fall-back to IPv4. Is that possible?
Or is possible to temporary force user IPv4 instead of IPv6 even if program does not support (eg. by -4 option)?
This should already happen, as it's (meant to be) the default behaviour of the your network.
However, in practice, there are one or two small things that can get in the way. Here's how it works:
You want to access a URL, let's say
www.kame.net
. Your DNS should request anAAAA
as well as anA
record.If an
AAAA
record is returned, then it attempts to connect to the IPv6 address.If no connection can be established (host offline, IPv6 connection down, etc), or no
AAAA
record exists, IPv4 is used instead.Problems can occur in the following:
An incorrectly configured, or old, DNS server that does not return
AAAA
addresses will mean that IPv6 is never used.An incorrectly configured IPv6 network (e.g. having a routable IPv6 address (not a link-local address) but no RA's have been discovered, or the RA is not actually connected to the internet, then the TCP/IP stack can take up to 90 seconds to time out and fail back to IPv4, rendering it virtually useless.
If you are writing your own application that does its own DNS lookups, this is also the behaviour you should write into your application. If this is also the case though, then supporting IPv6 is a bit more complicated than just that (for example, our log parser, built on IPv4 had a fixed-sied, 32-bit field for IP address. That of course broke when we implemented our first IPv6 network).