How to run a command on Linux (the host os) while you are using a FreeBSD vm (as guest os)

Hello to everyone.

I'm trying to configure the network of my host os (Linux Devuan 5) and of my guest OS (FreeBSD 13.2) because I want to have the connection inside the FreeBSD VM,that I have virtualized with qemu / kvm / libvirt on my ARM Chromebook. The procedure that I have explained below is working,nevertheless there is still something to fix. This is what I did :

1) Shut down libvirt

2) Created a bridge br1 manually without any slaves :

Code:
# ip link add name br1 type bridge

3) Added "allow all" to that bridge helper file (bridge.conf, located on /usr/local/etc/qemu/bridge.conf)

4) Started a VM with qemu only, telling it to use a bridge interface "br1". This creates a tap interface "tap0" which is a slave of a bridge "br1"

5) Right after VM start, explicitly set link br1 to "up" :

Code:
# ip link set br1 up

6) Configured an IP address from within the VM in a new subnet (192.168.20.2/24)

7) Configured IP address in the same subnet for br1 on KVM host (192.168.20.1/24). No IP should be assigned to the tap interface :

Code:
# ip a add 192.168.20.1/24 dev br1

8) Configured MASQUERADING for traffic leaving through my standard home interface on the KVM host:

Code:
# iptables -t nat -A POSTROUTING -o mlan0 -j MASQUERADE

9) Enabled Routing :

Code:
# echo 1 > /proc/sys/net/ipv4/ip_forward

That's it. The VM could ping everything,but another step is necessary. When the VM booted totally,until the login prompt,I should open a new terminal and do :

Code:
# ip a fl dev tap0

This is a dirty workaround that I don't like too much,but it removes the fake IP address169.254.89.8 from the tap0 and in this way I can ping the world while I'm using the VM. Every time I start a new VM,a new (and always the same) fake ip [169.254.35.253] is assigned to the tap interface and I should delete it everytime WHEN the vm has been fully loaded and it reached the login prompt (really I don't know what's the exact moment when the tap0 is created,so I've assumed that the right time is when the VM reached the login prompt). When this happens,an automatic script should be executed :

Code:
/bin/ip a fl dev tap0

otherwise I cannot ping an external domain from within the vm and I will get the error "host unknown". Now,I don't know how to automate the process. What I want to do is to execute that command after 50 seconds that the qemu parameters below are executed :

Code:
qemu-system-arm \
    -enable-kvm -serial stdio \
    -m 1024 -M virt -cpu cortex-a15 \
    -drive if=pflash,format=raw,unit=0,file=$UEFICODE1 \
    -drive if=pflash,format=raw,unit=1,file=$UEFIVARS2 \
    -drive file=$DISK,media=disk,format=raw \
    -net nic,model=virtio,macaddr=52:54:00:00:00:01 -net bridge,br=br1 \
    -device virtio-gpu-pci \
    -usb -device nec-usb-xhci \
    -device usb-kbd -device usb-mouse \
    -device vmware-svga,id=video0,vgamem_mb=16

because this is the time that the qemu parameters need to create the tap0 with the fake IP = 169.254.35.253 that should be deleted.

You know,It's very annoying to start every time a new terminal (because the terminal where the qemu parameters are running is busy) and writing "/bin/ip a fl dev tap0" inside it.

I've tried several methods to execute that command on the Linux OS while the FreeBSD vm was booting,but none of those methods worked. Now,I've got an idea for a new (interesting,from my point of view) approach to solve the "problem". What about to try to execute that command when FreeBSD is running ? It could be something like this :

1) I enable the automatic login on FreeBSD when the login prompt is ready,by configuring username and password in the right config file (In Linux usually I modify the file /etc/gdm3/custom.conf)

2) while FreeBSD is running or some time before it reaches the login prompt,I would like to run the command that I've shown above "/bin/ip a fl dev tap0" on Linux,but while FreeBSD is running. I have no idea at the moment how to do that,because they are different operating systems. But maybe,can I use the Linuxulator ? assuming that the userland is the host os itself (devuan 5),instead of creating a new,fresh userland directly on FreeBSD...unfortunately I'm on arm,so I have some doubts that the Linuxlator works there.

I would like to gather some opinions to understand if the idea is doable. Thanks.
 
I want to understand if I can run a Linux command while I'm running FreeBSD. FreeBSD is the main actor in this post. If this idea is too crazy,I will come back to try to look for different tecniques to apply on Linux.
 
I want to understand if I can run a Linux command while I'm running FreeBSD. FreeBSD is the main actor in this post.
If you are logged into the FreeBSD VM and you want to run a command on the Linux host you could open another window on the host and run the command or you ssh from the VM to the Host and run the command
 
nope. I don't want to do this. I'm too lazy to do that. I like to live my life comfortably. I want an automatic procedure that does it automatically. Since for now I have explored several tecniques in Linux but they all failed,I want to explore the chance to do it while I'm using FreeBSD. I even find this idea enough interesting to explore if it can be accomplished.
 
Since you don't need to run arbitrary commands on the host, why not use port knocking? knockd on the host, a random set of four ports, have the guest run a script to knock those ports. If you want to run a command that could compromise or dos the host, configure its firewall to only accept the knocks from the guest.
 
ok I have been stupid. When I'm in FreeBSD I can create / run an automatic script that does the following :

Code:
# ssh -Y root@192.168.1.8
# ip a fl dev tap0
# exit

I will take some time for me to script it automatically,but I think that it can be done.
 
-Y is "forward trusted X11 connections" so is not needed on command line stuff like the ip command.
You can also put the command to run on the same line in single quotes:

ssh root@192.168.1.8 'ip a fl dev tap0'
 
-Y is "forward trusted X11 connections" so is not needed on command line stuff like the ip command.
You can also put the command to run on the same line in single quotes:

ssh root@192.168.1.8 'ip a fl dev tap0'

the problem that I need to fix is how to insert username and password automatically (even bypassing their authentication,because the host IP may change),without writing them by hands....
 
Back
Top