Skip to content

Instantly share code, notes, and snippets.

@manavortex
Forked from yonatanh20/README.md
Last active June 18, 2025 11:00
Show Gist options
  • Save manavortex/cdaf9540784808e5848cbec744d49a19 to your computer and use it in GitHub Desktop.
Save manavortex/cdaf9540784808e5848cbec744d49a19 to your computer and use it in GitHub Desktop.
Enabling SocketCAN on WSL2 walkthrough: update 2025

Preface: this walkthrough is hand-holdy step by step tutorial to enable SocketCan on your WSL2 instance (Ubuntu 20.04).

Requirements:

From cmd / powershell

wsl --shutdown wsl --update

From wsl

sudo apt update sudo apt install can-utils

If you try now to use candump for example you'd get this error message: socket: Address family not supported by protocol

This just means that WSL2 doesn't come with CAN support, so we need to build the wsl kernel and enable can support.

dependencies to build the kernel

sudo apt install build-essential flex bison libssl-dev libelf-dev

cd ~ git clone https://github.com/microsoft/WSL2-Linux-Kernel cd WSL2-Linux-Kernel git checkout 'uname -r' cat /proc/config.gz | gunzip > .config make prepare modules_prepare

config can and vcan support

make menuconfig

Enter Networking support Change CAN bus subsystem support to M and enter Change Raw CAN Protocol to M Enter CAN Device Drivers Change Virtual Local CAN Interface to M Make sure CAN bit-timing calculation is set to * Optionally change CAN devices debugging messages to * Save and exit

make modules sudo make modules_install

sudo modprobe can sudo modprobe can-raw sudo modprobe vcan

Congratulations you've enabled CAN support in your wsl.

WINUSER='cmd.exe /c echo %username%'

Sources: https://www.reddit.com/r/CarHacking/comments/ot3gjf/socketcancanutils_on_windows/ microsoft/WSL#5533 https://chowdera.com/2022/01/202201082236197554.html

@philbegg
Copy link

philbegg commented Mar 7, 2025

Step 8:

Build the kernel (this can take a while):
make_modules

should be make modules

@manavortex
Copy link
Author

should be make modules
Fixed, thanks!

@fulmicotone98
Copy link

I followed all the steps and now I can create a running vcan interface, but still I have an error trying to use the interface (with candump for example):
"socket: Address family not supported by protocol"

Has someone ever had this error?
Thanks!

@manavortex
Copy link
Author

I followed all the steps and now I can create a running vcan interface, but still I have an error trying to use the interface (with candump for example): "socket: Address family not supported by protocol"

Has someone ever had this error? Thanks!

Nope, but please update with your solution!

@Afx31
Copy link

Afx31 commented Apr 23, 2025

This updated method still works as of today, using Ubuntu. Thankyou!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment