Solved How to know ip address guest system?

Well... An all working solution isn't there.
I have outlined a working solution above. From my Debian KVM hypervisor, farlap, nmap(1) identifies my FreeBSD VM gunsynd:
Code:
[farlap[1799] sudo nmap -sn  192.168.1.0/24
...
MAC Address: 52:54:00:00:04:8F (QEMU virtual NIC)
Nmap scan report for gunsynd.my.domain (192.168.1.30)
...
You cannot suppose you know where is the DHCP server and even if it will be used
Not particularly relevant. If you have no control of the DHCP server used for the subnet, I suggested "allow the DHCP server to allocate the IP address dynamically" above.
And even more, you still don't know the MAC address of the VM
On the contrary, from the hypervisor:
Code:
[farlap.1800] $ uname -a
Linux farlap 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.38-2 (2023-07-27) x86_64 GNU/Linux
[farlap.1801] # cd /etc/libvirt/qemu
[farlap.1802] # grep "mac address" gunsynd.xml
      <mac address='52:54:00:00:04:8f'/>
And on the VM:
Code:
[gunsynd.131] $ uname -a
FreeBSD gunsynd.my.domain 13.3-RELEASE-p7 FreeBSD 13.3-RELEASE-p7 GENERIC amd64
[gunsynd.132] $ ifconfig vtnet0 | grep ether
        ether 52:54:00:00:04:8f
furthermore it can be changed.
You can change the MAC address of most NICs (virtual or physical) if you really want to. What I said was that the "MAC address of the guest virtual NIC is a static thing", as it is allocated when a VM is created and continues with that value for life unless someone deliberately changes it. Thus, in that regard, the MAC value for a VM behaves exactly like a conventional hardware NIC.
 
We don't speak of the same thing. You KVM, me bhyve. I didn't say what were my constraints, sorry.

You obviously can get the ip and MAC address from inside the VM, but that's not what I wanted to achieve. It was during the writing of my tools for managing the bhyve VMs. How to determine the ip address of a given VM knowing its name.

Concerning nmap, a scan isn't something I want to use routinely on my network (because real hostile scan may remain unseen).

I saw someone who wrote a service for different OSes in order the host can get some informations from its VMs including the ip address, but the project was abandoned IIRC. Anyway, that idea was bad and inelegant as you're obliged to install something in all the VMs.

Yes, you can enforce a MAC of your own in the bhyve command line. Retrying my utility, I saw that I have in fact succeeded in getting the inner MAC address of a VM (tap). So, I was wrong, that's not the problem (but only for the way I configure my VMs, it could be a real problem in different circumstances). The problem is just to get the ip address from this information.

I recall I have tried a utility, a sort of ping that allows MAC address as argument, but it didn't work. And anyway, I don't want to install a software just for that, even if it had worked.


# ./vminfo fb15
Running: yes (pid = 2227)
Started: 08:45
Run time elapsed: 01:26
Loader: uefi
Cores: 2 / RAM: 4G
bhyve options: AHP
Main disk file: disk
Main disk driver: nvme
VNC: yes
COM: no
Devices: 4,virtio-net,tapFB15
Network interface: tapFB15 [00:a0:98:8b:79:0e] connected to bridgeLOCAL
 
We don't speak of the same thing. You KVM, me bhyve
That's not particularly relevant. In order to move VMs between (potentially different) hypervisors, all VMs must all store the same basic information in their configuration files stored on the hypervisor. I showed how to find the MAC for a VM under KVM because I had that example available. You can get the MAC address for a bhyve VM by looking in the VM's .conf file (on the hypervisor).

The VM MAC address is static. It can be found in the VM configuration file on the hypervisor. And it can be matched to the IP address of a running client on the same subnet using nmap(1). That is a working solution. Q.E.D.
 
The VM MAC address is static. It can be found in the VM configuration file
I don't store this information in my bhyve config files. I get it with the bridge on which a VM tap is connected. It's peculiar to my set of tools.

And again, NO SCAN on my network.
 
I don't store this information in my bhyve config files. I get it with the bridge on which a VM tap is connected. It's peculiar to my set of tools.
I am at a loss to understand why you would not use the standard VM configuration file to get the MAC address, but that's your issue, and not relevant to the solution I provided.
And again, NO SCAN on my network.
Please re-read the thread. My solution was directed at the OP, and not to your specific needs, and your claim that an "An all working solution isn't there" is wrong. You have suggested multiple impediments, none of which invalidate the solution I offered.

map -sn is simply a ping scan. If that's unacceptable, I suggest you look at net/arping.
 
I'm probably missing some constraints. Assuming the following:
* DHCP is using an internal server (e.g. isc-dhcpd) or a router that supports Dynamic DNS (most do AFAIK)
* a DNS server is present (if not, setting up a local-only bind in a VM/jail isn't hard, with a fixed internal IP of course)
Then the solution is simple: the DHCP server can push the hostname of the machine/VM/jail automatically to the DNS server using Dynamic DNS (very simple configuration).
Nothing is required to be installed nor configured inside the VM (or client in general). I've done this using physical Windows & FreeBSD and OSes in ESXi VMs.
For the clients, the DNS server configuration is sent with the DHCP response. Or if preferred, the DNS server can be queried separately through nslookup etc.

The benefit: assuming the IP address isn't static (otherwise this question wouldn't have been asked) and may change, the DHCP server will always keep the hostname up to date.
It's all using standards, no dirty hacks or anything. In essence the DNS server becomes a directory of IP addresses for anything the DHCP server has a lease out.

I've been running like this for a decade after I decided I no longer wanted to assign fixed IPs to each VM for worry of collision. It works like a charm assuming no unscrupulous hackers ever manage to get physical access to your systems.
 
Emrion think about this problem, so that VM stuff does not cloud it.
You have a physical machine, you plug in a USB stick with installed OS image (FreeBSD), the image is configured to use DHCP to set up networking.
You press the power button, the machine boots up.
How do you find out its IP address without accessing the machine's console?

Solve that problem and you will have the solution to your original problem.
People here already suggested some options.
 
Back
Top