Skip to content

SocketCAN Cheat Sheet

A quick reference of common SocketCAN use cases and commands.

Terminal window
# Set up a physical CAN device
sudo ip link set can0 type can bitrate 500000 # add the device and set bitrate
sudo ip link set up can0 # devices start down, bring it up
# Set up a Virtual CAN device
# Virtual CAN — try with no hardware
sudo modprobe vcan #Load kernel module - only required once
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
# Inspect
ip link show # list interfaces
ip -details -statistics link show vcan0 # detailed counters, error state, and bitrate timing
# Recover - bring device down then up
sudo ip link set down can0
sudo ip link set up can0