How To Use SocketCAN With CLI

The native can interface usually named as can0,can1 etc

Identifying CAN interface

ip link show

if you can see can0 then, issue below command to get more details

ip addr ls dev can0

you can also use ifconfig command

ifconfig can0

or

ifconfig -a

Configuring And Enabling The SocketCAN Interface

sudo ip link set can0 type can bitrate 500000

This configures can0 for 500KB baud rate
Bring up the interface

sudo ip link set up can0

Send/Receive Data On SocketCAN

If you want to send/receive data on the CAN interface, you need can-utils package installed in your system

sudo apt install can-utils

To send data to the CAN bus, use the cansend utility:

cansend can0 123#1122334455667788

here ID is 0x123 and the data bytes are 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88.
To see received messages on can0 interface

candump can0

Happy Hacking 🙂