Skip to content

Instantly share code, notes, and snippets.

@marek-pietrzak-tg
Last active August 29, 2015 14:01
Show Gist options
  • Save marek-pietrzak-tg/bb145cb60df650c815ca to your computer and use it in GitHub Desktop.
Save marek-pietrzak-tg/bb145cb60df650c815ca to your computer and use it in GitHub Desktop.
#!/bin/bash
# Programme changes IP address of the given hostname
# It expects the hostname already written in /etc/hosts e.g.
#
# 192.168.5.213 ec2.test
#
# author Marek Pietrzak
# date 04.05.2014
# licence MIT
HOSTNAME=ec2.test
if [ -z "$1" ]
then
echo "Usage: temp-ip [ip address]"
exit 0
fi
echo "Changing IP address of the hostname $HOSTNAME to $1"
# safe copy of /etc/hosts
cp /etc/hosts /tmp/etc-hosts.safecopy
# change IP address
sed -i.bak "s/\([0-9\.]*\)\([^I]$HOSTNAME\)/$1\2/" /etc/hosts
# remove old entry from ~/.ssh/known_hosts
sed -i.bak "/$HOSTNAME/ d" ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment