Finding the vCenter server

Ever wondered how do you find out what vCenter server is managing (or if there is any) a ESXi host? I’ve struggled for a while since there is no way via command line to see this information. vim-cmd, esxcli or esxcfg commands show nothing. I normally resorted to my Windows VM, launch the vSphere C# client and login directly to the ESXi host and wait for this to popup:


Thankfully, there is a way to see this without jumping through some extra hoops. If you can SSH to your ESX server, the vCenter IP is in this configuration file: /etc/vmware/vpxa/vpxa.cfg, under the vpxa portion:

 <hostKey>[Your key here]</hostKey>

You can grep for it by doing:

~ # cat /etc/vmware/vpxa/vpxa.cfg | grep serverI

If you have a lab environment and you have standardized on a common login scheme, you can script this to make life easier. Here is my script that I have.

if [ "$#" -lt 1 ]; then
 echo "Enter remote_host and password"
 exit 1
ssh-keygen -f "/root/.ssh/known_hosts" -R $ > /dev/null 2>&1
sshpas=`sshpass -p $2 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $1 cat /etc/vmware/vpxa/vpxa.cfg | grep serverIp`
VC=`echo $sshpas | tr -d '</>serverIp'`
NS=`nslookup $VC | grep name | awk '{print $4}'`
echo "$1 vCenter is: $NS ($VC) "


# ./ esx-001 password
Warning: Permanently added 'esx-001,' (RSA) to the list of known hosts.
esx-001 vCenter is: (

Note: It only shows an IP address, and I do a reverse lookup on it against my DNS server. If there is nothing there, it hangs out in the nslookup prompt and i just hit control+c to get out like this:

./ esx-001 password
Warning: Permanently added 'esx-001,' (RSA) to the list of known hosts.
> ^C


I also

Leave a Comment

3 × 2 =