adding mac udev rules through DNS lookup configs
This commit is contained in:
parent
b5860daf1d
commit
22edbf98f3
|
@ -36,8 +36,11 @@ case "$1" in
|
|||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
MGMT_MAC=$(ip -br link show dev $(ip -4 -br addr | grep 10.0. | awk '{ print $1 }') | awk '{ print $3 }')
|
||||
declare -A MACS
|
||||
for if in mgmt feth1 feth2 up1 up2
|
||||
do
|
||||
MACS["$if"]=$(dig txt +short mac.$if.$HOSTNAME) ## careful mac will be wrapped in quotes, but we don't care since we'll need it again wrapped in quotes (so far)
|
||||
done
|
||||
|
||||
## END variables
|
||||
|
||||
|
@ -104,15 +107,12 @@ case "$1" in
|
|||
|
||||
|
||||
# write udev rules for device names
|
||||
echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$MGMT_MAC'", ATTR{type}=="1", NAME="mgmt1"' >/etc/udev/rules.d/70-persistent-net.rules
|
||||
i=0
|
||||
for nic in $(ip -br link | awk '{ print $1 }'); do
|
||||
if ethtool $nic | grep -q 10000; then
|
||||
i=$((i+1))
|
||||
echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'$(cat /sys/class/net/$nic/address)'", ATTR{type}=="1", NAME="feth'$i'"' >>/etc/udev/rules.d/70-persistent-net.rules
|
||||
fi
|
||||
done
|
||||
sed -i "/$MGMT_MAC.*feth./d" /etc/udev/rules.d/70-persistent-net.rules
|
||||
for if in ${!MACS[@]}
|
||||
do
|
||||
ifmac=${MACS[$if]}
|
||||
[ "$if" == "mgmt" ] && if=mgmt1
|
||||
[ -z "$ifmac" ] || echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=='$mac', ATTR{type}=="1", NAME="'${if}'"'
|
||||
done >/etc/udev/rules.d/70-persistent-net.rules
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue