Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Function to get user input
- get_input() {
- read -p "$1: " input
- echo $input
- }
- # Backup reminder
- echo "Always backup your server data before making changes."
- read -p "Have you backed up your data? (yes/no): " backup_confirm
- if [ "$backup_confirm" != "yes" ]; then
- echo "Please backup your data before proceeding."
- exit 1
- fi
- # Get the current NIC names and MAC addresses
- echo "Fetching current network interfaces..."
- ifconfig | grep -o -E 'eth[0-9]' | while read -r nic; do
- mac=$(cat /sys/class/net/$nic/address)
- echo "Interface: $nic, MAC Address: $mac"
- new_name=$(get_input "Enter new name for $nic (e.g., ens192)")
- # Update udev rules
- echo "Updating udev rules..."
- echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$mac\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$new_name\"" | sudo tee -a /etc/udev/rules.d/70-persistent-net.rules
- # Rename network script files
- echo "Renaming network script files..."
- sudo mv /etc/sysconfig/network-scripts/ifcfg-$nic /etc/sysconfig/network-scripts/ifcfg-$new_name
- # Update DEVICE parameter in network script files
- echo "Updating DEVICE parameter..."
- sudo sed -i "s/DEVICE=$nic/DEVICE=$new_name/g" /etc/sysconfig/network-scripts/ifcfg-$new_name
- done
- # Disable predictable network interface names
- echo "Disabling predictable network interface names..."
- sudo sed -i '/GRUB_CMDLINE_LINUX=/ s/"$/ net.ifnames=0 biosdevname=0"/' /etc/default/grub
- # Regenerate GRUB configuration
- echo "Regenerating GRUB configuration..."
- sudo grub2-mkconfig -o /boot/grub2/grub.cfg
- # Reboot the system
- echo "Rebooting the system..."
- sudo reboot
Advertisement
Add Comment
Please, Sign In to add comment