Configuring Address Family for SSH Connections

in   networking   ,

I recently enabled IPv6 on my home router and decided it was a good time to try and connect to my server using IPv6, rather than IPv4. However, on my Macbook, running High Sierra (the highest version supported), the SSH client would default to using IPv4 to connect.

Obviously, I don’t want to disable IPv4 altogether, as there are still sites which are IPv4 only. But, at least while I’m at home, I want to force SSH connectivity over IPv6. It turns out that there’s a simple option on the command line to do so.

ssh -6

The -6 tells the SSH client to use IPv6 connectivity. If you need to force it to use IPv4 for some reason, then use -4 instead. It’s also possible to add the address family preference in ~/.ssh/config, aptly named AddressFamily.

    # Use only IPv6
    AddressFamily inet6
    # Use only IPv4
    AddressFamily inet
    # Use any address family (default)
    AddressFamily any