Changing DNS Settings on ESXi Hosts is an article that shows an automated approach to changing the DNS configurations on all connected ESXi hosts under the same vCenter Server, using a Python script.
The idea is to use a Linux CentOS 9 as a script server. We’ll execute a Python script from this server to connect to each ESXi host and upgrade the VMware Tools.
1- Install CentOS 9 (without GUI) – We have tested it with CentOS 9, but feel free to install a different Linux flavor and adjust the script to run on it.
2- Access it by SSH with root rights and install Python:
curl -O https://raw.githubusercontent.com/danchiacchio/scripts/refs/heads/main/sh_PythonInstall/install-python.sh
chmod +x install-python.sh
./install-python.sh
Grab a coffee and wait for a while. The automated Python install takes a while to complete! ☕
3- Creating a working directory (something such as /root/scripts/py_vESXiDNS) – you can choose the directory name:
mkdir -p /root/scripts/py_vESXiDNS
4- Go to the working directory and download the Python script “py_vESXiDNS.py“:
cd /root/scripts/py_vESXiDNS
curl -O https://raw.githubusercontent.com/danchiacchio/scripts/refs/heads/main/py_vESXiDNS/py_vESXiDNS.py
pip install pyvmomi paramiko
5- Run the Python script:
chmod 700 py_vESXiDNS.py
python py_vESXiDNS.py




Rechecking the DNS config after changing the DNS Servers and DNS domain name:


In the following picture, we run the nslookup inside each ESXi host. The command failed because we’re using an unreachable DNS server:

After fixing it (changed to a working DNS server):

That’s it 🙂
Note: So, I tested it several times in a lab environment, and it worked as expected. However, be careful when executing it in a production environment. We’ll not be responsible for downtime or weird behavior in your environment!