Shell – Get IP addresses of Hyper-V Linux machines

hyper-vpowershell

I have Hyper-V on Windows Server 2012, and in the Hyper-v I have CentOS 6/7 vm.
I doing the following command:

Get-vm -name "x" | select -ExpandProperty NetworkAdapters

Output:

Name            IsManagementOs VMName SwitchName     MacAddress Status                         IPAddresses

----            -------------- ------ ----------     ---------- ------                         -----------

Network Adapter False          "x"    InternalSwitch Mac        {Degraded, protocolversion} {}

Why is IPAddresses empty?

I tried (command).ipaddresses and got the same result.

Best Answer

I had to install Linux Integration Services to the virtual machine (Linux Integration Services 4.1):

  1. Download the package from Linux Integration Services Version 4.1 for Hyper-V to the guest server (Linux) and unpack it. There is also an ISO image available that you can mount with Hyper-V Manager if you have no way of transferring the package to the guest host.
  2. Find your distribution under the unpacked directory (e.g. CentOS72).
  3. Run install.sh as root.
  4. Reboot the guest OS.

For CentOS 7 it also required to disable NetworkManager. That (and other hints) is told in Supported CentOS and Red Hat Enterprise Linux virtual machines on Hyper-V (Notes 2 for NetworkManager)

Run: systemctl disable NetworkManager and reboot

Now the Hyper-V Manager should show you the IP address of the VM and Get-VM should also work.

Related Question