Edit: This is still an interesting idea.
Originally posted March 20, 2012 on AIXchange
I recently spoke to a customer that has its primary and backup servers in different locations. The customer boots from a SAN, with the SAN replicating from site 1 to site 2. In the event of a disaster, the customer wants to fire up its site 2 LPAR from the replicated copy of rootvg. However, the networks are also in different locations.
Rather than do some admin kung fu to allow each network to have the same IP address when it boots up, the customer sought the capability to easily change the IP address depending on the frame being used to boot the LPAR. The customer says this functionality is available in VMware’s recovery management product, and wanted to know if the same type of thing can be done from the HMC.
I checked with a couple of my IBM contacts to see if they had any ideas. Chris Gibson had a good one.
“You could write a script that lives on the source system. It checks the system ID (lsattr -El sys0 -a systemid) when the LPAR boots. And if it’s a particular system serial number, it could bring up the interface with a different IP address.”
I forwarded this suggestion to the customer, and literally within a day their script was working. With the customer’s permission I’m sharing it here, along with their caveat:
“It works … the script is pretty rough. I’m no shell script expert by any means, but it does what I need it to do. I have it in /etc/inittab right before the rctcpip stuff, and that seems to work fine.”
Before trying to use this script, make sure your domain, nameserver, gateway and primary and backup server information are accurate for your environment. Of course you might be able to simplify or improve what’s here, but this should help you get started. Also note that in the process of posting this script to the blog, some of the formatting may be altered. You savvy scripters should move things around if need be.
#!/bin/ksh
# This script checks to see whether the system is booting off hardware
#at the primary or backup site and sets the IP, gateway, and name
#server based on what hardware it is booting from
# check to see which hardware is booting
OPTION=`lsattr -El sys0 -a systemid -F value`
IPADDRESS=`lsattr -El en0 -a netaddr -F value`
HOST=$(hostname)
DOMAIN=”mydomain.com”
PRIMARY=”IBM,123″
BACKUP=”IBM,456″
NAMESERVER=”10.9.0.1″
GATEWAY=”10.9.16.1″
# set the primary and backup IP to the correct subnet (xx.1 for primary, xx.2 for backup)
PRIMARYIP=`echo $IPADDRESS | awk -v pos=4 -v repl=1 ‘{print
substr($0,1,pos-1) repl substr($0,pos+1)}’`
BACKUPIP=`echo $IPADDRESS | awk -v pos=4 -v repl=2 ‘{print
substr($0,1,pos-1) repl substr($0,pos+1)}’`
BACKUPGW=”10.9.16.1″
BACKUPNS=”10.9.30.32″
echo “Host Hardware: $OPTION”
echo “Current IP: $IPADDRESS”
echo “Primary IP: $PRIMARYIP”
echo “Backup IP: $BACKUPIP”
if [ “$OPTION” = “$PRIMARY” ]
then
echo “Running from primary site”
if [ “$IPADDRESS” = “$BACKUPIP” ] ; then
echo “Setting IP for primary location”
/usr/sbin/mktcpip -h $HOST -a $PRIMARYIP -m
255.255.255.0 -i en0 -n $NAMESERVER -d $DOMAIN -g $GATEWAY -A no -t
N/A
fi
fi
if [ “$OPTION” = “$BACKUP” ]
then
echo “Running from backup site”
if [ “$IPADDRESS” = “$PRIMARYIP” ] ; then
/usr/sbin/mktcpip -h $HOST -a $BACKUPIP -m 255.255.255.0 -i en0 -n
$BACKUPNS -d $DOMAIN -g $BACKUPGW -A no -t N/A
fi
fi
As always, I love getting reader questions and submissions. That includes scripts. Please send me your scripts or any other useful tips. We all benefit when you share your expertise.