MongoDB Reverse SSH Replica Set Config Fails when leader changes
You should use TLS/SSL for connections between those machines. Then you don't need to play around with ssh. With SSL connections between nodes are encrypted and IP addresses don't change.