[systemd-devel] Rename NIC by using dynamic MAC
Kaesbauer Michael
Michael.Kaesbauer at krones.com
Thu Dec 3 05:25:03 PST 2015
Hi,
up to now I found no way to write an udev rule which renames a specific NIC by using a MAC address that is returned by a bash script. The reason for getting the MAC address by the bash script is that the renaming NIC rule should be applied to different CPUs (with different MACs).
Here is my udev rule: /etc/udev/rules.d/81-net-rename.rules
SUBSYSTEM!="net", GOTO="net_name_slot_end"
ACTION!="add|change", GOTO="net_name_slot_end"
KERNEL=="*", ATTR{type}=="1", PROGRAM="/bin/getMAC_DHCP.sh", ATTR{address}=="%c", NAME="net0"
LABEL="net_name_slot_end"
Here is my bash script:
#!/bin/bash
NIC_ID=
MACS=(`cat /sys/class/net/*/address`)
len=${#MACS[*]}
NIC_CNT=0
for ((i=0; i != len; i++)); do
mac_str=${MACS[$i]}
if [ $mac_str != "00:00:00:00:00:00" ]; then
let NIC_CNT=$NIC_CNT+1
fi
done
if [ $NIC_CNT -eq 2 ]; then
NIC_ID="enp1s0"
fi
if [ $NIC_CNT -eq 3 ]; then
NIC_ID="enp3s0"
fi
if [ $NIC_CNT -eq 4 ]; then
NIC_ID="enp3s0"
fi
echo $NIC_ID >> $LOG
cat /sys/class/net/$NIC_ID/address
Kind regards
Michael
______________________________________________________________
KRONES AG
Vorstand: Volker Kronseder (Vors.),
Christoph Klenk, Rainulf Diepold, Thomas Ricker, Markus Tischer, Ralf Goldbrunner
Vors. des Aufsichtsrates: Ernst Baumann
Sitz Neutraubling
Registergericht Regensburg HRB 2344
______________________________________________________________
Der Inhalt dieser E-Mail und jeder Anhang ist vertraulich.
Diese Inhalte sind nur fuer die benannten Adressaten.
Wenn Sie diese E-Mail durch einen Fehler erhalten haben,
benachrichtigen Sie sofort Ihren Administrator oder den Absender.
Behandeln Sie die E-Mail vertraulich.
* Diese E-Mail wurde auf Viren und gefaehrlichen Inhalt geprueft. *
______________________________________________________________
The contents of this email and any attachments are confidential.
They are intended for the named recipient(s) only.
If you have received this email in error please notify the system manager
or the sender immediately and do not disclose the contents to anyone or
make copies.
* This e-Mail was scanned for viruses, vandals and malicious content. *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20151203/a4cac6e1/attachment.html>
More information about the systemd-devel
mailing list