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 10:57] – walkeradmin | wiki:interface_renaming_scripts [2023/03/09 22:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Interface Renaming Scripts ====== | ====== Interface Renaming Scripts ====== | ||
<color darkorange> | <color darkorange> | ||
- | \\ | ||
\\ | \\ | ||
\\ | \\ | ||
---- | ---- | ||
+ | <color # | ||
+ | ---- | ||
+ | \\ | ||
+ | \\ | ||
For anyone that has used CentOS/Red Hat prior to version 7, or indeed other versions of Linux, the norm for network interface naming is to use **eth0, eth1, eth2** etc. | For anyone that has used CentOS/Red Hat prior to version 7, or indeed other versions of Linux, the norm for network interface naming is to use **eth0, eth1, eth2** etc. | ||
\\ | \\ | ||
Line 37: | Line 40: | ||
Now execute the file using the following syntax: | Now execute the file using the following syntax: | ||
\\ | \\ | ||
- | ./ | + | ./ |
\\ | \\ | ||
\\ | \\ | ||
Line 68: | Line 71: | ||
Both of these are easy to fix. Firsly you can manually edit the file, so that the interface names are correct, but more importantly, | Both of these are easy to fix. Firsly you can manually edit the file, so that the interface names are correct, but more importantly, | ||
\\ | \\ | ||
- | Use <color # | ||
\\ | \\ | ||
+ | Use <color # | ||
\\ | \\ | ||
ip link show | ip link show | ||
Line 102: | 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.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1