VMware vSphere

 View Only
  • 1.  problem with changing virtual machine network name.

    Posted Aug 08, 2017 06:30 AM

    hello,

    I have problem with changing virtual machine name.

    when I change vm name, It's ok,

    but in esxcli network vm list, it showes me pervious name and It doesn't change without restart virtual machine.

    How can I change vm network name without restart virtual machine?



  • 2.  RE: problem with changing virtual machine network name.

    Posted Aug 08, 2017 12:49 PM

    Save, edit and run the below PS script to rename Windows VM without restart:

    $ComputerName = "New Name"

      

    Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname"

    Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname"

    New-PSDrive -name HKU -PSProvider "Registry" -Root "HKEY_USERS"

    Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\Computername" -name "Computername" -value $ComputerName

    Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername" -name "Computername" -value $ComputerName

    Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname" -value $ComputerName

    Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname" -value $ComputerName

    Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "AltDefaultDomainName" -value $ComputerName

    Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "DefaultDomainName" -value $ComputerName

    You can edit and use the below bash script for a Linux VM (Ubuntu in this example):

    #!/usr/bin/env bash
    NEW_HOSTNAME
    =$1
    echo $NEW_HOSTNAME
    > /proc/sys/kernel/hostname
    sed
    -i 's/127.0.1.1.*/127.0.1.1\t'"$NEW_HOSTNAME"'/g' /etc/hosts
    echo $NEW_HOSTNAME
    > /etc/hostname
    service hostname start
    su $SUDO_USER
    -c "xauth add $(xauth list | sed 's/^.*\//'"$NEW_HOSTNAME"'\//g' | awk 'NR==1 {sub($1,"\"&\""); print}')"