wiki:interface_renaming_scripts
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wiki:interface_renaming_scripts [2018/06/19 09:59] – walkeradmin | wiki:interface_renaming_scripts [2018/07/31 07:26] (current) – walkeradmin | ||
|---|---|---|---|
| Line 40: | Line 40: | ||
| Now execute the file using the following syntax: | Now execute the file using the following syntax: | ||
| \\ | \\ | ||
| - | ./ | + | ./ |
| \\ | \\ | ||
| \\ | \\ | ||
| Line 105: | Line 105: | ||
| ---- | ---- | ||
| + | ===rename_network_interfaces.sh=== | ||
| + | \\ | ||
| + | The next part is much simpler. Copy the rename_network_interfaces.sh to your server, and give it execute privileges using the following syntax: | ||
| + | \\ | ||
| + | chmod 777 rename_network_interfaces.sh | ||
| + | \\ | ||
| + | Now execute the script using the following syntax: | ||
| + | \\ | ||
| + | ./ | ||
| + | \\ | ||
| + | \\ | ||
| + | If successful the following output will be observed (depending on what interface scripts already existed). | ||
| + | \\ | ||
| + | < | ||
| + | *** Getting macaddr to register *** | ||
| + | *** Using network_mapping.csv for network interface mapping *** | ||
| + | Backup of / | ||
| + | Backup of / | ||
| + | Backup of / | ||
| + | Backup of / | ||
| + | Backup of / | ||
| + | Backup of / | ||
| + | Generating file / | ||
| + | Generating file / | ||
| + | Generating file / | ||
| + | Generating file / | ||
| + | Generating file / | ||
| + | Generating file / | ||
| + | </ | ||
| + | \\ | ||
| + | Check the / | ||
| + | \\ | ||
| + | Note: No configuration information is copied from the old interface scripts, so before you reboot, you need to re-add all of your IP/ | ||
| + | \\ | ||
| + | \\ | ||
| + | Reboot the server to check the interfaces have been renamed, and the mapping is correct. | ||
| + | \\ | ||
| + | \\ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===The Scripts=== | ||
| + | \\ | ||
| + | <color # | ||
| + | \\ | ||
| + | < | ||
| + | #!/bin/bash | ||
| + | |||
| + | # this script is based on infos got from blog page: | ||
| + | # http:// | ||
| + | |||
| + | # exit at first error | ||
| + | set -o errexit | ||
| + | |||
| + | export IP_INTERFACES=" | ||
| + | export INTERFACE_ANCHOR=" | ||
| + | export MACADDR_ANCHOR=" | ||
| + | |||
| + | export OUTPUT_FILE | ||
| + | |||
| + | function show_help() { | ||
| + | cat <<- EOF | ||
| + | Generate csv file with interface name; mac addr. Output file is a mandatory parameter. | ||
| + | --output | ||
| + | --help|-h | ||
| + | |||
| + | EOF | ||
| + | } | ||
| + | |||
| + | while [ $# -gt 0 ] ; do | ||
| + | case $1 in | ||
| + | --output) OUTPUT_FILE=" | ||
| + | --help|-h) show_help; | ||
| + | *) if ! [ -z " | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | [ -z " | ||
| + | |||
| + | rm -f " | ||
| + | |||
| + | echo " | ||
| + | interface_name_list=$($IP_INTERFACES | grep " | ||
| + | interface_name_list=($interface_name_list) | ||
| + | macaddr_list=$($IP_INTERFACES | grep " | ||
| + | macaddr_list=($macaddr_list) | ||
| + | cnt=0 | ||
| + | arraySize=" | ||
| + | |||
| + | while [ " | ||
| + | echo " | ||
| + | cnt=$(( cnt + 1 )) | ||
| + | done | ||
| + | |||
| + | </ | ||
| + | <color # | ||
| + | \\ | ||
| + | < | ||
| + | #!/bin/bash | ||
| + | |||
| + | # this script is based on infos got from blog page: | ||
| + | # http:// | ||
| + | |||
| + | # exit at first error | ||
| + | set -o errexit | ||
| + | |||
| + | IP_INTERFACES=" | ||
| + | MACADDR_ANCHOR=" | ||
| + | NET_NAME_TEMPLATE=" | ||
| + | |||
| + | CSV_FILE= | ||
| + | |||
| + | NETWORK_SCRIPT_DIR="/ | ||
| + | NETWORK_BACKUP_DIR="/ | ||
| + | NETWORK_SCRIPT_TEMPLATE=' | ||
| + | DEVICE="< | ||
| + | ONBOOT=yes | ||
| + | NETBOOT=yes | ||
| + | BOOTPROTO=dhcp | ||
| + | TYPE=Ethernet | ||
| + | # HWADDR key is mandatory to use custom interface name: do not delete it | ||
| + | HWADDR=< | ||
| + | ' | ||
| + | |||
| + | function show_help() { | ||
| + | cat <<- EOF | ||
| + | Update network interfaces names. A csv file with the expected mapping can be given as arg. | ||
| + | --csv Csv file containing < | ||
| + | --help|-h | ||
| + | |||
| + | EOF | ||
| + | } | ||
| + | |||
| + | while [ $# -gt 0 ] ; do | ||
| + | case $1 in | ||
| + | --csv) CSV_FILE=" | ||
| + | --help|-h) show_help; | ||
| + | *) if ! [ -z " | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | echo "*** Getting macaddr to register ***" | ||
| + | macaddr_list=$($IP_INTERFACES | grep " | ||
| + | |||
| + | if ! [ -z " | ||
| + | echo "*** Using $CSV_FILE for network interface mapping ***" | ||
| + | ! [ -d " | ||
| + | for old_script_file in $(find $NETWORK_SCRIPT_DIR -maxdepth 1 -name " | ||
| + | echo -e " | ||
| + | mv -f " | ||
| + | done | ||
| + | while read interface_data | ||
| + | do | ||
| + | [ -z " | ||
| + | interface_name=$(echo " | ||
| + | mac_addr=$(echo " | ||
| + | [ -z " | ||
| + | [ -z " | ||
| + | | ||
| + | # check that given mac addr exist | ||
| + | if ! echo " | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | echo -e " | ||
| + | echo " | ||
| + | sed -i " | ||
| + | sed -i " | ||
| + | done < " | ||
| + | |||
| + | else | ||
| + | echo "*** Using default naming (${NET_NAME_TEMPLATE}x) for network interface mapping ***" | ||
| + | ! [ -d " | ||
| + | cnt=0 | ||
| + | for old_script_file in $(find $NETWORK_SCRIPT_DIR -maxdepth 1 -name " | ||
| + | echo -e " | ||
| + | mv -f " | ||
| + | done | ||
| + | for mac_addr in ${macaddr_list[*]}; | ||
| + | mac_addr=$(echo " | ||
| + | echo -e " | ||
| + | echo " | ||
| + | sed -i " | ||
| + | sed -i " | ||
| + | cnt=$(( cnt + 1 )) | ||
| + | done | ||
| + | fi | ||
| + | |||
| + | echo "*** Please check consistency of generated files in directory $NETWORK_SCRIPT_DIR ***" | ||
| + | |||
| + | |||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
wiki/interface_renaming_scripts.1529402371.txt.gz · Last modified: (external edit)
