ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    QEMU Get Guest IP

    IT Discussion
    qemu kvm linux
    2
    3
    1.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • stacksofplatesS
      stacksofplates
      last edited by

      QEMU has a guest agent like other hypervisors. If you have the guest agent you can get some info out of the guest directly from the host. Here's a way to get the IP address from the guest:

      virsh qemu-agent-command $guest '{"execute":"guest-network-get-interfaces"}' | python -mjson.tool
      

      This spits out some json:

      {
          "return": [
              {
                  "hardware-address": "00:00:00:00:00:00",
                  "ip-addresses": [
                      {
                          "ip-address": "127.0.0.1",
                          "ip-address-type": "ipv4",
                          "prefix": 8
                      },
                      {
                          "ip-address": "::1",
                          "ip-address-type": "ipv6",
                          "prefix": 128
                      }
                  ],
                  "name": "lo"
              },
              {
                  "hardware-address": "52:54:00:1b:3a:ba",
                  "ip-addresses": [
                      {
                          "ip-address": "10.1.30.6",
                          "ip-address-type": "ipv4",
                          "prefix": 24
                      },
                      {
                          "ip-address": "fe80::5054:ff:fe1b:3aba",
                          "ip-address-type": "ipv6",
                          "prefix": 64
                      }
                  ],
                  "name": "eth0"
              }
          ]
      }
      
      1 Reply Last reply Reply Quote 4
      • stacksofplatesS
        stacksofplates
        last edited by

        After looking around, you don't have to pass commands to QEMU directly. You can do the same thing using virsh and the domifaddr command:

        [jhooks@kvm ~]$ sudo virsh domifaddr gluster1 --source agent
         Name       MAC address          Protocol     Address
        -------------------------------------------------------------------------------
         lo         00:00:00:00:00:00    ipv4         127.0.0.1/8
         -          -                    ipv6         ::1/128
         eth0       52:54:00:50:d0:77    ipv4         10.1.30.220/24
         -          -                    ipv6         fe80::5054:ff:fe50:d077/64
        

        This is a little nicer since it doesn't spit out a ton of JSON to parse through. However, this means the last few hours I've spent trying to get Ansible to read just the one hardware address was for nothing.

        1 Reply Last reply Reply Quote 1
        • dafyreD
          dafyre
          last edited by

          But you learned something along the way. 😄

          1 Reply Last reply Reply Quote 3
          • 1 / 1
          • First post
            Last post