-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Issue: How to Establish Bidirectional Communication Between Host and Guest Using virtio-vsock
Background
I'm trying to set up bidirectional communication between host and guest using vsock. According to the documentation at https://github.com/crc-org/vfkit/blob/main/doc/usage.md#virtio-vsock-communication, I understand that:
This allows virtio-vsock communication from the host to the guest over vsock port 6:
--device virtio-vsock,port=6,socketURL=/Users/virtuser/vfkit-6.sock,connectThe socket can be created on the guest with
nc --vsock --listen 3 6, and the host can connect to it withnc -U /Users/virtuser/vfkit-6.sock
My Goal
I want to achieve the following:
- Allow the guest VM to connect to Service A on the host via VSOCK port 1023
- Allow the host to connect to Service B in the guest VM via a Unix domain socket
My Configuration
Here is my vfkit start command:
vfkit \
-c 4 \
-m 4096 \
-b linux,kernel=vmlinux,initrd=initrd,cmdline="console=hvc0 root=/dev/vda" \
-d virtio-blk,path=disk.img \
-d virtio-serial,stdio \
-d virtio-net,nat \
-d virtio-fs,sharedDir=/,mountTag=host \
-d virtio-vsock,port=1023,socketURL=/tmp/sock-a.sock \
-d virtio-vsock,port=3300,socketURL=/tmp/vfkit-3300.sock,connect \
-d virtio-fs,sharedDir="$SHARED_DIR",mountTag=mytagObserved Behavior
Observation 1: Socket Creation
/tmp/sock-a.sockis successfully created automatically/tmp/vfkit-3300.sockis not created automatically. I had to manually create this socket file usingnc
Observation 2: Guest to Host Communication (Working ✅)
From within the guest VM, I can successfully connect to the host service on VSOCK port 1023:
# Command in guest VM
echo "Hello From Guest" | socat - VSOCK-CONNECT:2:1023
# Output
Hello From HostThis works as expected.
Observation 3: Host to Guest Communication (Not Working ❌)
I started a vsock listener in the guest VM:
ncat --vsock --listen 3 3300 -c 'cat'However, when I try to connect from the host, it fails:
# Command on host
echo "Hello From Host" | socat - UNIX-CONNECT:/tmp/vfkit-3300.sock
# Error output
2026/03/03 22:19:13 socat[52745] E connect(, LEN=31 AF=1 "/tmp/vfkit-3300.sock", 22): Connection refusedI also tried using nc -U as shown in the documentation, but there is no output at all. Additionally, the listener in the guest VM does not receive any data.
Question
Could you please advise on the correct configuration to achieve my goal? Specifically:
- Why is
/tmp/vfkit-3300.socknot being created automatically when using theconnectflag? - What is the proper way to establish a connection from the host to a vsock listener in the guest?
- Is there a specific order or additional configuration required for bidirectional vsock communication?
Thank you for your assistance!