Solved Automatic login into a bhyve linux guest and write it's IP address into a file on the host

The bhyve guest sometimes receives another IP address from my LAN router.
I can always login into the guest using "screen /dev/nmdm0B" .
I would like to write an automatic script which logs in the guest and then writes the output of the command "ifconfig -a" into a file on the host.
In fact some serial-line "automation".
If I could write a python program which opens "/dev/nmdm0B" but I have no idea which API to use.
 
Instead of writing a script why not get to the root of the problem. Why is your upstream router assigning a different IP to your VM.
One reason could be you are using a bridge/tap to provide an IP to your VM.

So how are you assigning a network interface to your VM is my question?
I use a seperate ethernet interface to each VM to avoid the use of bridges. It is a much cleaner approach.
 
The host is currently just a DHCP client to my router and when the lease times out it can get a different IP-address.
Code:
bhyve -S -A -H -P \
    -s 0:0,hostbridge \
    -s 1:0,lpc \
    -s 2:0,virtio-net,tap0 \
    -s 3:0,virtio-blk,/dev/zvol/zfsada0s1/void \
    -s 4,passthru,2/0/0 \
    -l com1,/dev/nmdm0A \
    -c 2 \
    -m $MYMEM \
    $myvm &
 
So the bridge/tap must be using different MAC addresses and your upstream DHCP server is assigning different IP's.
Does that sound correct?
Perhaps you could assign a MAC address to the bridge/tap to keep the same MAC address each time.
Maybe your upstream DHCP server is only keeping your DHCP lease for short time (like 24h) and you could increase that.
 
A static IP adress can give problems with IPV6 and my router.
I have increased the lease time from 3600 seconds to 36000 seconds.
Now I'll try to fix the mac address when i create the virtio-net.
Then it will be almost static.
 
FWIW, a manually configured way to let a DHCP client get a static ip address (if you also control the DHCP server) is to use the send dhcp-client-identifier statement in /etc/dhclient.conf on the client. Like this:
Code:
send dhcp-client-identifier "string";
The string can be anything, this will get sent to the DHCP server. If you use ISC DHCP server, you can match and give out a "static" ip address like this
Code:
  host name-of-host {
        option dhcp-client-identifier "string";
        fixed-address 192.168.3.8;
  }
No need to involve MAC addresses.
 
Back
Top