我正在编写一个 udev 规则,以自动重命名和编号具有特定 MAC 地址的 NIC。
生成的规则应该做的几乎相同75-persistent-net-generator.rules
(匹配卡的 MAC 地址的前 3 个字节,将其命名为“mycard*”,具体取决于安装了该供应商的卡数量,将重命名规则写入70-persistent-net.rules
)。
到目前为止,我已经走了多远:
# udev rules to name rename cards to mycard
ACTION!="add", GOTO="persistent_mycard_generator_end"
SUBSYSTEM!="net", GOTO="persistent_mycard_generator_end"
# ignore the interface if a name has already been set
NAME=="mycard*", GOTO="persistent_mycard_generator_end"
# device name whitelist
KERNEL!="eth*", GOTO="persistent_mycard_generator_end"
# read MAC address
ENV{MATCHADDR}="$attr{address}"
# match interface type
ENV{MATCHIFTYPE}="$attr{type}"
# ignore non mycard MAC addresses
ENV{MATCHADDR}!="00:11:22:*", GOTO="persistent_mycard_generator_end"
# default comment
ENV{COMMENT}=="", ENV{COMMENT}="mycard connected through ($attr{driver})"
#### THIS IS THE PART I DON'T GET ####
# write rule
DRIVERS=="?*", IMPORT{program}="write_net_rules"
# rename interface if needed
ENV{INTERFACE_NEW}=="?*", NAME="mycard*"
#### THIS IS THE END OF THE PART I DON'T GET ####
LABEL="persistent_mycard_generator_end
“我没有得到的部分”应该做的任务是将卡(假设它是 eth3)重命名为 mycard0,或者如果它是系统中具有匹配 MAC 地址 mycard1 的第二张卡,依此类推。
在此先感谢,弗洛克拉