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.
1 2 3 4 5 6 |
[Match] Name=can* [CAN] BitRate=500K |
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:
1 2 |
sudo systemctl restart systemd-networkd |
To have it start automatically when booting:
1 |
sudo systemctl enable systemd-networkd |