How to find the IP address of a KVM Virtual Machine, that I can SSH into it?












26















I have follow this guide (Virtualization With KVM On Ubuntu 11.10) to setup my KVM (Virtual Machines Software) on my Ubuntu 11.10 Server. However, I didn't setup my VM's IP address when creating the VM, instead of using:



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --ip=192.168.0.101 --gw=192.168.0.1 --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I used: (I deleted "--ip=192.168.0.101 --gw=192.168.0.1" from the command line)



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I have set up the network bridge as the guide instructed and the new VM's interface is connected to the network bridge.



I assume the KVM will assign my VM via DHCP but I don't have information on my new VM's IP address, where can I find the VM's IP address and SSH to the new VM? Thanks.



[Notes: I have managed to login the VM without knowing the IP address of the VM. Using "Xming + SSH with X Graphic Forwarding" But there is no DHCP ip address assigned to my VM, Besides the above question, I have another question here: How to enable the DCHP on my VM so when I use Xming to login via "virt viewer" I can at least see my IP address is there.]










share|improve this question

























  • I have figured out the problem and solved it. In the /etc/network/interfaces I deleted "network" and "broadcast" information and the DHCP worked on my guest VMs. Now I can ssh into my Guest VM. I guess my "network XXX.XXX.XXX.XXX" or "broadcast XXX.XXX.XXX.XXX" is wrong. the guide is still working well for this kind of setup, just be careful when set up your own network environment. The problem is solved!!!

    – Xianlin
    Mar 9 '12 at 5:25






  • 1





    libvirt has two commands now: domifaddr and net-dhcp-leases

    – Nehal J Wani
    Mar 18 '15 at 0:04











  • please refer this link, you will find a answer:

    – user169994
    May 12 '16 at 3:38


















26















I have follow this guide (Virtualization With KVM On Ubuntu 11.10) to setup my KVM (Virtual Machines Software) on my Ubuntu 11.10 Server. However, I didn't setup my VM's IP address when creating the VM, instead of using:



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --ip=192.168.0.101 --gw=192.168.0.1 --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I used: (I deleted "--ip=192.168.0.101 --gw=192.168.0.1" from the command line)



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I have set up the network bridge as the guide instructed and the new VM's interface is connected to the network bridge.



I assume the KVM will assign my VM via DHCP but I don't have information on my new VM's IP address, where can I find the VM's IP address and SSH to the new VM? Thanks.



[Notes: I have managed to login the VM without knowing the IP address of the VM. Using "Xming + SSH with X Graphic Forwarding" But there is no DHCP ip address assigned to my VM, Besides the above question, I have another question here: How to enable the DCHP on my VM so when I use Xming to login via "virt viewer" I can at least see my IP address is there.]










share|improve this question

























  • I have figured out the problem and solved it. In the /etc/network/interfaces I deleted "network" and "broadcast" information and the DHCP worked on my guest VMs. Now I can ssh into my Guest VM. I guess my "network XXX.XXX.XXX.XXX" or "broadcast XXX.XXX.XXX.XXX" is wrong. the guide is still working well for this kind of setup, just be careful when set up your own network environment. The problem is solved!!!

    – Xianlin
    Mar 9 '12 at 5:25






  • 1





    libvirt has two commands now: domifaddr and net-dhcp-leases

    – Nehal J Wani
    Mar 18 '15 at 0:04











  • please refer this link, you will find a answer:

    – user169994
    May 12 '16 at 3:38
















26












26








26


6






I have follow this guide (Virtualization With KVM On Ubuntu 11.10) to setup my KVM (Virtual Machines Software) on my Ubuntu 11.10 Server. However, I didn't setup my VM's IP address when creating the VM, instead of using:



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --ip=192.168.0.101 --gw=192.168.0.1 --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I used: (I deleted "--ip=192.168.0.101 --gw=192.168.0.1" from the command line)



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I have set up the network bridge as the guide instructed and the new VM's interface is connected to the network bridge.



I assume the KVM will assign my VM via DHCP but I don't have information on my new VM's IP address, where can I find the VM's IP address and SSH to the new VM? Thanks.



[Notes: I have managed to login the VM without knowing the IP address of the VM. Using "Xming + SSH with X Graphic Forwarding" But there is no DHCP ip address assigned to my VM, Besides the above question, I have another question here: How to enable the DCHP on my VM so when I use Xming to login via "virt viewer" I can at least see my IP address is there.]










share|improve this question
















I have follow this guide (Virtualization With KVM On Ubuntu 11.10) to setup my KVM (Virtual Machines Software) on my Ubuntu 11.10 Server. However, I didn't setup my VM's IP address when creating the VM, instead of using:



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --ip=192.168.0.101 --gw=192.168.0.1 --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I used: (I deleted "--ip=192.168.0.101 --gw=192.168.0.1" from the command line)



vmbuilder kvm ubuntu --suite=oneiric --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --part=vmbuilder.partition --templates=mytemplates --user=administrator --name=Administrator --pass=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=256 --hostname=vm1 --bridge=br0


I have set up the network bridge as the guide instructed and the new VM's interface is connected to the network bridge.



I assume the KVM will assign my VM via DHCP but I don't have information on my new VM's IP address, where can I find the VM's IP address and SSH to the new VM? Thanks.



[Notes: I have managed to login the VM without knowing the IP address of the VM. Using "Xming + SSH with X Graphic Forwarding" But there is no DHCP ip address assigned to my VM, Besides the above question, I have another question here: How to enable the DCHP on my VM so when I use Xming to login via "virt viewer" I can at least see my IP address is there.]







ubuntu networking ip kvm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 17 '17 at 8:55









dr01

16.1k114973




16.1k114973










asked Mar 2 '12 at 2:24









XianlinXianlin

44341016




44341016













  • I have figured out the problem and solved it. In the /etc/network/interfaces I deleted "network" and "broadcast" information and the DHCP worked on my guest VMs. Now I can ssh into my Guest VM. I guess my "network XXX.XXX.XXX.XXX" or "broadcast XXX.XXX.XXX.XXX" is wrong. the guide is still working well for this kind of setup, just be careful when set up your own network environment. The problem is solved!!!

    – Xianlin
    Mar 9 '12 at 5:25






  • 1





    libvirt has two commands now: domifaddr and net-dhcp-leases

    – Nehal J Wani
    Mar 18 '15 at 0:04











  • please refer this link, you will find a answer:

    – user169994
    May 12 '16 at 3:38





















  • I have figured out the problem and solved it. In the /etc/network/interfaces I deleted "network" and "broadcast" information and the DHCP worked on my guest VMs. Now I can ssh into my Guest VM. I guess my "network XXX.XXX.XXX.XXX" or "broadcast XXX.XXX.XXX.XXX" is wrong. the guide is still working well for this kind of setup, just be careful when set up your own network environment. The problem is solved!!!

    – Xianlin
    Mar 9 '12 at 5:25






  • 1





    libvirt has two commands now: domifaddr and net-dhcp-leases

    – Nehal J Wani
    Mar 18 '15 at 0:04











  • please refer this link, you will find a answer:

    – user169994
    May 12 '16 at 3:38



















I have figured out the problem and solved it. In the /etc/network/interfaces I deleted "network" and "broadcast" information and the DHCP worked on my guest VMs. Now I can ssh into my Guest VM. I guess my "network XXX.XXX.XXX.XXX" or "broadcast XXX.XXX.XXX.XXX" is wrong. the guide is still working well for this kind of setup, just be careful when set up your own network environment. The problem is solved!!!

– Xianlin
Mar 9 '12 at 5:25





I have figured out the problem and solved it. In the /etc/network/interfaces I deleted "network" and "broadcast" information and the DHCP worked on my guest VMs. Now I can ssh into my Guest VM. I guess my "network XXX.XXX.XXX.XXX" or "broadcast XXX.XXX.XXX.XXX" is wrong. the guide is still working well for this kind of setup, just be careful when set up your own network environment. The problem is solved!!!

– Xianlin
Mar 9 '12 at 5:25




1




1





libvirt has two commands now: domifaddr and net-dhcp-leases

– Nehal J Wani
Mar 18 '15 at 0:04





libvirt has two commands now: domifaddr and net-dhcp-leases

– Nehal J Wani
Mar 18 '15 at 0:04













please refer this link, you will find a answer:

– user169994
May 12 '16 at 3:38







please refer this link, you will find a answer:

– user169994
May 12 '16 at 3:38












14 Answers
14






active

oldest

votes


















16














You can run arp -n to see what IP your virtual machine pick up. In that way, you don't have to login guest vm and type ifconfig.



The blog below has more details and includes a perl script which automates finding the address of a virtual machine.



Tip: Find the IP address of a virtual machine






share|improve this answer


























  • So simple. Great....

    – Indika K
    Nov 10 '16 at 4:22











  • Go to xyz webpage for answers are no good if link goes down, please post "full answers"

    – FreeSoftwareServers
    Feb 24 '18 at 8:11



















26














Try this:



virsh net-list
virsh net-dhcp-leases <net-name> <--- net-name from above command


You can also use following form if you know the MAC address:



virsh net-dhcp-leases <net-name> --mac <mac-address>


The MAC address can be found from dumpxml command. 
See Is there a way to determine which virtual interface belongs to a virtual machine in a kvm host?






share|improve this answer





















  • 3





    This is the correct answer. Works without any hacking. Thanks a lot.

    – chmac
    Jun 24 '16 at 13:46






  • 1





    Should be "virsh net-list" ... no space between "net" and "list". Otherwise, this works perfectly.

    – Dave Hein
    Aug 14 '16 at 13:57











  • @DaveHein Thanks for correcting. Updated the answer.

    – Rahul
    Aug 14 '16 at 17:50



















5














list for vms:



virsh list


get vm MAC from name



virsh domiflist debian8


do the scan of your vm subnet with grep (MAC must be capitalized)



nmap -sP 10.0.0.0/24 | grep 52:54:00:FD:1F:92 -B 3 


result



Nmap scan report for 10.0.0.173
Host is up (0.0012s latency).
MAC Address: 52:54:00:FD:1F:92 (QEMU Virtual NIC)





share|improve this answer

































    4














    If you have console access to the VM then just run ifconfig -a on the guest. While you are there, check to make sure that the guest does have network connectivity and that sshd is running.



    If you have not console access, then chances are the IP address was assigned by DHCP. Look for another machine that is also getting a DHCP assignment, maybe the host server, and then add 1 to the address and try it. In fact, try the next 5 or 6 addresses. If that doesn't work, then you either have a large active network and will need to try every IP address in the subnet, or there is a lower level network problem like no route to host or two hosts with the same MAC address. Or maybe you just didn't get sshd running.



    Using the console is the easiest way to solve this problem.






    share|improve this answer
























    • I actually managed to connect to my VM via Xming Server + "virt-viewr" command. I found there is no IP assigned to the guest while I am in the VM. How to make DHCP works? Any XML file I need to change?

      – Xianlin
      Mar 2 '12 at 6:21











    • Hi Michael, do you think you can help me if I give you access to my server? I tried DHCP and Static IP but the guest VMs are not getting any IP, my host server still can access the internet though. thanks.

      – Xianlin
      Mar 5 '12 at 3:21



















    3














    To see the IP address of your VM/s just run:



    $ arp -n



    If arp isn't installed on your system just install the net-tools package.






    share|improve this answer































      2














      It's possible to connect through builtin VNC with virt-manager, and you do tty login, find the ip address with ifconfig eth0. Normally eth0, unless you've specified otherwise.






      share|improve this answer































        2














        sudo nmap -sn 192.168.5.0/24 | awk '/Nmap scan report/{printf $5;printf " ";getline;getline;print $3;}' | fgrep -if <(virsh list --name | grep . | while read n; do virsh domiflist $n; done | grep --only-matching ..:..:..:..:..:..)



        Scan subnet. Parse the output with awk to get lines like <IP> <MAC>. Then grep in them using a list of the MACs of the VMs.



        The list of the MACs is obtained by listing all of the VMs (also strip empty lines), then doing virsh domiflist for each of them, and then grepping for a pattern that looks like a MAC.



        Sources:



        https://serverfault.com/a/669862/284568






        share|improve this answer































          2














          I guess this is an old question, but the current versions of virsh make this a lot easier if you're using a nat or bridged private network. I have a machine - steak - on a (routed) private network:



          sauer@helium:~> sudo virsh list
          Id Name State
          ----------------------------------------------------
          21 steak running

          sauer@helium:~> sudo virsh domifaddr steak
          Name MAC address Protocol Address
          -------------------------------------------------------------------------------
          vnet0 76:0c:28:ab:0e:ee ipv4 10.14.1.1/24


          On another machine, I have a system (unifi) which is bridged to the regular network. Libvirt doesn't assign it an address; it gets an address from my network DHCP server, which also updates dynamic DNS in my case. So, you basically have to find the address like it's any other machine - finding it in the arp table is probably the easiest -- which means ip neighbour now, as arp is deprecated and no longer present on some distributions. Luckily for those of us who don't spell things with extrae vouwels, you can also use shorter versions, like ip neigh and ip n (or ip neighbor). ;)



          sauer@helium:~$ sudo virsh domifaddr unifi
          Name MAC address Protocol Address
          -------------------------------------------------------------------------------

          sauer@helium:~$ sudo virsh domiflist unifi
          Interface Type Source Model MAC
          -------------------------------------------------------
          vnet0 bridge br0 virtio 52:54:00:2c:ac:ee

          sauer@helium:~$ ip neigh | grep -i 52:54:00:2c:ac:ee
          192.168.0.226 dev br0 lladdr 52:54:00:2c:ac:ee REACHABLE
          sauer@helium:~$ host unifi
          unifi.home.domain.com has address 192.168.0.226





          share|improve this answer































            0














            (While you seem too advanced for such a simple answer)



            Will



            $ ifconfig


            work?






            share|improve this answer
























            • also, be careful, if you have duplicate instances of the same machine, as the machine will have issues with the fake MAC address etc... there are ways to manually edit that (and I think run a command for that as well)

              – David
              Mar 2 '12 at 3:58











            • I only have one VM "vm1" on my ubuntu server host and the "ifconfig" command output shows no ip address assigned to my "eth0" network adapter.

              – Xianlin
              Mar 2 '12 at 4:59











            • yeah, you have no ip... Did you try "dhclient eth0" --might need sudo

              – David
              Mar 3 '12 at 23:21













            • I tried but still not getting dhcp ip from my host server to my guest VMs. My host server is assigned a fixed IP and it can access the internet.

              – Xianlin
              Mar 5 '12 at 3:22











            • if you want an ip not on the parent network, you want to select NAT in your vm settings instead of bridged.

              – David
              Mar 5 '12 at 18:57



















            0














            If you have QEMU(VM emulator) go to "i" button and check the network card associated with "Br0" network. Take a note of the mac address of the NIC. Now Login to your VM -> Open Terminal -> type: "ifconfig" command in the terminal -> take a note of IP address associated with the the Mac address that you have noted earlier.



            You can login to your VM using Putty or any ssh client using the IP you have noted in the last step.






            share|improve this answer































              0














              I have my KVM guests on br0 interface so I think its a bit different, but here is my two scripts I made.



              Note to use ARP you first need to have the MAC in your Arp Table. Therefor its best to use fping to do a quick ping of entire network (takes like 2 seconds). This makes sure your Arp cache is up to date.



              apt-get install fping
              yum install fping


              Find a single guest IP via :



              cat << 'EOF' > ~/findip.sh
              #!/bin/bash
              #FreeSoftwareServers.com

              echo "Finding All Active IP's in Network via single Ping"
              sleep 2s

              fping -a -g 192.168.1.0/24
              #nmap -sn 192.168.1.0/24

              echo "Please Enter the Exact Name of the VM Guest:"

              read guestname

              arp -na | awk -v mac=$(virsh domiflist $guestname | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}'
              EOF
              chmod +x ~/findip.sh
              sudo sh -c 'echo "alias findguestip=~/findip.sh" >> ~/.bashrc'
              source ~/.bashrc
              findguestip


              Find All Guest IP's via:



              cat << 'EOF' > ~/findallips.sh
              #!/bin/bash
              #FreeSoftwareServers.com

              echo "Finding All Active IP's in Network via single Ping"
              sleep 2s

              fping -a -g 192.168.1.0/24
              #nmap -sn 192.168.1.0/24

              domainlog=/tmp/domain.log

              virsh list --all | grep running | cut -c 8- >> "$domainlog"

              sed -i 's/running*//g' "$domainlog"

              readarray domain < "$domainlog"

              for i in "${domain[@]}"
              do
              ip="$(arp -na | awk -v mac=$(virsh domiflist $i | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}')"
              echo "Hostname : $i IP : $ip"
              done
              rm "$domainlog"
              EOF
              chmod +x ~/findallips.sh
              sudo sh -c 'echo "alias findallips=~/findallips.sh" >> ~/.bashrc'
              source ~/.bashrc
              findallips





              share|improve this answer


























              • I tackled this problem in the end with arp-scan. example: sudo arp-scan --interface=br0 --localnet --bandwidth=8192000 --numeric --retry=1 that was for when I wanted to actively search. I used addrwatch to sit in the background and accumulate a mac/ip address mapping for me.

                – Duke Dougal
                Feb 26 '18 at 20:38



















              0














              I wrote a get-vm-ip script (available at https://github.com/earlruby/create-vm/blob/master/get-vm-ip) which uses this to get the IP:



              HOSTNAME=[your vm name]
              MAC=$(virsh domiflist $HOSTNAME | awk '{ print $5 }' | tail -2 | head -1)
              arp -a | grep $MAC | awk '{ print $2 }' | sed 's/[()]//g'





              share|improve this answer































                0
















                1. Get your domain list by virsh list --all



                  virsh # list --all

                  2 webserver_01 running



                2. Get your domain interface list by domain id or name using virsh domiflist yourDomainId, and you will see the MAC ADDRESS of the domain's interface.



                  virsh # domiflist 2

                  bridge br0 virtio 52:54:00:42:be:96



                3. Using nmap scan your LAN by nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B 2, you will get the IP ADDRESS.



                  [root@kvm-master ~]# nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B2 

                  Nmap scan report for bogon (192.168.1.210)
                  Host is up (0.00013s latency).
                  MAC Address: 52:54:00:42:BE:96 (QEMU Virtual NIC)







                share|improve this answer

































                  0














                  A nice solution which use the qemu-guest agent.



                  a)Configure your vm to use qemu-guest agent
                  On host: Add with virt-manager a "qemu-guest-agent" channel
                  Is really easy.In my case machine is called "Debian",and xml after modify will be similar to this.



                   <channel type='unix'>
                  <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-3-debian/org.qemu.guest_agent.0'/>
                  <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
                  <alias name='channel1'/>
                  <address type='virtio-serial' controller='0' bus='0' port='2'/>
                  </channel>


                  b)On guest install qemu-guest-agent and ensure is started



                  apt -y install qemu-guest-agent

                  systemctl status qemu-guest-agent.service
                  ● qemu-guest-agent.service - LSB: QEMU Guest Agent startup script
                  Loaded: loaded (/etc/init.d/qemu-guest-agent; generated; vendor preset: enabled)
                  Active: active (running) since Sat 2019-01-26 09:35:57 CET; 3s ago
                  Docs: man:systemd-sysv-generator(8)
                  Process: 1624 ExecStop=/etc/init.d/qemu-guest-agent stop (code=exited, status=0/SUCCESS)
                  Process: 1630 ExecStart=/etc/init.d/qemu-guest-agent start (code=exited, status=0/SUCCESS)
                  Tasks: 1 (limit: 4915)
                  CGroup: /system.slice/qemu-guest-agent.service
                  └─1638 /usr/sbin/qemu-ga --daemonize -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent.0


                  c)Finally this nice pipe will return the ip,instead of NAMEOFVMNIC put eth0,enp1s0,etc..



                  virsh domifaddr  --domain yourvmname --source agent|grep -w NAMEOFVMNIC|egrep -o '([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}'





                  share|improve this answer

























                    Your Answer








                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "106"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: false,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: null,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f33191%2fhow-to-find-the-ip-address-of-a-kvm-virtual-machine-that-i-can-ssh-into-it%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    14 Answers
                    14






                    active

                    oldest

                    votes








                    14 Answers
                    14






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    16














                    You can run arp -n to see what IP your virtual machine pick up. In that way, you don't have to login guest vm and type ifconfig.



                    The blog below has more details and includes a perl script which automates finding the address of a virtual machine.



                    Tip: Find the IP address of a virtual machine






                    share|improve this answer


























                    • So simple. Great....

                      – Indika K
                      Nov 10 '16 at 4:22











                    • Go to xyz webpage for answers are no good if link goes down, please post "full answers"

                      – FreeSoftwareServers
                      Feb 24 '18 at 8:11
















                    16














                    You can run arp -n to see what IP your virtual machine pick up. In that way, you don't have to login guest vm and type ifconfig.



                    The blog below has more details and includes a perl script which automates finding the address of a virtual machine.



                    Tip: Find the IP address of a virtual machine






                    share|improve this answer


























                    • So simple. Great....

                      – Indika K
                      Nov 10 '16 at 4:22











                    • Go to xyz webpage for answers are no good if link goes down, please post "full answers"

                      – FreeSoftwareServers
                      Feb 24 '18 at 8:11














                    16












                    16








                    16







                    You can run arp -n to see what IP your virtual machine pick up. In that way, you don't have to login guest vm and type ifconfig.



                    The blog below has more details and includes a perl script which automates finding the address of a virtual machine.



                    Tip: Find the IP address of a virtual machine






                    share|improve this answer















                    You can run arp -n to see what IP your virtual machine pick up. In that way, you don't have to login guest vm and type ifconfig.



                    The blog below has more details and includes a perl script which automates finding the address of a virtual machine.



                    Tip: Find the IP address of a virtual machine







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 3 at 18:16









                    Michael Hampton

                    5,68411742




                    5,68411742










                    answered Mar 25 '13 at 8:50









                    chenwjchenwj

                    28423




                    28423













                    • So simple. Great....

                      – Indika K
                      Nov 10 '16 at 4:22











                    • Go to xyz webpage for answers are no good if link goes down, please post "full answers"

                      – FreeSoftwareServers
                      Feb 24 '18 at 8:11



















                    • So simple. Great....

                      – Indika K
                      Nov 10 '16 at 4:22











                    • Go to xyz webpage for answers are no good if link goes down, please post "full answers"

                      – FreeSoftwareServers
                      Feb 24 '18 at 8:11

















                    So simple. Great....

                    – Indika K
                    Nov 10 '16 at 4:22





                    So simple. Great....

                    – Indika K
                    Nov 10 '16 at 4:22













                    Go to xyz webpage for answers are no good if link goes down, please post "full answers"

                    – FreeSoftwareServers
                    Feb 24 '18 at 8:11





                    Go to xyz webpage for answers are no good if link goes down, please post "full answers"

                    – FreeSoftwareServers
                    Feb 24 '18 at 8:11













                    26














                    Try this:



                    virsh net-list
                    virsh net-dhcp-leases <net-name> <--- net-name from above command


                    You can also use following form if you know the MAC address:



                    virsh net-dhcp-leases <net-name> --mac <mac-address>


                    The MAC address can be found from dumpxml command. 
                    See Is there a way to determine which virtual interface belongs to a virtual machine in a kvm host?






                    share|improve this answer





















                    • 3





                      This is the correct answer. Works without any hacking. Thanks a lot.

                      – chmac
                      Jun 24 '16 at 13:46






                    • 1





                      Should be "virsh net-list" ... no space between "net" and "list". Otherwise, this works perfectly.

                      – Dave Hein
                      Aug 14 '16 at 13:57











                    • @DaveHein Thanks for correcting. Updated the answer.

                      – Rahul
                      Aug 14 '16 at 17:50
















                    26














                    Try this:



                    virsh net-list
                    virsh net-dhcp-leases <net-name> <--- net-name from above command


                    You can also use following form if you know the MAC address:



                    virsh net-dhcp-leases <net-name> --mac <mac-address>


                    The MAC address can be found from dumpxml command. 
                    See Is there a way to determine which virtual interface belongs to a virtual machine in a kvm host?






                    share|improve this answer





















                    • 3





                      This is the correct answer. Works without any hacking. Thanks a lot.

                      – chmac
                      Jun 24 '16 at 13:46






                    • 1





                      Should be "virsh net-list" ... no space between "net" and "list". Otherwise, this works perfectly.

                      – Dave Hein
                      Aug 14 '16 at 13:57











                    • @DaveHein Thanks for correcting. Updated the answer.

                      – Rahul
                      Aug 14 '16 at 17:50














                    26












                    26








                    26







                    Try this:



                    virsh net-list
                    virsh net-dhcp-leases <net-name> <--- net-name from above command


                    You can also use following form if you know the MAC address:



                    virsh net-dhcp-leases <net-name> --mac <mac-address>


                    The MAC address can be found from dumpxml command. 
                    See Is there a way to determine which virtual interface belongs to a virtual machine in a kvm host?






                    share|improve this answer















                    Try this:



                    virsh net-list
                    virsh net-dhcp-leases <net-name> <--- net-name from above command


                    You can also use following form if you know the MAC address:



                    virsh net-dhcp-leases <net-name> --mac <mac-address>


                    The MAC address can be found from dumpxml command. 
                    See Is there a way to determine which virtual interface belongs to a virtual machine in a kvm host?







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 12 '17 at 23:15









                    G-Man

                    13.1k93465




                    13.1k93465










                    answered May 13 '16 at 21:57









                    RahulRahul

                    36635




                    36635








                    • 3





                      This is the correct answer. Works without any hacking. Thanks a lot.

                      – chmac
                      Jun 24 '16 at 13:46






                    • 1





                      Should be "virsh net-list" ... no space between "net" and "list". Otherwise, this works perfectly.

                      – Dave Hein
                      Aug 14 '16 at 13:57











                    • @DaveHein Thanks for correcting. Updated the answer.

                      – Rahul
                      Aug 14 '16 at 17:50














                    • 3





                      This is the correct answer. Works without any hacking. Thanks a lot.

                      – chmac
                      Jun 24 '16 at 13:46






                    • 1





                      Should be "virsh net-list" ... no space between "net" and "list". Otherwise, this works perfectly.

                      – Dave Hein
                      Aug 14 '16 at 13:57











                    • @DaveHein Thanks for correcting. Updated the answer.

                      – Rahul
                      Aug 14 '16 at 17:50








                    3




                    3





                    This is the correct answer. Works without any hacking. Thanks a lot.

                    – chmac
                    Jun 24 '16 at 13:46





                    This is the correct answer. Works without any hacking. Thanks a lot.

                    – chmac
                    Jun 24 '16 at 13:46




                    1




                    1





                    Should be "virsh net-list" ... no space between "net" and "list". Otherwise, this works perfectly.

                    – Dave Hein
                    Aug 14 '16 at 13:57





                    Should be "virsh net-list" ... no space between "net" and "list". Otherwise, this works perfectly.

                    – Dave Hein
                    Aug 14 '16 at 13:57













                    @DaveHein Thanks for correcting. Updated the answer.

                    – Rahul
                    Aug 14 '16 at 17:50





                    @DaveHein Thanks for correcting. Updated the answer.

                    – Rahul
                    Aug 14 '16 at 17:50











                    5














                    list for vms:



                    virsh list


                    get vm MAC from name



                    virsh domiflist debian8


                    do the scan of your vm subnet with grep (MAC must be capitalized)



                    nmap -sP 10.0.0.0/24 | grep 52:54:00:FD:1F:92 -B 3 


                    result



                    Nmap scan report for 10.0.0.173
                    Host is up (0.0012s latency).
                    MAC Address: 52:54:00:FD:1F:92 (QEMU Virtual NIC)





                    share|improve this answer






























                      5














                      list for vms:



                      virsh list


                      get vm MAC from name



                      virsh domiflist debian8


                      do the scan of your vm subnet with grep (MAC must be capitalized)



                      nmap -sP 10.0.0.0/24 | grep 52:54:00:FD:1F:92 -B 3 


                      result



                      Nmap scan report for 10.0.0.173
                      Host is up (0.0012s latency).
                      MAC Address: 52:54:00:FD:1F:92 (QEMU Virtual NIC)





                      share|improve this answer




























                        5












                        5








                        5







                        list for vms:



                        virsh list


                        get vm MAC from name



                        virsh domiflist debian8


                        do the scan of your vm subnet with grep (MAC must be capitalized)



                        nmap -sP 10.0.0.0/24 | grep 52:54:00:FD:1F:92 -B 3 


                        result



                        Nmap scan report for 10.0.0.173
                        Host is up (0.0012s latency).
                        MAC Address: 52:54:00:FD:1F:92 (QEMU Virtual NIC)





                        share|improve this answer















                        list for vms:



                        virsh list


                        get vm MAC from name



                        virsh domiflist debian8


                        do the scan of your vm subnet with grep (MAC must be capitalized)



                        nmap -sP 10.0.0.0/24 | grep 52:54:00:FD:1F:92 -B 3 


                        result



                        Nmap scan report for 10.0.0.173
                        Host is up (0.0012s latency).
                        MAC Address: 52:54:00:FD:1F:92 (QEMU Virtual NIC)






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Apr 22 '17 at 20:02

























                        answered Apr 22 '17 at 19:56









                        Antonín VrbaAntonín Vrba

                        5912




                        5912























                            4














                            If you have console access to the VM then just run ifconfig -a on the guest. While you are there, check to make sure that the guest does have network connectivity and that sshd is running.



                            If you have not console access, then chances are the IP address was assigned by DHCP. Look for another machine that is also getting a DHCP assignment, maybe the host server, and then add 1 to the address and try it. In fact, try the next 5 or 6 addresses. If that doesn't work, then you either have a large active network and will need to try every IP address in the subnet, or there is a lower level network problem like no route to host or two hosts with the same MAC address. Or maybe you just didn't get sshd running.



                            Using the console is the easiest way to solve this problem.






                            share|improve this answer
























                            • I actually managed to connect to my VM via Xming Server + "virt-viewr" command. I found there is no IP assigned to the guest while I am in the VM. How to make DHCP works? Any XML file I need to change?

                              – Xianlin
                              Mar 2 '12 at 6:21











                            • Hi Michael, do you think you can help me if I give you access to my server? I tried DHCP and Static IP but the guest VMs are not getting any IP, my host server still can access the internet though. thanks.

                              – Xianlin
                              Mar 5 '12 at 3:21
















                            4














                            If you have console access to the VM then just run ifconfig -a on the guest. While you are there, check to make sure that the guest does have network connectivity and that sshd is running.



                            If you have not console access, then chances are the IP address was assigned by DHCP. Look for another machine that is also getting a DHCP assignment, maybe the host server, and then add 1 to the address and try it. In fact, try the next 5 or 6 addresses. If that doesn't work, then you either have a large active network and will need to try every IP address in the subnet, or there is a lower level network problem like no route to host or two hosts with the same MAC address. Or maybe you just didn't get sshd running.



                            Using the console is the easiest way to solve this problem.






                            share|improve this answer
























                            • I actually managed to connect to my VM via Xming Server + "virt-viewr" command. I found there is no IP assigned to the guest while I am in the VM. How to make DHCP works? Any XML file I need to change?

                              – Xianlin
                              Mar 2 '12 at 6:21











                            • Hi Michael, do you think you can help me if I give you access to my server? I tried DHCP and Static IP but the guest VMs are not getting any IP, my host server still can access the internet though. thanks.

                              – Xianlin
                              Mar 5 '12 at 3:21














                            4












                            4








                            4







                            If you have console access to the VM then just run ifconfig -a on the guest. While you are there, check to make sure that the guest does have network connectivity and that sshd is running.



                            If you have not console access, then chances are the IP address was assigned by DHCP. Look for another machine that is also getting a DHCP assignment, maybe the host server, and then add 1 to the address and try it. In fact, try the next 5 or 6 addresses. If that doesn't work, then you either have a large active network and will need to try every IP address in the subnet, or there is a lower level network problem like no route to host or two hosts with the same MAC address. Or maybe you just didn't get sshd running.



                            Using the console is the easiest way to solve this problem.






                            share|improve this answer













                            If you have console access to the VM then just run ifconfig -a on the guest. While you are there, check to make sure that the guest does have network connectivity and that sshd is running.



                            If you have not console access, then chances are the IP address was assigned by DHCP. Look for another machine that is also getting a DHCP assignment, maybe the host server, and then add 1 to the address and try it. In fact, try the next 5 or 6 addresses. If that doesn't work, then you either have a large active network and will need to try every IP address in the subnet, or there is a lower level network problem like no route to host or two hosts with the same MAC address. Or maybe you just didn't get sshd running.



                            Using the console is the easiest way to solve this problem.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 2 '12 at 5:08









                            Michael DillonMichael Dillon

                            75737




                            75737













                            • I actually managed to connect to my VM via Xming Server + "virt-viewr" command. I found there is no IP assigned to the guest while I am in the VM. How to make DHCP works? Any XML file I need to change?

                              – Xianlin
                              Mar 2 '12 at 6:21











                            • Hi Michael, do you think you can help me if I give you access to my server? I tried DHCP and Static IP but the guest VMs are not getting any IP, my host server still can access the internet though. thanks.

                              – Xianlin
                              Mar 5 '12 at 3:21



















                            • I actually managed to connect to my VM via Xming Server + "virt-viewr" command. I found there is no IP assigned to the guest while I am in the VM. How to make DHCP works? Any XML file I need to change?

                              – Xianlin
                              Mar 2 '12 at 6:21











                            • Hi Michael, do you think you can help me if I give you access to my server? I tried DHCP and Static IP but the guest VMs are not getting any IP, my host server still can access the internet though. thanks.

                              – Xianlin
                              Mar 5 '12 at 3:21

















                            I actually managed to connect to my VM via Xming Server + "virt-viewr" command. I found there is no IP assigned to the guest while I am in the VM. How to make DHCP works? Any XML file I need to change?

                            – Xianlin
                            Mar 2 '12 at 6:21





                            I actually managed to connect to my VM via Xming Server + "virt-viewr" command. I found there is no IP assigned to the guest while I am in the VM. How to make DHCP works? Any XML file I need to change?

                            – Xianlin
                            Mar 2 '12 at 6:21













                            Hi Michael, do you think you can help me if I give you access to my server? I tried DHCP and Static IP but the guest VMs are not getting any IP, my host server still can access the internet though. thanks.

                            – Xianlin
                            Mar 5 '12 at 3:21





                            Hi Michael, do you think you can help me if I give you access to my server? I tried DHCP and Static IP but the guest VMs are not getting any IP, my host server still can access the internet though. thanks.

                            – Xianlin
                            Mar 5 '12 at 3:21











                            3














                            To see the IP address of your VM/s just run:



                            $ arp -n



                            If arp isn't installed on your system just install the net-tools package.






                            share|improve this answer




























                              3














                              To see the IP address of your VM/s just run:



                              $ arp -n



                              If arp isn't installed on your system just install the net-tools package.






                              share|improve this answer


























                                3












                                3








                                3







                                To see the IP address of your VM/s just run:



                                $ arp -n



                                If arp isn't installed on your system just install the net-tools package.






                                share|improve this answer













                                To see the IP address of your VM/s just run:



                                $ arp -n



                                If arp isn't installed on your system just install the net-tools package.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Apr 22 '17 at 20:42









                                AlxsAlxs

                                1,1011624




                                1,1011624























                                    2














                                    It's possible to connect through builtin VNC with virt-manager, and you do tty login, find the ip address with ifconfig eth0. Normally eth0, unless you've specified otherwise.






                                    share|improve this answer




























                                      2














                                      It's possible to connect through builtin VNC with virt-manager, and you do tty login, find the ip address with ifconfig eth0. Normally eth0, unless you've specified otherwise.






                                      share|improve this answer


























                                        2












                                        2








                                        2







                                        It's possible to connect through builtin VNC with virt-manager, and you do tty login, find the ip address with ifconfig eth0. Normally eth0, unless you've specified otherwise.






                                        share|improve this answer













                                        It's possible to connect through builtin VNC with virt-manager, and you do tty login, find the ip address with ifconfig eth0. Normally eth0, unless you've specified otherwise.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Sep 28 '12 at 9:16









                                        daisydaisy

                                        28.7k49170302




                                        28.7k49170302























                                            2














                                            sudo nmap -sn 192.168.5.0/24 | awk '/Nmap scan report/{printf $5;printf " ";getline;getline;print $3;}' | fgrep -if <(virsh list --name | grep . | while read n; do virsh domiflist $n; done | grep --only-matching ..:..:..:..:..:..)



                                            Scan subnet. Parse the output with awk to get lines like <IP> <MAC>. Then grep in them using a list of the MACs of the VMs.



                                            The list of the MACs is obtained by listing all of the VMs (also strip empty lines), then doing virsh domiflist for each of them, and then grepping for a pattern that looks like a MAC.



                                            Sources:



                                            https://serverfault.com/a/669862/284568






                                            share|improve this answer




























                                              2














                                              sudo nmap -sn 192.168.5.0/24 | awk '/Nmap scan report/{printf $5;printf " ";getline;getline;print $3;}' | fgrep -if <(virsh list --name | grep . | while read n; do virsh domiflist $n; done | grep --only-matching ..:..:..:..:..:..)



                                              Scan subnet. Parse the output with awk to get lines like <IP> <MAC>. Then grep in them using a list of the MACs of the VMs.



                                              The list of the MACs is obtained by listing all of the VMs (also strip empty lines), then doing virsh domiflist for each of them, and then grepping for a pattern that looks like a MAC.



                                              Sources:



                                              https://serverfault.com/a/669862/284568






                                              share|improve this answer


























                                                2












                                                2








                                                2







                                                sudo nmap -sn 192.168.5.0/24 | awk '/Nmap scan report/{printf $5;printf " ";getline;getline;print $3;}' | fgrep -if <(virsh list --name | grep . | while read n; do virsh domiflist $n; done | grep --only-matching ..:..:..:..:..:..)



                                                Scan subnet. Parse the output with awk to get lines like <IP> <MAC>. Then grep in them using a list of the MACs of the VMs.



                                                The list of the MACs is obtained by listing all of the VMs (also strip empty lines), then doing virsh domiflist for each of them, and then grepping for a pattern that looks like a MAC.



                                                Sources:



                                                https://serverfault.com/a/669862/284568






                                                share|improve this answer













                                                sudo nmap -sn 192.168.5.0/24 | awk '/Nmap scan report/{printf $5;printf " ";getline;getline;print $3;}' | fgrep -if <(virsh list --name | grep . | while read n; do virsh domiflist $n; done | grep --only-matching ..:..:..:..:..:..)



                                                Scan subnet. Parse the output with awk to get lines like <IP> <MAC>. Then grep in them using a list of the MACs of the VMs.



                                                The list of the MACs is obtained by listing all of the VMs (also strip empty lines), then doing virsh domiflist for each of them, and then grepping for a pattern that looks like a MAC.



                                                Sources:



                                                https://serverfault.com/a/669862/284568







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Apr 26 '17 at 6:53









                                                VelkanVelkan

                                                236210




                                                236210























                                                    2














                                                    I guess this is an old question, but the current versions of virsh make this a lot easier if you're using a nat or bridged private network. I have a machine - steak - on a (routed) private network:



                                                    sauer@helium:~> sudo virsh list
                                                    Id Name State
                                                    ----------------------------------------------------
                                                    21 steak running

                                                    sauer@helium:~> sudo virsh domifaddr steak
                                                    Name MAC address Protocol Address
                                                    -------------------------------------------------------------------------------
                                                    vnet0 76:0c:28:ab:0e:ee ipv4 10.14.1.1/24


                                                    On another machine, I have a system (unifi) which is bridged to the regular network. Libvirt doesn't assign it an address; it gets an address from my network DHCP server, which also updates dynamic DNS in my case. So, you basically have to find the address like it's any other machine - finding it in the arp table is probably the easiest -- which means ip neighbour now, as arp is deprecated and no longer present on some distributions. Luckily for those of us who don't spell things with extrae vouwels, you can also use shorter versions, like ip neigh and ip n (or ip neighbor). ;)



                                                    sauer@helium:~$ sudo virsh domifaddr unifi
                                                    Name MAC address Protocol Address
                                                    -------------------------------------------------------------------------------

                                                    sauer@helium:~$ sudo virsh domiflist unifi
                                                    Interface Type Source Model MAC
                                                    -------------------------------------------------------
                                                    vnet0 bridge br0 virtio 52:54:00:2c:ac:ee

                                                    sauer@helium:~$ ip neigh | grep -i 52:54:00:2c:ac:ee
                                                    192.168.0.226 dev br0 lladdr 52:54:00:2c:ac:ee REACHABLE
                                                    sauer@helium:~$ host unifi
                                                    unifi.home.domain.com has address 192.168.0.226





                                                    share|improve this answer




























                                                      2














                                                      I guess this is an old question, but the current versions of virsh make this a lot easier if you're using a nat or bridged private network. I have a machine - steak - on a (routed) private network:



                                                      sauer@helium:~> sudo virsh list
                                                      Id Name State
                                                      ----------------------------------------------------
                                                      21 steak running

                                                      sauer@helium:~> sudo virsh domifaddr steak
                                                      Name MAC address Protocol Address
                                                      -------------------------------------------------------------------------------
                                                      vnet0 76:0c:28:ab:0e:ee ipv4 10.14.1.1/24


                                                      On another machine, I have a system (unifi) which is bridged to the regular network. Libvirt doesn't assign it an address; it gets an address from my network DHCP server, which also updates dynamic DNS in my case. So, you basically have to find the address like it's any other machine - finding it in the arp table is probably the easiest -- which means ip neighbour now, as arp is deprecated and no longer present on some distributions. Luckily for those of us who don't spell things with extrae vouwels, you can also use shorter versions, like ip neigh and ip n (or ip neighbor). ;)



                                                      sauer@helium:~$ sudo virsh domifaddr unifi
                                                      Name MAC address Protocol Address
                                                      -------------------------------------------------------------------------------

                                                      sauer@helium:~$ sudo virsh domiflist unifi
                                                      Interface Type Source Model MAC
                                                      -------------------------------------------------------
                                                      vnet0 bridge br0 virtio 52:54:00:2c:ac:ee

                                                      sauer@helium:~$ ip neigh | grep -i 52:54:00:2c:ac:ee
                                                      192.168.0.226 dev br0 lladdr 52:54:00:2c:ac:ee REACHABLE
                                                      sauer@helium:~$ host unifi
                                                      unifi.home.domain.com has address 192.168.0.226





                                                      share|improve this answer


























                                                        2












                                                        2








                                                        2







                                                        I guess this is an old question, but the current versions of virsh make this a lot easier if you're using a nat or bridged private network. I have a machine - steak - on a (routed) private network:



                                                        sauer@helium:~> sudo virsh list
                                                        Id Name State
                                                        ----------------------------------------------------
                                                        21 steak running

                                                        sauer@helium:~> sudo virsh domifaddr steak
                                                        Name MAC address Protocol Address
                                                        -------------------------------------------------------------------------------
                                                        vnet0 76:0c:28:ab:0e:ee ipv4 10.14.1.1/24


                                                        On another machine, I have a system (unifi) which is bridged to the regular network. Libvirt doesn't assign it an address; it gets an address from my network DHCP server, which also updates dynamic DNS in my case. So, you basically have to find the address like it's any other machine - finding it in the arp table is probably the easiest -- which means ip neighbour now, as arp is deprecated and no longer present on some distributions. Luckily for those of us who don't spell things with extrae vouwels, you can also use shorter versions, like ip neigh and ip n (or ip neighbor). ;)



                                                        sauer@helium:~$ sudo virsh domifaddr unifi
                                                        Name MAC address Protocol Address
                                                        -------------------------------------------------------------------------------

                                                        sauer@helium:~$ sudo virsh domiflist unifi
                                                        Interface Type Source Model MAC
                                                        -------------------------------------------------------
                                                        vnet0 bridge br0 virtio 52:54:00:2c:ac:ee

                                                        sauer@helium:~$ ip neigh | grep -i 52:54:00:2c:ac:ee
                                                        192.168.0.226 dev br0 lladdr 52:54:00:2c:ac:ee REACHABLE
                                                        sauer@helium:~$ host unifi
                                                        unifi.home.domain.com has address 192.168.0.226





                                                        share|improve this answer













                                                        I guess this is an old question, but the current versions of virsh make this a lot easier if you're using a nat or bridged private network. I have a machine - steak - on a (routed) private network:



                                                        sauer@helium:~> sudo virsh list
                                                        Id Name State
                                                        ----------------------------------------------------
                                                        21 steak running

                                                        sauer@helium:~> sudo virsh domifaddr steak
                                                        Name MAC address Protocol Address
                                                        -------------------------------------------------------------------------------
                                                        vnet0 76:0c:28:ab:0e:ee ipv4 10.14.1.1/24


                                                        On another machine, I have a system (unifi) which is bridged to the regular network. Libvirt doesn't assign it an address; it gets an address from my network DHCP server, which also updates dynamic DNS in my case. So, you basically have to find the address like it's any other machine - finding it in the arp table is probably the easiest -- which means ip neighbour now, as arp is deprecated and no longer present on some distributions. Luckily for those of us who don't spell things with extrae vouwels, you can also use shorter versions, like ip neigh and ip n (or ip neighbor). ;)



                                                        sauer@helium:~$ sudo virsh domifaddr unifi
                                                        Name MAC address Protocol Address
                                                        -------------------------------------------------------------------------------

                                                        sauer@helium:~$ sudo virsh domiflist unifi
                                                        Interface Type Source Model MAC
                                                        -------------------------------------------------------
                                                        vnet0 bridge br0 virtio 52:54:00:2c:ac:ee

                                                        sauer@helium:~$ ip neigh | grep -i 52:54:00:2c:ac:ee
                                                        192.168.0.226 dev br0 lladdr 52:54:00:2c:ac:ee REACHABLE
                                                        sauer@helium:~$ host unifi
                                                        unifi.home.domain.com has address 192.168.0.226






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Jul 27 '18 at 20:14









                                                        dannysauerdannysauer

                                                        84748




                                                        84748























                                                            0














                                                            (While you seem too advanced for such a simple answer)



                                                            Will



                                                            $ ifconfig


                                                            work?






                                                            share|improve this answer
























                                                            • also, be careful, if you have duplicate instances of the same machine, as the machine will have issues with the fake MAC address etc... there are ways to manually edit that (and I think run a command for that as well)

                                                              – David
                                                              Mar 2 '12 at 3:58











                                                            • I only have one VM "vm1" on my ubuntu server host and the "ifconfig" command output shows no ip address assigned to my "eth0" network adapter.

                                                              – Xianlin
                                                              Mar 2 '12 at 4:59











                                                            • yeah, you have no ip... Did you try "dhclient eth0" --might need sudo

                                                              – David
                                                              Mar 3 '12 at 23:21













                                                            • I tried but still not getting dhcp ip from my host server to my guest VMs. My host server is assigned a fixed IP and it can access the internet.

                                                              – Xianlin
                                                              Mar 5 '12 at 3:22











                                                            • if you want an ip not on the parent network, you want to select NAT in your vm settings instead of bridged.

                                                              – David
                                                              Mar 5 '12 at 18:57
















                                                            0














                                                            (While you seem too advanced for such a simple answer)



                                                            Will



                                                            $ ifconfig


                                                            work?






                                                            share|improve this answer
























                                                            • also, be careful, if you have duplicate instances of the same machine, as the machine will have issues with the fake MAC address etc... there are ways to manually edit that (and I think run a command for that as well)

                                                              – David
                                                              Mar 2 '12 at 3:58











                                                            • I only have one VM "vm1" on my ubuntu server host and the "ifconfig" command output shows no ip address assigned to my "eth0" network adapter.

                                                              – Xianlin
                                                              Mar 2 '12 at 4:59











                                                            • yeah, you have no ip... Did you try "dhclient eth0" --might need sudo

                                                              – David
                                                              Mar 3 '12 at 23:21













                                                            • I tried but still not getting dhcp ip from my host server to my guest VMs. My host server is assigned a fixed IP and it can access the internet.

                                                              – Xianlin
                                                              Mar 5 '12 at 3:22











                                                            • if you want an ip not on the parent network, you want to select NAT in your vm settings instead of bridged.

                                                              – David
                                                              Mar 5 '12 at 18:57














                                                            0












                                                            0








                                                            0







                                                            (While you seem too advanced for such a simple answer)



                                                            Will



                                                            $ ifconfig


                                                            work?






                                                            share|improve this answer













                                                            (While you seem too advanced for such a simple answer)



                                                            Will



                                                            $ ifconfig


                                                            work?







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Mar 2 '12 at 3:56









                                                            DavidDavid

                                                            1011




                                                            1011













                                                            • also, be careful, if you have duplicate instances of the same machine, as the machine will have issues with the fake MAC address etc... there are ways to manually edit that (and I think run a command for that as well)

                                                              – David
                                                              Mar 2 '12 at 3:58











                                                            • I only have one VM "vm1" on my ubuntu server host and the "ifconfig" command output shows no ip address assigned to my "eth0" network adapter.

                                                              – Xianlin
                                                              Mar 2 '12 at 4:59











                                                            • yeah, you have no ip... Did you try "dhclient eth0" --might need sudo

                                                              – David
                                                              Mar 3 '12 at 23:21













                                                            • I tried but still not getting dhcp ip from my host server to my guest VMs. My host server is assigned a fixed IP and it can access the internet.

                                                              – Xianlin
                                                              Mar 5 '12 at 3:22











                                                            • if you want an ip not on the parent network, you want to select NAT in your vm settings instead of bridged.

                                                              – David
                                                              Mar 5 '12 at 18:57



















                                                            • also, be careful, if you have duplicate instances of the same machine, as the machine will have issues with the fake MAC address etc... there are ways to manually edit that (and I think run a command for that as well)

                                                              – David
                                                              Mar 2 '12 at 3:58











                                                            • I only have one VM "vm1" on my ubuntu server host and the "ifconfig" command output shows no ip address assigned to my "eth0" network adapter.

                                                              – Xianlin
                                                              Mar 2 '12 at 4:59











                                                            • yeah, you have no ip... Did you try "dhclient eth0" --might need sudo

                                                              – David
                                                              Mar 3 '12 at 23:21













                                                            • I tried but still not getting dhcp ip from my host server to my guest VMs. My host server is assigned a fixed IP and it can access the internet.

                                                              – Xianlin
                                                              Mar 5 '12 at 3:22











                                                            • if you want an ip not on the parent network, you want to select NAT in your vm settings instead of bridged.

                                                              – David
                                                              Mar 5 '12 at 18:57

















                                                            also, be careful, if you have duplicate instances of the same machine, as the machine will have issues with the fake MAC address etc... there are ways to manually edit that (and I think run a command for that as well)

                                                            – David
                                                            Mar 2 '12 at 3:58





                                                            also, be careful, if you have duplicate instances of the same machine, as the machine will have issues with the fake MAC address etc... there are ways to manually edit that (and I think run a command for that as well)

                                                            – David
                                                            Mar 2 '12 at 3:58













                                                            I only have one VM "vm1" on my ubuntu server host and the "ifconfig" command output shows no ip address assigned to my "eth0" network adapter.

                                                            – Xianlin
                                                            Mar 2 '12 at 4:59





                                                            I only have one VM "vm1" on my ubuntu server host and the "ifconfig" command output shows no ip address assigned to my "eth0" network adapter.

                                                            – Xianlin
                                                            Mar 2 '12 at 4:59













                                                            yeah, you have no ip... Did you try "dhclient eth0" --might need sudo

                                                            – David
                                                            Mar 3 '12 at 23:21







                                                            yeah, you have no ip... Did you try "dhclient eth0" --might need sudo

                                                            – David
                                                            Mar 3 '12 at 23:21















                                                            I tried but still not getting dhcp ip from my host server to my guest VMs. My host server is assigned a fixed IP and it can access the internet.

                                                            – Xianlin
                                                            Mar 5 '12 at 3:22





                                                            I tried but still not getting dhcp ip from my host server to my guest VMs. My host server is assigned a fixed IP and it can access the internet.

                                                            – Xianlin
                                                            Mar 5 '12 at 3:22













                                                            if you want an ip not on the parent network, you want to select NAT in your vm settings instead of bridged.

                                                            – David
                                                            Mar 5 '12 at 18:57





                                                            if you want an ip not on the parent network, you want to select NAT in your vm settings instead of bridged.

                                                            – David
                                                            Mar 5 '12 at 18:57











                                                            0














                                                            If you have QEMU(VM emulator) go to "i" button and check the network card associated with "Br0" network. Take a note of the mac address of the NIC. Now Login to your VM -> Open Terminal -> type: "ifconfig" command in the terminal -> take a note of IP address associated with the the Mac address that you have noted earlier.



                                                            You can login to your VM using Putty or any ssh client using the IP you have noted in the last step.






                                                            share|improve this answer




























                                                              0














                                                              If you have QEMU(VM emulator) go to "i" button and check the network card associated with "Br0" network. Take a note of the mac address of the NIC. Now Login to your VM -> Open Terminal -> type: "ifconfig" command in the terminal -> take a note of IP address associated with the the Mac address that you have noted earlier.



                                                              You can login to your VM using Putty or any ssh client using the IP you have noted in the last step.






                                                              share|improve this answer


























                                                                0












                                                                0








                                                                0







                                                                If you have QEMU(VM emulator) go to "i" button and check the network card associated with "Br0" network. Take a note of the mac address of the NIC. Now Login to your VM -> Open Terminal -> type: "ifconfig" command in the terminal -> take a note of IP address associated with the the Mac address that you have noted earlier.



                                                                You can login to your VM using Putty or any ssh client using the IP you have noted in the last step.






                                                                share|improve this answer













                                                                If you have QEMU(VM emulator) go to "i" button and check the network card associated with "Br0" network. Take a note of the mac address of the NIC. Now Login to your VM -> Open Terminal -> type: "ifconfig" command in the terminal -> take a note of IP address associated with the the Mac address that you have noted earlier.



                                                                You can login to your VM using Putty or any ssh client using the IP you have noted in the last step.







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered May 12 '16 at 6:29









                                                                sauravsaurav

                                                                211




                                                                211























                                                                    0














                                                                    I have my KVM guests on br0 interface so I think its a bit different, but here is my two scripts I made.



                                                                    Note to use ARP you first need to have the MAC in your Arp Table. Therefor its best to use fping to do a quick ping of entire network (takes like 2 seconds). This makes sure your Arp cache is up to date.



                                                                    apt-get install fping
                                                                    yum install fping


                                                                    Find a single guest IP via :



                                                                    cat << 'EOF' > ~/findip.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    echo "Please Enter the Exact Name of the VM Guest:"

                                                                    read guestname

                                                                    arp -na | awk -v mac=$(virsh domiflist $guestname | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}'
                                                                    EOF
                                                                    chmod +x ~/findip.sh
                                                                    sudo sh -c 'echo "alias findguestip=~/findip.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findguestip


                                                                    Find All Guest IP's via:



                                                                    cat << 'EOF' > ~/findallips.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    domainlog=/tmp/domain.log

                                                                    virsh list --all | grep running | cut -c 8- >> "$domainlog"

                                                                    sed -i 's/running*//g' "$domainlog"

                                                                    readarray domain < "$domainlog"

                                                                    for i in "${domain[@]}"
                                                                    do
                                                                    ip="$(arp -na | awk -v mac=$(virsh domiflist $i | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}')"
                                                                    echo "Hostname : $i IP : $ip"
                                                                    done
                                                                    rm "$domainlog"
                                                                    EOF
                                                                    chmod +x ~/findallips.sh
                                                                    sudo sh -c 'echo "alias findallips=~/findallips.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findallips





                                                                    share|improve this answer


























                                                                    • I tackled this problem in the end with arp-scan. example: sudo arp-scan --interface=br0 --localnet --bandwidth=8192000 --numeric --retry=1 that was for when I wanted to actively search. I used addrwatch to sit in the background and accumulate a mac/ip address mapping for me.

                                                                      – Duke Dougal
                                                                      Feb 26 '18 at 20:38
















                                                                    0














                                                                    I have my KVM guests on br0 interface so I think its a bit different, but here is my two scripts I made.



                                                                    Note to use ARP you first need to have the MAC in your Arp Table. Therefor its best to use fping to do a quick ping of entire network (takes like 2 seconds). This makes sure your Arp cache is up to date.



                                                                    apt-get install fping
                                                                    yum install fping


                                                                    Find a single guest IP via :



                                                                    cat << 'EOF' > ~/findip.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    echo "Please Enter the Exact Name of the VM Guest:"

                                                                    read guestname

                                                                    arp -na | awk -v mac=$(virsh domiflist $guestname | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}'
                                                                    EOF
                                                                    chmod +x ~/findip.sh
                                                                    sudo sh -c 'echo "alias findguestip=~/findip.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findguestip


                                                                    Find All Guest IP's via:



                                                                    cat << 'EOF' > ~/findallips.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    domainlog=/tmp/domain.log

                                                                    virsh list --all | grep running | cut -c 8- >> "$domainlog"

                                                                    sed -i 's/running*//g' "$domainlog"

                                                                    readarray domain < "$domainlog"

                                                                    for i in "${domain[@]}"
                                                                    do
                                                                    ip="$(arp -na | awk -v mac=$(virsh domiflist $i | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}')"
                                                                    echo "Hostname : $i IP : $ip"
                                                                    done
                                                                    rm "$domainlog"
                                                                    EOF
                                                                    chmod +x ~/findallips.sh
                                                                    sudo sh -c 'echo "alias findallips=~/findallips.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findallips





                                                                    share|improve this answer


























                                                                    • I tackled this problem in the end with arp-scan. example: sudo arp-scan --interface=br0 --localnet --bandwidth=8192000 --numeric --retry=1 that was for when I wanted to actively search. I used addrwatch to sit in the background and accumulate a mac/ip address mapping for me.

                                                                      – Duke Dougal
                                                                      Feb 26 '18 at 20:38














                                                                    0












                                                                    0








                                                                    0







                                                                    I have my KVM guests on br0 interface so I think its a bit different, but here is my two scripts I made.



                                                                    Note to use ARP you first need to have the MAC in your Arp Table. Therefor its best to use fping to do a quick ping of entire network (takes like 2 seconds). This makes sure your Arp cache is up to date.



                                                                    apt-get install fping
                                                                    yum install fping


                                                                    Find a single guest IP via :



                                                                    cat << 'EOF' > ~/findip.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    echo "Please Enter the Exact Name of the VM Guest:"

                                                                    read guestname

                                                                    arp -na | awk -v mac=$(virsh domiflist $guestname | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}'
                                                                    EOF
                                                                    chmod +x ~/findip.sh
                                                                    sudo sh -c 'echo "alias findguestip=~/findip.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findguestip


                                                                    Find All Guest IP's via:



                                                                    cat << 'EOF' > ~/findallips.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    domainlog=/tmp/domain.log

                                                                    virsh list --all | grep running | cut -c 8- >> "$domainlog"

                                                                    sed -i 's/running*//g' "$domainlog"

                                                                    readarray domain < "$domainlog"

                                                                    for i in "${domain[@]}"
                                                                    do
                                                                    ip="$(arp -na | awk -v mac=$(virsh domiflist $i | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}')"
                                                                    echo "Hostname : $i IP : $ip"
                                                                    done
                                                                    rm "$domainlog"
                                                                    EOF
                                                                    chmod +x ~/findallips.sh
                                                                    sudo sh -c 'echo "alias findallips=~/findallips.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findallips





                                                                    share|improve this answer















                                                                    I have my KVM guests on br0 interface so I think its a bit different, but here is my two scripts I made.



                                                                    Note to use ARP you first need to have the MAC in your Arp Table. Therefor its best to use fping to do a quick ping of entire network (takes like 2 seconds). This makes sure your Arp cache is up to date.



                                                                    apt-get install fping
                                                                    yum install fping


                                                                    Find a single guest IP via :



                                                                    cat << 'EOF' > ~/findip.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    echo "Please Enter the Exact Name of the VM Guest:"

                                                                    read guestname

                                                                    arp -na | awk -v mac=$(virsh domiflist $guestname | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}'
                                                                    EOF
                                                                    chmod +x ~/findip.sh
                                                                    sudo sh -c 'echo "alias findguestip=~/findip.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findguestip


                                                                    Find All Guest IP's via:



                                                                    cat << 'EOF' > ~/findallips.sh
                                                                    #!/bin/bash
                                                                    #FreeSoftwareServers.com

                                                                    echo "Finding All Active IP's in Network via single Ping"
                                                                    sleep 2s

                                                                    fping -a -g 192.168.1.0/24
                                                                    #nmap -sn 192.168.1.0/24

                                                                    domainlog=/tmp/domain.log

                                                                    virsh list --all | grep running | cut -c 8- >> "$domainlog"

                                                                    sed -i 's/running*//g' "$domainlog"

                                                                    readarray domain < "$domainlog"

                                                                    for i in "${domain[@]}"
                                                                    do
                                                                    ip="$(arp -na | awk -v mac=$(virsh domiflist $i | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}')"
                                                                    echo "Hostname : $i IP : $ip"
                                                                    done
                                                                    rm "$domainlog"
                                                                    EOF
                                                                    chmod +x ~/findallips.sh
                                                                    sudo sh -c 'echo "alias findallips=~/findallips.sh" >> ~/.bashrc'
                                                                    source ~/.bashrc
                                                                    findallips






                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Feb 26 '18 at 6:18

























                                                                    answered Feb 24 '18 at 8:14









                                                                    FreeSoftwareServersFreeSoftwareServers

                                                                    99731838




                                                                    99731838













                                                                    • I tackled this problem in the end with arp-scan. example: sudo arp-scan --interface=br0 --localnet --bandwidth=8192000 --numeric --retry=1 that was for when I wanted to actively search. I used addrwatch to sit in the background and accumulate a mac/ip address mapping for me.

                                                                      – Duke Dougal
                                                                      Feb 26 '18 at 20:38



















                                                                    • I tackled this problem in the end with arp-scan. example: sudo arp-scan --interface=br0 --localnet --bandwidth=8192000 --numeric --retry=1 that was for when I wanted to actively search. I used addrwatch to sit in the background and accumulate a mac/ip address mapping for me.

                                                                      – Duke Dougal
                                                                      Feb 26 '18 at 20:38

















                                                                    I tackled this problem in the end with arp-scan. example: sudo arp-scan --interface=br0 --localnet --bandwidth=8192000 --numeric --retry=1 that was for when I wanted to actively search. I used addrwatch to sit in the background and accumulate a mac/ip address mapping for me.

                                                                    – Duke Dougal
                                                                    Feb 26 '18 at 20:38





                                                                    I tackled this problem in the end with arp-scan. example: sudo arp-scan --interface=br0 --localnet --bandwidth=8192000 --numeric --retry=1 that was for when I wanted to actively search. I used addrwatch to sit in the background and accumulate a mac/ip address mapping for me.

                                                                    – Duke Dougal
                                                                    Feb 26 '18 at 20:38











                                                                    0














                                                                    I wrote a get-vm-ip script (available at https://github.com/earlruby/create-vm/blob/master/get-vm-ip) which uses this to get the IP:



                                                                    HOSTNAME=[your vm name]
                                                                    MAC=$(virsh domiflist $HOSTNAME | awk '{ print $5 }' | tail -2 | head -1)
                                                                    arp -a | grep $MAC | awk '{ print $2 }' | sed 's/[()]//g'





                                                                    share|improve this answer




























                                                                      0














                                                                      I wrote a get-vm-ip script (available at https://github.com/earlruby/create-vm/blob/master/get-vm-ip) which uses this to get the IP:



                                                                      HOSTNAME=[your vm name]
                                                                      MAC=$(virsh domiflist $HOSTNAME | awk '{ print $5 }' | tail -2 | head -1)
                                                                      arp -a | grep $MAC | awk '{ print $2 }' | sed 's/[()]//g'





                                                                      share|improve this answer


























                                                                        0












                                                                        0








                                                                        0







                                                                        I wrote a get-vm-ip script (available at https://github.com/earlruby/create-vm/blob/master/get-vm-ip) which uses this to get the IP:



                                                                        HOSTNAME=[your vm name]
                                                                        MAC=$(virsh domiflist $HOSTNAME | awk '{ print $5 }' | tail -2 | head -1)
                                                                        arp -a | grep $MAC | awk '{ print $2 }' | sed 's/[()]//g'





                                                                        share|improve this answer













                                                                        I wrote a get-vm-ip script (available at https://github.com/earlruby/create-vm/blob/master/get-vm-ip) which uses this to get the IP:



                                                                        HOSTNAME=[your vm name]
                                                                        MAC=$(virsh domiflist $HOSTNAME | awk '{ print $5 }' | tail -2 | head -1)
                                                                        arp -a | grep $MAC | awk '{ print $2 }' | sed 's/[()]//g'






                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Dec 13 '18 at 0:22









                                                                        Earl RubyEarl Ruby

                                                                        8112




                                                                        8112























                                                                            0
















                                                                            1. Get your domain list by virsh list --all



                                                                              virsh # list --all

                                                                              2 webserver_01 running



                                                                            2. Get your domain interface list by domain id or name using virsh domiflist yourDomainId, and you will see the MAC ADDRESS of the domain's interface.



                                                                              virsh # domiflist 2

                                                                              bridge br0 virtio 52:54:00:42:be:96



                                                                            3. Using nmap scan your LAN by nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B 2, you will get the IP ADDRESS.



                                                                              [root@kvm-master ~]# nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B2 

                                                                              Nmap scan report for bogon (192.168.1.210)
                                                                              Host is up (0.00013s latency).
                                                                              MAC Address: 52:54:00:42:BE:96 (QEMU Virtual NIC)







                                                                            share|improve this answer






























                                                                              0
















                                                                              1. Get your domain list by virsh list --all



                                                                                virsh # list --all

                                                                                2 webserver_01 running



                                                                              2. Get your domain interface list by domain id or name using virsh domiflist yourDomainId, and you will see the MAC ADDRESS of the domain's interface.



                                                                                virsh # domiflist 2

                                                                                bridge br0 virtio 52:54:00:42:be:96



                                                                              3. Using nmap scan your LAN by nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B 2, you will get the IP ADDRESS.



                                                                                [root@kvm-master ~]# nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B2 

                                                                                Nmap scan report for bogon (192.168.1.210)
                                                                                Host is up (0.00013s latency).
                                                                                MAC Address: 52:54:00:42:BE:96 (QEMU Virtual NIC)







                                                                              share|improve this answer




























                                                                                0












                                                                                0








                                                                                0









                                                                                1. Get your domain list by virsh list --all



                                                                                  virsh # list --all

                                                                                  2 webserver_01 running



                                                                                2. Get your domain interface list by domain id or name using virsh domiflist yourDomainId, and you will see the MAC ADDRESS of the domain's interface.



                                                                                  virsh # domiflist 2

                                                                                  bridge br0 virtio 52:54:00:42:be:96



                                                                                3. Using nmap scan your LAN by nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B 2, you will get the IP ADDRESS.



                                                                                  [root@kvm-master ~]# nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B2 

                                                                                  Nmap scan report for bogon (192.168.1.210)
                                                                                  Host is up (0.00013s latency).
                                                                                  MAC Address: 52:54:00:42:BE:96 (QEMU Virtual NIC)







                                                                                share|improve this answer

















                                                                                1. Get your domain list by virsh list --all



                                                                                  virsh # list --all

                                                                                  2 webserver_01 running



                                                                                2. Get your domain interface list by domain id or name using virsh domiflist yourDomainId, and you will see the MAC ADDRESS of the domain's interface.



                                                                                  virsh # domiflist 2

                                                                                  bridge br0 virtio 52:54:00:42:be:96



                                                                                3. Using nmap scan your LAN by nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B 2, you will get the IP ADDRESS.



                                                                                  [root@kvm-master ~]# nmap -sn 192.168.1.0/24|grep -i '52:54:00:42:be:96' -B2 

                                                                                  Nmap scan report for bogon (192.168.1.210)
                                                                                  Host is up (0.00013s latency).
                                                                                  MAC Address: 52:54:00:42:BE:96 (QEMU Virtual NIC)








                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited Jan 3 at 18:34









                                                                                Jeff Schaller

                                                                                40.9k1056129




                                                                                40.9k1056129










                                                                                answered Jan 3 at 17:15









                                                                                Rod TerryRod Terry

                                                                                12




                                                                                12























                                                                                    0














                                                                                    A nice solution which use the qemu-guest agent.



                                                                                    a)Configure your vm to use qemu-guest agent
                                                                                    On host: Add with virt-manager a "qemu-guest-agent" channel
                                                                                    Is really easy.In my case machine is called "Debian",and xml after modify will be similar to this.



                                                                                     <channel type='unix'>
                                                                                    <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-3-debian/org.qemu.guest_agent.0'/>
                                                                                    <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
                                                                                    <alias name='channel1'/>
                                                                                    <address type='virtio-serial' controller='0' bus='0' port='2'/>
                                                                                    </channel>


                                                                                    b)On guest install qemu-guest-agent and ensure is started



                                                                                    apt -y install qemu-guest-agent

                                                                                    systemctl status qemu-guest-agent.service
                                                                                    ● qemu-guest-agent.service - LSB: QEMU Guest Agent startup script
                                                                                    Loaded: loaded (/etc/init.d/qemu-guest-agent; generated; vendor preset: enabled)
                                                                                    Active: active (running) since Sat 2019-01-26 09:35:57 CET; 3s ago
                                                                                    Docs: man:systemd-sysv-generator(8)
                                                                                    Process: 1624 ExecStop=/etc/init.d/qemu-guest-agent stop (code=exited, status=0/SUCCESS)
                                                                                    Process: 1630 ExecStart=/etc/init.d/qemu-guest-agent start (code=exited, status=0/SUCCESS)
                                                                                    Tasks: 1 (limit: 4915)
                                                                                    CGroup: /system.slice/qemu-guest-agent.service
                                                                                    └─1638 /usr/sbin/qemu-ga --daemonize -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent.0


                                                                                    c)Finally this nice pipe will return the ip,instead of NAMEOFVMNIC put eth0,enp1s0,etc..



                                                                                    virsh domifaddr  --domain yourvmname --source agent|grep -w NAMEOFVMNIC|egrep -o '([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}'





                                                                                    share|improve this answer






























                                                                                      0














                                                                                      A nice solution which use the qemu-guest agent.



                                                                                      a)Configure your vm to use qemu-guest agent
                                                                                      On host: Add with virt-manager a "qemu-guest-agent" channel
                                                                                      Is really easy.In my case machine is called "Debian",and xml after modify will be similar to this.



                                                                                       <channel type='unix'>
                                                                                      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-3-debian/org.qemu.guest_agent.0'/>
                                                                                      <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
                                                                                      <alias name='channel1'/>
                                                                                      <address type='virtio-serial' controller='0' bus='0' port='2'/>
                                                                                      </channel>


                                                                                      b)On guest install qemu-guest-agent and ensure is started



                                                                                      apt -y install qemu-guest-agent

                                                                                      systemctl status qemu-guest-agent.service
                                                                                      ● qemu-guest-agent.service - LSB: QEMU Guest Agent startup script
                                                                                      Loaded: loaded (/etc/init.d/qemu-guest-agent; generated; vendor preset: enabled)
                                                                                      Active: active (running) since Sat 2019-01-26 09:35:57 CET; 3s ago
                                                                                      Docs: man:systemd-sysv-generator(8)
                                                                                      Process: 1624 ExecStop=/etc/init.d/qemu-guest-agent stop (code=exited, status=0/SUCCESS)
                                                                                      Process: 1630 ExecStart=/etc/init.d/qemu-guest-agent start (code=exited, status=0/SUCCESS)
                                                                                      Tasks: 1 (limit: 4915)
                                                                                      CGroup: /system.slice/qemu-guest-agent.service
                                                                                      └─1638 /usr/sbin/qemu-ga --daemonize -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent.0


                                                                                      c)Finally this nice pipe will return the ip,instead of NAMEOFVMNIC put eth0,enp1s0,etc..



                                                                                      virsh domifaddr  --domain yourvmname --source agent|grep -w NAMEOFVMNIC|egrep -o '([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}'





                                                                                      share|improve this answer




























                                                                                        0












                                                                                        0








                                                                                        0







                                                                                        A nice solution which use the qemu-guest agent.



                                                                                        a)Configure your vm to use qemu-guest agent
                                                                                        On host: Add with virt-manager a "qemu-guest-agent" channel
                                                                                        Is really easy.In my case machine is called "Debian",and xml after modify will be similar to this.



                                                                                         <channel type='unix'>
                                                                                        <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-3-debian/org.qemu.guest_agent.0'/>
                                                                                        <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
                                                                                        <alias name='channel1'/>
                                                                                        <address type='virtio-serial' controller='0' bus='0' port='2'/>
                                                                                        </channel>


                                                                                        b)On guest install qemu-guest-agent and ensure is started



                                                                                        apt -y install qemu-guest-agent

                                                                                        systemctl status qemu-guest-agent.service
                                                                                        ● qemu-guest-agent.service - LSB: QEMU Guest Agent startup script
                                                                                        Loaded: loaded (/etc/init.d/qemu-guest-agent; generated; vendor preset: enabled)
                                                                                        Active: active (running) since Sat 2019-01-26 09:35:57 CET; 3s ago
                                                                                        Docs: man:systemd-sysv-generator(8)
                                                                                        Process: 1624 ExecStop=/etc/init.d/qemu-guest-agent stop (code=exited, status=0/SUCCESS)
                                                                                        Process: 1630 ExecStart=/etc/init.d/qemu-guest-agent start (code=exited, status=0/SUCCESS)
                                                                                        Tasks: 1 (limit: 4915)
                                                                                        CGroup: /system.slice/qemu-guest-agent.service
                                                                                        └─1638 /usr/sbin/qemu-ga --daemonize -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent.0


                                                                                        c)Finally this nice pipe will return the ip,instead of NAMEOFVMNIC put eth0,enp1s0,etc..



                                                                                        virsh domifaddr  --domain yourvmname --source agent|grep -w NAMEOFVMNIC|egrep -o '([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}'





                                                                                        share|improve this answer















                                                                                        A nice solution which use the qemu-guest agent.



                                                                                        a)Configure your vm to use qemu-guest agent
                                                                                        On host: Add with virt-manager a "qemu-guest-agent" channel
                                                                                        Is really easy.In my case machine is called "Debian",and xml after modify will be similar to this.



                                                                                         <channel type='unix'>
                                                                                        <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-3-debian/org.qemu.guest_agent.0'/>
                                                                                        <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
                                                                                        <alias name='channel1'/>
                                                                                        <address type='virtio-serial' controller='0' bus='0' port='2'/>
                                                                                        </channel>


                                                                                        b)On guest install qemu-guest-agent and ensure is started



                                                                                        apt -y install qemu-guest-agent

                                                                                        systemctl status qemu-guest-agent.service
                                                                                        ● qemu-guest-agent.service - LSB: QEMU Guest Agent startup script
                                                                                        Loaded: loaded (/etc/init.d/qemu-guest-agent; generated; vendor preset: enabled)
                                                                                        Active: active (running) since Sat 2019-01-26 09:35:57 CET; 3s ago
                                                                                        Docs: man:systemd-sysv-generator(8)
                                                                                        Process: 1624 ExecStop=/etc/init.d/qemu-guest-agent stop (code=exited, status=0/SUCCESS)
                                                                                        Process: 1630 ExecStart=/etc/init.d/qemu-guest-agent start (code=exited, status=0/SUCCESS)
                                                                                        Tasks: 1 (limit: 4915)
                                                                                        CGroup: /system.slice/qemu-guest-agent.service
                                                                                        └─1638 /usr/sbin/qemu-ga --daemonize -m virtio-serial -p /dev/virtio-ports/org.qemu.guest_agent.0


                                                                                        c)Finally this nice pipe will return the ip,instead of NAMEOFVMNIC put eth0,enp1s0,etc..



                                                                                        virsh domifaddr  --domain yourvmname --source agent|grep -w NAMEOFVMNIC|egrep -o '([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}'






                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited Jan 26 at 10:11

























                                                                                        answered Jan 26 at 8:43









                                                                                        elbarnaelbarna

                                                                                        4,103113684




                                                                                        4,103113684






























                                                                                            draft saved

                                                                                            draft discarded




















































                                                                                            Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                                                            • Please be sure to answer the question. Provide details and share your research!

                                                                                            But avoid



                                                                                            • Asking for help, clarification, or responding to other answers.

                                                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                                                            To learn more, see our tips on writing great answers.




                                                                                            draft saved


                                                                                            draft discarded














                                                                                            StackExchange.ready(
                                                                                            function () {
                                                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f33191%2fhow-to-find-the-ip-address-of-a-kvm-virtual-machine-that-i-can-ssh-into-it%23new-answer', 'question_page');
                                                                                            }
                                                                                            );

                                                                                            Post as a guest















                                                                                            Required, but never shown





















































                                                                                            Required, but never shown














                                                                                            Required, but never shown












                                                                                            Required, but never shown







                                                                                            Required, but never shown

































                                                                                            Required, but never shown














                                                                                            Required, but never shown












                                                                                            Required, but never shown







                                                                                            Required, but never shown







                                                                                            Popular posts from this blog

                                                                                            How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                                                                                            is 'sed' thread safe

                                                                                            How to make a Squid Proxy server?