The msort utility can be used to sort an OpenSSH known_hosts file in domain order.
msort -l -j -q -d', ' -n1 -cD ~/.ssh/known_hosts -2 ~/.ssh/known_hosts
For example:
$ cat known_hosts
a.a.com,127.0.0.1 ssh-rsa KEY
a.a.org,127.0.0.1 ssh-rsa KEY
a.b.com,127.0.0.1 ssh-rsa KEY
a.b.org,127.0.0.1 ssh-rsa KEY
b.a.com,127.0.0.1 ssh-rsa KEY
b.a.org,127.0.0.1 ssh-rsa KEY
b.b.com,127.0.0.1 ssh-rsa KEY
b.b.org,127.0.0.1 ssh-rsa KEY
$ msort -l -j -q -d', ' -n1 -cD known_hosts
a.a.com,127.0.0.1 ssh-rsa KEY
b.a.com,127.0.0.1 ssh-rsa KEY
a.b.com,127.0.0.1 ssh-rsa KEY
b.b.com,127.0.0.1 ssh-rsa KEY
a.a.org,127.0.0.1 ssh-rsa KEY
b.a.org,127.0.0.1 ssh-rsa KEY
a.b.org,127.0.0.1 ssh-rsa KEY
b.b.org,127.0.0.1 ssh-rsa KEY