I created a script, that can be accessed "outside" of the zone (copied in, NAS 
mount, etc - but doesn't require any special build/access for the zone).

It looks for a common MAC from the zone's MAC to the global zone's MAC.  It 
isn't perfect, but gives a list of IPs to look against.


#!/bin/ksh
#
################################################################################
#
# Tries to determine the global name for the local/non-global zone by using arp.
# May not always be accurate or successful.
#
# Written by Matt Baker  mba...@computeranddata.com
# 8/22/2008
# Version 1.0
#
################################################################################

if [[ $(uname) == SunOS  && $(uname -r | awk -F. '{print $2}') -ge 10 ]]
then
    if [[ $(zonename) != global ]]
    then
        ping  $(hostname)
        MYZONEIP=$(grep -w $(hostname) /etc/hosts | awk '{print $1}')
        MYZONEMAC=$(/usr/sbin/arp -na \
                        | grep $MYZONEIP \
                        | awk '{print $NF}')
        MYZONEVIPS=$(ifconfig -a | grep inet \
                                 | grep -v 127.0.0.1 \
                                 | awk '{print $2}'\
                                 | grep -v $MYZONEIP )
        MYZONEVIPS=$(echo $MYZONEVIPS | sed -e 's/ /|/')

        #
        # give it something dumb so I don't have to make another test case
        #
        if [[ -z $MYZONEVIPS ]]
        then
                MYZONEVIPS="0.0.0.0|0.0.0.1"
        fi      

        print -n "My possible Globals are: "
                GLOBAL=$(/usr/sbin/arp -na \
                                | grep $MYZONEMAC \
                                | egrep -v "$MYZONEVIPS" \
                                | awk '{print $2}' \
                                | sort )
                
                if [[ -n $GLOBAL ]]
                then
                        print "$GLOBAL"
                else
                        print "ERROR:1: CANNOT FIND GLOBALNAME - Sorry."
                        exit 1
                fi
    else
        print "ERROR:3: You already in a global zone, use 'zoneadm list -civ'."
        exit 3
    fi

else
    print "ERROR:2: Only works on Solaris 10 or greater."
    exit 2
fi
-- 
This message posted from opensolaris.org
_______________________________________________
zones-discuss mailing list
zones-discuss@opensolaris.org

Reply via email to