Setting infos on the ESXi host with esxcli
Page content
Howto set hostname, domainname, 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"
mygw="0.0.0.0"
mydns="1.1.1.1 8.8.8.8"
basedomain="example1.com"
mysearch="$basedomain example2.com"
olddomains="example1-old.com example2-old.com"
myfqdn="${myhost}.${basedomain}"
3rd: Execute the following script
# seting basic infos ...
esxcli system hostname set --host=$myhost
esxcli system hostname set --fqdn=$myfqdn
# removing old dns servers ...
esxcli network ip dns server remove --all
# adding new dns servers ...
for n in $mydns ; do
esxcli network ip dns server add -s $n
done
# removing old search domains ...
for d in $olddomains ; do
esxcli network ip dns search remove -d $d
done
# adding new search domains ...
for s in $mysearch ; do
esxcli network ip dns search add -d $s
done
# setting new default gateway ...
esxcli network ip route ipv4 add --gateway $mygw --network default
# showing everyting
esxcli system hostname get
esxcli network ip dns server list
esxcli network ip dns search list
esxcli network ip route ipv4 list
4th: Reboot
reboot
Do not forget to eventually re-register this server in the vcenter.
Reference: https://kb.vmware.com/s/article/1010821