Update
As Ollie pointed out, Ubuntu 18.04 comes equipped with systemd v237, which doesn't support configuring CAN interfaces. CAN support was added in this commit, which was first released in systemd v239. You can check your version of systemd by typing systemctl --version
. If you can, you should update to Ubuntu 20.04 to use this functionality.
If you're stuck using Ubuntu 18.04, then you could manually update your version of systemd, but this is generally considered to be a bad idea.
Original Answer
I ran into into a similar issue. At the moment it doesn't look like netplan supports can interfaces, which is a bit of a bummer. I did find, though, that systemd-networkd does support can and vcan interfaces. The following is untested - I'm waiting for CAN hardware to arrive - but should work.
Add the can modules to /etc/modules
so that they get loaded at boot. (i.e., cat
, raw-can
, can-dev
, mttcan
, etc.)
Create a new file under /etc/systemd/network/
with a .network
extension and with the following content:
[Match]
Name=can0
[CAN]
BitRate=500000
Make sure that systemd-networkd
is enabled on boot. Warning - this could cause issues if you are already running NetworkManager
and both networkd
and NetworkManager
try to configure the same interfaces... Use with caution
sudo systemctl enable systemd-networkd
Now whenever you boot your system your can0 interface should be configured to the specified bitrate.
Additionally, if you want to specify that your link is 'up', then you can add an extra argument to your .network
file:
[Link]
ActivationPolicy=up
As a side note, networkd
can also be used to bring up a vcan
network. In this case you need to make a .netdev
file specifying the virtual network you want to create and a .network
file to automatically bring up the interface on boot.
Useful documentation:
https://www.freedesktop.org/software/systemd/man/systemd.network.html
https://www.freedesktop.org/software/systemd/man/systemd.netdev.html
Related forums/issues:
https://github.com/linux-can/can-utils/issues/68
https://github.com/systemd/systemd/issues/4042
https://unix.stackexchange.com/questions/178871/systemd-networkd-wont-reload-virtual-network-interface-configuraion-file
https://superuser.com/questions/1450668/network-configuration-systemd-networkd-vs-networking-service-and-compatiblity
/etc/network/interfaces, systemd-networkd and NetworkManager: how do they coexist together?
239
whereas 18.04 uses version237
. Apparently the first version of Ubuntu to support this was 19.04 but as that is now end of life you will need Ubuntu 20.04 LTS or later. Source: this comment in the can-utils GitHub issue 68. – Ollie Oct 27 '21 at 10:18