Bring up can0 on boot

What is the canonical way of bring up a CAN interface (can0 via flexcan) on boot? It seems kind of hacky to me to tack that at the end of rc.local or doing a service file to issue the ip commands to actually bring it online.

Can this be done via systemd-network? I’ve read through the man page but I can’t seem to pull a solution out of that.

I don’t know if this is something that could be handled by conman but we are using an NFS based root fs so we don’t have conman running

systemd-networkd would definitely be ideal, but it looks that systemd just very recently gained CAN Bus support.

If you are using systemd, then using a systemd service is probably nicer than using rc.local.

[Unit]
Description=Setup SocketCAN interface can0 with a baudrate of 250000
After=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/sbin/ip link set can0 type can bitrate 250000
ExecStart=/sbin/ip link set can0 up
ExecStop=/sbin/ip link set can0 down

[Install]
WantedBy=multi-user.target
1 Like