:: Re: [DNG] if2mac init.d service for…
Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: aitor
Fecha:  
A: dng
Asunto: Re: [DNG] if2mac init.d service for persistent network interface names
Hi tito,

On 22/12/20 8:18, tito via Dng wrote:
> BTW I don't know how to achieve this with udev rules
> could you be so kind and make a minimal example.


You can invoke your bourne shell script from a new udev.rule via:

IMPORT{program}="script"

If you locate this script in /lib/udev, the path to the script is
superfluous.
On the other hand, you can define new udev.rule stanzas from the shell
script
at boot time as follows (in this concrete case, we are using
70-persistent-net.rules
and previously we source the rule_generator.funcions):


#!/bin/sh -e

RULES_FILE='/etc/udev/rules.d/70-persistent-net.rules'

# Source the rule_generator.funcions:
. /lib/udev/rule_generator.functions

# lock 70-persistent-net.rules, preventing concurrent processes from
modifying the file at the same time.
lock_rules_file

# Check if the rules file is writeable.
choose_rules_file

# Write the stanza
echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\",
ATTR{address}==\"$mac_address\", ATTR{type}==\"1\", KERNEL==\"?*\",
NAME=\"$name\""
>> $RULES_FILE


# Unlock 70-persistent-net.rules
unlock_rules_file

exit 0


For more instruction, have a look at "/lib/udev/write_net_rules" script.

Hope this helps,

Aitor.