Created
February 23, 2012 19:31
-
-
Save pmbuko/1894523 to your computer and use it in GitHub Desktop.
Script to change rhel/fedora ip address, meant to be used in single-user mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# != 1 ]]; then echo "You must supply a single IP address." && exit 1; fi | |
newip="$1" | |
config="/etc/sysconfig/network-scripts/ifcfg-eth0" | |
oldip=$(awk -F= '/IPADDR/{gsub("\"","");print $2}' $config) | |
newgw=$(echo $newip | awk '{sub(".[0-9]+$",".1"); print}') | |
echo "" | |
echo -n "The old address $(tput bold)$(tput setaf 1)$oldip$(tput sgr0) " | |
sed -i.orig -e"s/^IPADDR=.*$/IPADDR=$newip/" -e"s/^GATEWAY=.*$/GATEWAY=$gway/" $config | |
echo "has been changed to $(tput bold)$(tput setaf 2)$newip$(tput sgr0)." | |
echo "" | |
echo "Next steps:" | |
echo "" | |
echo " 1. Type $(tput bold)$(tput setaf 4)service network start$(tput sgr0) to bring up the network interface." | |
echo " 2. Type $(tput bold)$(tput setaf 4)ping -c 3 $newgw$(tput sgr0) to verify that the network is now functioning." | |
echo " 3. Type $(tput bold)$(tput setaf 4)init 5$(tput sgr0) to boot the computer normally." | |
echo " 3. Contact the linux team to inform them that the computer has a new ip address." | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment