How to automatically bring up socketcan network interfaces on boot (can0, …)

  • Avatar photo
  • 2024年5月23日

Except add sudo ip link set can0 up to rc.local script, we got another method to do this.

To automatically enable all can interfaces, create a file /etc/systemd/network/80-can.network with the following content:

Note: In some Linux distributions, the .network files may located in /usr/lib/systemd/network/80-can.network , to ensure this, change dir to /etc/systemd/network or /usr/lib/systemd/network, if there are many other .network files, that’s the right position for your new .network file.

Instead of “can*” you can also specify a specific interface (e.g. “can0”). And of course you may adjust the bit rate to your needs. See man systemd-network for all available options in the [CAN] section.

Then (re-)start the systemd-networkd service:

To have it start automatically when booting: