setup可以在启动时激活接口


2

我想在启动时设置虚拟SocketCAN接口。以下几行做我想要的(手动):

ip link add dev vcan0 type vcan
ip link set up vcan0

(要么)

ip link add dev vcan0 up type vcan

我有一种提出方法 物理 热插拔时的USB CAN接口 - 我添加以下行 /etc/network/interfaces

allow-hotplug can0
iface can0 can static
    bitrate 250000
    up /sbin/ip link set $IFACE down
    up /sbin/ip link set $IFACE up type can

我现在想提出来 vcan 启动界面也是如此。所以我自动添加了 vcan 模块并将这些行添加到 /etc/network/interfaces

auto vcan0
iface vcan0 can static
    bitrate 0  # NEEDED but not supported
    pre-up /sbin/ip link add dev $IFACE type vcan
    up /sbin/ip link set $IFACE up 

但奇怪的是这种方法不起作用:开机或运行时 ifup vcan0 我得到了以下错误:

Configuring interface vcan0=vcan0 (can)
/sbin/ip link add dev $IFACE type vcan
...
ip link set vcan0 type can bitrate 0
RTNETLINK answers: Operation not supported
Failed to bring up vcan0.

..当我添加线 bitrate <somevalue> 或者我明白了

Configuring interface vcan0=vcan0 (can)
Missing required variable: bitrate
Missing required configuration variables for interface vcan0/can.
Failed to bring up vcan0.

..当我省略比特率设置时。

所以它看起来像我 不得不 bitrate 一定不 设置它 - 同时。

我在这做错了什么?

附:当然我可以简单地运行 ip link add .. 在启动时,但我想对两个接口使用相同的方法。

Answers:


1

您必须在启动时加载vcan模块。编辑 的/ etc /模块 为此并添加该行

vcan

接下来,编辑/ etc / network / interfaces

auto vcan0
   iface vcan0 inet manual
   pre-up /sbin/ip link add dev $IFACE type vcan
   up /sbin/ifconfig $IFACE up

最后,重启接口:

sudo /etc/init.d/networking restart

如果键入,则会弹出vcan0界面

ifconfig

在一个终端。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.