Overview
To avoid bringing up the can interface every time we reboot or plug in the cable, we can use the following setting to automate the process.
Normally, we will need this command to bring up the interface and set the bitrate.
sudo ip link set can0 up type can bitrate 1000000
For CAN FD
sudo ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on
Now we want to set a configuration file once and be able to use the interface when the cable is plugged in.
Steps
Add a new file: /etc/systemd/network/99-interbotix.network.
Put in the following lines.
[Match]
Name=can0
[CAN]
BitRate=1000000
For CAN FD
[Match]
Name=can0
[CAN]
BitRate=1000000
DataBitRate=5000000
FDMode=yes
Reboot the machine.
Result
Now can0 should be up when we plug in the cable. And we’ll get no such device error when it’s unplugged.
Check the status with the following command.
ip -details link show can0
