Setting hostname and ip address with esxcli

Page content

Howto set hostname, doaminname, ip address, search doamins, dns etc. pp. on an esxi server with commandline.

Recipe:

1st: Login to your ESXi server as root

ssh root@ESXI-host

2nd: Define new hostname etc. pp

# config data:
myhost="HOSTNAME"
basedomain="example-domain1.com"
myfqdn="${myhost}.${basedomain}"
mysearch="$basedomain example-domain2.com"
mydns="1.1.1.1 8.8.8.8"
olddomains="example1.com example2.com"

3rd: Execute the following script

# set basic infos ...
esxcli system hostname set --host=$myhost
esxcli system hostname set --fqdn=$myfqdn
esxcli system hostname get

# remove old dns servers ...
esxcli network ip dns server remove --all

# add new dns servers ...
for n in $mydns ; do
  esxcli network ip dns server add -s $n
done
esxcli network ip dns server list

# remove old domains ...
for d in $olddomains ; do
  esxcli network ip dns search remove -d $d
done

# add new search domains ...
for s in $mysearch ; do
  esxcli network ip dns search add -d $s
done
esxcli network ip dns search list

4th: Reboot

reboot

Do not forget to re-register this server in the vcenter.

Reference: https://kb.vmware.com/s/article/1010821