Centos – SSH connection is slow and buggy when connected by IPv6

centoscentos7domain-name-systemipv6ssh

I noticed that my SSH session is not usable (random connection errors, hugh delay, etc.) when I'm connected by IPv6. I'm not connecting to my server by IPv4/IPv6 addresses directly. I use my domain name which has valid A and AAAA DNS records. I noticed that I get randomly connected by either IPv4 or IPv6.

A simple solution would be to just disbale IPv6 in the ssh config, but I think that's a dirty solution.
I would rather know:

  1. Why get I connected by IPv4/IPv6 randomly.
  2. Why is only a session by IPv6 unstable?

Best Answer

ssh's -6 parameter forces the client to connect with IPv6: ssh -6 hostname

It is possible to stop sshd from listening on IPv6 but that would simply cause an error instead of your slow connection problem.

The exact reason why your connection alternates randomly between the two may be hard (and pointless) to pinpoint, but is probably related to the results (possibly their order) received by the DNS servers and local DNS caching.