Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Used to map PCI bus to name
- # CONSTANTS
- INTF_NAME="eth"
- INTF_NUMBER=0
- RULES_FILE="/etc/udev/rules.d/70-persistent-net.rules"
- # Get all PCI bus, order them ascending and assign to an array
- pci_bus_array=( $(for dir in /sys/class/net/* ; do [ -e $dir/device ] && { basename $dir ; readlink -f $dir/device; }; done | grep devices | sort -n) )
- # Iterate through PCI bus array and change each NIC name
- for pci_bus in "${pci_bus_array[@]}"; do
- echo "Mapping ${pci_bus} to $INTF_NAME$INTF_NUMBER"
- line_number=$(grep -n $pci_bus $RULES_FILE | awk -F: '{print $1}')
- line_number=$(($line_number + 1))
- sed -i "${line_number}s/eth[0-9]/${INTF_NAME}${INTF_NUMBER}/" $RULES_FILE
- INTF_NUMBER=$(($INTF_NUMBER + 1))
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement