How to check free port number for multi node training

I am training a network on 2 machines each machine consists of two GPUS. I have checked the port number but it changes every time when I restart the process and I am not sure whether I am doing the right or wrong way.

How I can check the free port number? Is this the correct way?

sudo lsof -i :22 | grep LISTEN

sshd    1930    root    3u  IPv4  57569      0t0  TCP *:ssh (LISTEN)
sshd    1930    root    4u  IPv6  57571      0t0  TCP *:ssh (LISTEN)