Look up master node IP address in a loop

Fixes #2949