Skip to content

Issue: How to Establish Bidirectional Communication Between Host and Guest Using virtio-vsock #433

@sntaoo

Description

@sntaoo

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,connect

The socket can be created on the guest with nc --vsock --listen 3 6, and the host can connect to it with nc -U /Users/virtuser/vfkit-6.sock

My Goal

I want to achieve the following:

  1. Allow the guest VM to connect to Service A on the host via VSOCK port 1023
  2. 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=mytag

Observed Behavior

Observation 1: Socket Creation

  • /tmp/sock-a.sock is successfully created automatically
  • /tmp/vfkit-3300.sock is not created automatically. I had to manually create this socket file using nc

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 Host

This 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 refused

I 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:

  1. Why is /tmp/vfkit-3300.sock not being created automatically when using the connect flag?
  2. What is the proper way to establish a connection from the host to a vsock listener in the guest?
  3. Is there a specific order or additional configuration required for bidirectional vsock communication?

Thank you for your assistance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions