Guest User

Untitled

a guest
Jun 25th, 2024
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # Function to get user input
  4. get_input() {
  5. read -p "$1: " input
  6. echo $input
  7. }
  8.  
  9. # Backup reminder
  10. echo "Always backup your server data before making changes."
  11. read -p "Have you backed up your data? (yes/no): " backup_confirm
  12. if [ "$backup_confirm" != "yes" ]; then
  13. echo "Please backup your data before proceeding."
  14. exit 1
  15. fi
  16.  
  17. # Get the current NIC names and MAC addresses
  18. echo "Fetching current network interfaces..."
  19. ifconfig | grep -o -E 'eth[0-9]' | while read -r nic; do
  20. mac=$(cat /sys/class/net/$nic/address)
  21. echo "Interface: $nic, MAC Address: $mac"
  22. new_name=$(get_input "Enter new name for $nic (e.g., ens192)")
  23.  
  24. # Update udev rules
  25. echo "Updating udev rules..."
  26. 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
  27.  
  28. # Rename network script files
  29. echo "Renaming network script files..."
  30. sudo mv /etc/sysconfig/network-scripts/ifcfg-$nic /etc/sysconfig/network-scripts/ifcfg-$new_name
  31.  
  32. # Update DEVICE parameter in network script files
  33. echo "Updating DEVICE parameter..."
  34. sudo sed -i "s/DEVICE=$nic/DEVICE=$new_name/g" /etc/sysconfig/network-scripts/ifcfg-$new_name
  35. done
  36.  
  37. # Disable predictable network interface names
  38. echo "Disabling predictable network interface names..."
  39. sudo sed -i '/GRUB_CMDLINE_LINUX=/ s/"$/ net.ifnames=0 biosdevname=0"/' /etc/default/grub
  40.  
  41. # Regenerate GRUB configuration
  42. echo "Regenerating GRUB configuration..."
  43. sudo grub2-mkconfig -o /boot/grub2/grub.cfg
  44.  
  45. # Reboot the system
  46. echo "Rebooting the system..."
  47. sudo reboot
  48.  
Advertisement
Add Comment
Please, Sign In to add comment